Changeset 10220
- Timestamp:
- 03/03/11 19:28:48 (14 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Configuration.cc
r10198 r10220 166 166 If the second option is false, the options will not be displayed in any 167 167 \b --help directive, but are available to the user. Each of the functions 168 can be called more than once. 168 can be called more than once. If an option should be available from 169 all kind of inputs AddOptions() can be used which will call all 170 four other AddOptions() functions. 169 171 170 172 A special case are the options from environment variables. Since you might 171 want to use the same option-key for the command-line and the environment 173 want to use the same option-key for the command-line and the environment, 172 174 a mapping is needed (e.g. from \b PATH to \b --path). This mapping 173 can be implemented by a mapping function and be initialized like this: 175 can be implemented by a mapping function or by the build in mapping 176 and be initialized like this: 174 177 175 178 \code 176 179 177 const string name_mapper(const string &str) 180 conf.AddEnv("path", "PATH"); 181 182 \endcode 183 184 or 185 186 \code 187 188 const string name_mapper(const string str) 178 189 { 179 190 return str=="PATH" ? "path" : ""; … … 421 432 //! 422 433 // 423 Configuration::Configuration(const string &prgname) : fName(prgname), fNameMapper(&NameMapper) 434 Configuration::Configuration(const string &prgname) : fName(prgname), 435 fNameMapper(bind1st(mem_fun(&Configuration::DefaultMapper), this)) 424 436 { 425 437 po::options_description generic("Generic options"); … … 665 677 //! 666 678 // 667 void Configuration::SetNameMapper(const string (*mapper)(const string&)) 668 { 669 fNameMapper = mapper; 679 void Configuration::SetNameMapper(const boost::function1<std::string, std::string> &func) 680 { 681 fNameMapper = func; 682 } 683 684 void Configuration::SetNameMapper() 685 { 686 fNameMapper = bind1st(mem_fun(&Configuration::DefaultMapper), this); 670 687 } 671 688 … … 902 919 // ------------------------ (11) ------------------------- 903 920 904 const po::parsed_options parsed_environment = po::parse_environment(opt_environment, *fNameMapper);921 const po::parsed_options parsed_environment = po::parse_environment(opt_environment, fNameMapper); 905 922 906 923 // ------------------------ (12) ------------------------- -
trunk/FACT++/src/Configuration.h
r10183 r10220 3 3 4 4 #include <boost/program_options.hpp> 5 /*6 \attention7 \callgraph8 \callergraph9 \category10 \dot11 \remark12 \see13 \throws14 \todo15 \warning16 17 \e italic18 \b bold19 \c typewriter20 21 \code22 \endcode23 24 \f$25 \f[ \f]26 */27 5 28 6 namespace po = boost::program_options; … … 39 17 40 18 const std::string fName; /// argv[0] 19 20 std::map<std::string, std::string> fEnvMap; 41 21 42 22 po::options_description fOptionsCommandline[2]; /// Description of the command-line options … … 59 39 60 40 /// A default mapper for environment variables skipping all of them 61 static const std::string NameMapper(const std::string &) { return ""; } 41 std::string DefaultMapper(const std::string env) 42 { 43 return fEnvMap[env]; 44 } 62 45 63 46 /// Pointer to the mapper function for environment variables 64 const std::string (*fNameMapper)(const std::string&);47 boost::function1<std::string, std::string> fNameMapper; 65 48 66 49 /// Helper function which return the max of the two arguments in the first argument … … 88 71 void AddOptionsEnvironment(const po::options_description &env, bool visible=true); 89 72 void AddOptionsDatabase(const po::options_description &db, bool visible=true); 73 void AddOptions(const po::options_description &opt, bool visible=true) 74 { 75 AddOptionsCommandline(opt, visible); 76 AddOptionsConfigfile(opt, visible); 77 AddOptionsEnvironment(opt, visible); 78 AddOptionsDatabase(opt, visible); 79 } 90 80 91 81 void SetArgumentPositions(const po::positional_options_description &desc); 92 82 93 void SetNameMapper(const std::string (*mapper)(const std::string&)); 83 void SetNameMapper(const boost::function1<std::string, std::string> &func); 84 void SetNameMapper(); 85 86 void AddEnv(const std::string &conf, const std::string &env) 87 { 88 fEnvMap[env] = conf; 89 } 94 90 95 91 // Output
Note:
See TracChangeset
for help on using the changeset viewer.