File: main.cpp

package info (click to toggle)
libgdf 0.1.3-13
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,352 kB
  • sloc: cpp: 7,096; makefile: 65; sh: 49
file content (124 lines) | stat: -rw-r--r-- 3,277 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//
// This file is part of libGDF.
//
// libGDF is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// libGDF is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with libGDF.  If not, see <http://www.gnu.org/licenses/>.
//
// Copyright 2010 Christian Breitwieser


//---------------------------------------------------------------------------------------

#include "gdfmerger.h"

#include <string>
#include <vector>
#include <iostream>
#include <iterator>

#include <boost/program_options.hpp>

namespace po  = boost::program_options;

using std::vector;
using std::string;
using std::cerr;
using std::cout;
using std::endl;
using std::ostream;
using std::ostream_iterator;


//---------------------------------------------------------------------------------------

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
  std::copy(v.begin(), v.end(), ostream_iterator<T>(cout, " "));
    return os;
}

//---------------------------------------------------------------------------------------

int main(int argc, char* argv[])
{
  try
  {

    po::options_description desc("Allowed options");
    desc.add_options()
        ("help,h", "produce help message")
        ("input-files,i",  po::value< vector<string> >()->composing() , "input files")
        ("output-file,o", po::value< vector<string> >() , "output file")
    ;

    po::positional_options_description p;
    p.add("input-files", -1);

    po::variables_map vm;
    po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
    po::notify(vm);

    if(vm.count("help") || vm.size() == 0)
    {
      cout << "Usage: gdf_merger [options]\n";
      cout << desc;
      return 0;
    }

    if(!vm.count("output-file"))
    {
      cerr << "Error -- No output file given!" << endl;
      return(1);
    }
    if(vm.count("output-file") > 1)
    {
      cerr << "Error -- More than 1 output file given!" << endl;
      return(1);
    }

    if(!vm.count("input-files"))
    {
      cerr << "Error -- No input file(s) given!" << endl;
      return(1);
    }

    cout << std::left;
    cout << "Merging gdf files ... " << endl;
    cout.width(23);
    cout << "  -- Input files are: " << vm["input-files"].as< vector<string> >() << endl;
    cout.width(23);
    cout << "  -- Output file is: "  << vm["output-file"].as< vector<string> >() << endl;

    gdfMerger merger(vm["input-files"].as< vector<string> >(),
                     vm["output-file"].as< vector<string> >()[0]);

    merger.merge();

    cout << " ... done." << endl;

  }
  catch(std::exception& e)
  {
    cerr << "error: " << e.what() << "\n";
    return 1;
  }
  catch(...)
  {
    cerr << "Exception of unknown type!\n";
  }

  return(0);
}

//---------------------------------------------------------------------------------------