Ignore:
Timestamp:
03/03/11 19:28:48 (14 years ago)
Author:
tbretz
Message:
Added fEnvMap and a default name mapper.
File:
1 edited

Legend:

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

    r10198 r10220  
    166166If the second option is false, the options will not be displayed in any
    167167\b --help directive, but are available to the user. Each of the functions
    168 can be called more than once.
     168can be called more than once. If an option should be available from
     169all kind of inputs AddOptions() can be used which will call all
     170four other AddOptions() functions.
    169171
    170172A 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
     173want to use the same option-key for the command-line and the environment,
    172174a 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:
     175can be implemented by a mapping function or by the build in mapping
     176and be initialized like this:
    174177
    175178\code
    176179
    177    const string name_mapper(const string &str)
     180   conf.AddEnv("path", "PATH");
     181
     182\endcode
     183
     184or
     185
     186\code
     187
     188   const string name_mapper(const string str)
    178189   {
    179190      return str=="PATH" ? "path" : "";
     
    421432//!
    422433//
    423 Configuration::Configuration(const string &prgname) : fName(prgname), fNameMapper(&NameMapper)
     434Configuration::Configuration(const string &prgname) : fName(prgname),
     435fNameMapper(bind1st(mem_fun(&Configuration::DefaultMapper), this))
    424436{
    425437    po::options_description generic("Generic options");
     
    665677//!
    666678//
    667 void Configuration::SetNameMapper(const string (*mapper)(const string&))
    668 {
    669     fNameMapper = mapper;
     679void Configuration::SetNameMapper(const boost::function1<std::string, std::string> &func)
     680{
     681    fNameMapper = func;
     682}
     683
     684void Configuration::SetNameMapper()
     685{
     686    fNameMapper = bind1st(mem_fun(&Configuration::DefaultMapper), this);
    670687}
    671688
     
    902919    // ------------------------ (11) -------------------------
    903920
    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);
    905922
    906923    // ------------------------ (12) -------------------------
Note: See TracChangeset for help on using the changeset viewer.