/[usata]/usata2/src/options.cpp
ViewVC logotype

Diff of /usata2/src/options.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by Descender, Wed Dec 22 23:35:19 2004 UTC revision 1.3 by Descender, Sun Dec 26 18:36:42 2004 UTC
# Line 11  Line 11 
11  // http://www.fsf.org/licenses/gpl.html.  // http://www.fsf.org/licenses/gpl.html.
12  //  //
13  // $Id$  // $Id$
 // $Log$  
 // Revision 1.2  2004/12/22 23:35:19  Descender  
 // Fix license headers  
 //  
14    
15  #include "config.hpp"  #include "config.hpp"
16  #include <iostream>  #include <iostream>
17    #include <vector>
18  #include <string>  #include <string>
19    #include <utility>
20    #include <iterator>
21  #include <cstdlib>  #include <cstdlib>
22    #include <cctype>
23    #include <boost/algorithm/string.hpp>
24  #include <boost/format.hpp>  #include <boost/format.hpp>
25  #include <boost/program_options.hpp>  #include <boost/program_options.hpp>
26  #include "build_info.hpp"  #include "build_info.hpp"
27    
28    typedef std::pair<std::string, std::string> StringPair;
29    typedef std::vector<std::string>            StringVector;
30    
31    namespace boost
32    {
33            namespace program_options
34            {
35                    void validate(boost::any& value_store,
36                                              const StringVector& values,
37                                              std::vector<StringPair> *,
38                                              int)
39                    {
40                            using namespace boost::algorithm;
41    
42                            StringVector tokens;
43    
44                            split(tokens, values[0], is_space());
45                            if (tokens.size() != 2)
46                                    throw validation_error("invalid string pair");
47    
48                            value_store = boost::any(std::make_pair(tokens[0], tokens[1]));
49                    }
50            }
51    }
52    
53  namespace usata  namespace usata
54  {  {
55            namespace po = boost::program_options;
56    
57          void print_version()          void print_version()
58          {          {
59                  std::cout << boost::format("%s %s\n") % PROGRAM_NAME % PROGRAM_VERSION;                  std::cout << boost::format("%s %s\n") % PROGRAM_NAME % PROGRAM_VERSION;
60          }          }      
61    
62          Configuration*          Configuration*
63          parse_options(int argc, char **argv)          parse_options(int argc, char **argv)
# Line 41  namespace usata Line 68  namespace usata
68                    
69                  std::auto_ptr<Configuration> op_conf(new Configuration);                  std::auto_ptr<Configuration> op_conf(new Configuration);
70    
                 namespace po = boost::program_options;  
   
71                  po::options_description description("Allowed options");                  po::options_description description("Allowed options");
72                  description.add_options()                  description.add_options()
73                          ("help,h"   , "show this help message")                          ("help,h"   , "show this help message")
74                          ("version,v", "print version")                          ("version,v", "print version")
75                          ("config,c" , po::value<std::string>(), "specify path to configuration file")                          ("config,c" , po::value<std::string>(), "specify path to configuration file")
76                          ("set,s"    , po::value<std::vector<std::string> >(), "set configuration option")                          ("set,s"    , po::value<std::vector<StringPair> >()->multitoken(), "set configuration option(s)")
77                          ;                          ;
78    
79                  po::variables_map var_map;                  po::variables_map var_map;
# Line 83  namespace usata Line 108  namespace usata
108                          std::exit(EXIT_SUCCESS);                          std::exit(EXIT_SUCCESS);
109                  }                  }
110    
111                    if (var_map.count("set"))
112                    {
113                            try
114                            {
115    //                              std::vector<std::string> values = var_map["set"].as<std::vector<std::string> >();
116    //                              std::copy(values.begin(), values.end(),
117    //                                                std::ostream_iterator<std::string>(std::cout, ","));
118                            }
119                            catch (boost::bad_any_cast& error)
120                            {
121                                    std::cerr << error.what();
122                            }
123                    }
124    
125                  return op_conf.release();                  return op_conf.release();
126          }          }
127    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26