Skip to content

Use Cases Requirements

Jeff Garland edited this page May 15, 2015 · 8 revisions

Basic parameters with simple option type

   options myoptions;

   option server {"server", "server host and port info", "server1:9097", 
                  "s|server", "string"};
   
   option_dir  cfg_path {"path", "path for config", "/usr/etc/myapp");
   option_file subconfig {"subconfig", "an optional cfg file to open ",
   			              "${path}/foo.cfg",  //default for file
   				      NO_CHECK};

   option_time start( "start", query start time" , 2, boost::posix_time::ptime());

   int device_count = // read from elsewhere
   for (int i; i < device_count, i++)
      myoptions.add(option_range("device" + to_string(i) + "foo", 
                                 "foo options for a device", 25, 2, 30));

   const string validTypes[3] = 
    { "xml", "json", "yaml" };
   enum ftype { XML, JSON, YAML };
   option_enum<ftype> file_types { "filetype", 
                                   "The types of files allowed", "XML", validTypes };

    myoptions.readCommandLine(argc, argv);
    myoptions.readConfigFile("path/to/file.ini");
    myoptions.process();
    myoptions.validate(vector<string> errors);
    ftype ft = myoptions.get<ftype>("filetype");
    ptime st = myoptions.get<ptime>("start"));
     //load library 
     void load() {
        //this is like Meyers singleton....loaded once at known entry point...
        static config = loadMyLibConfig();
     }
Clone this wiki locally