Changeset 11101 for trunk


Ignore:
Timestamp:
06/21/11 23:21:27 (13 years ago)
Author:
tbretz
Message:
Added an example for an extension.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/Configuration.cc

    r11064 r11101  
    268268   bool has_option1 = vm.count("option1");
    269269   bool has_option2 = conf.Has("option2");
     270
     271\endcode
     272
     273@section Extensions
     274
     275The configuration interpreter can be easily extended to new types, for example:
     276
     277\code
     278
     279template<class T,class S> // Just for the output
     280   std::ostream &operator<<(std::ostream &out, const pair<T,S> &f)
     281   {
     282       out << f.first << "|" << f.second;
     283       return out;
     284   }
     285
     286template<class T, class S> // Needed by the lexical_cast to convert the option
     287   std::istream &operator>>(std::istream &in,  pair<T,S> &f)
     288   {
     289       char c;
     290       in >> f.first;
     291       in >> c;
     292       if (c!=':')
     293           return in;
     294       in >> f.second;
     295       return in;
     296   }
     297
     298typedef pair<int,int> mytype; // Type definition
     299
     300void main(int argc, char **argv)
     301{
     302   po::options_description config("Configuration");
     303   config.add_options()
     304        ("mytype", var<mytype>(), "my new type")
     305        ;
     306
     307   Configuration conf;
     308   conf.AddOptionsCommandline(config);
     309   conf.Parse(argc, argv);
     310
     311   cout << conf.Get<mytype>("mytype") << endl;
     312}
    270313
    271314\endcode
Note: See TracChangeset for help on using the changeset viewer.