Global singleton ParameterList to handle all configuration. More...
#include <ConfigHandler.hh>
Classes | |
class | CommandSwitch |
Concrete implementation of VCommandSwitch. More... | |
struct | OrderCommandSwitchPointers |
utility class for sorting command switches More... | |
class | VCommandSwitch |
Abstract base class represents command line switch for containers. More... | |
Public Member Functions | |
template<class Action > | |
int | AddCommandSwitch (char shortname, const std::string &longname, const std::string &helptext, Action action, const std::string ¶meter="") |
Add a command line switch. | |
int | RemoveCommandSwitch (char shortname, const std::string &longname) |
Remove a previously registered command line switch. | |
void | PrintSwitches (bool quit=true, std::ostream &out=std::cout, bool escape=false) |
Prints info for the registered switches. | |
void | SetProgramUsageString (const std::string &usage) |
Set the usage string given by the '-h' or '--help' options. | |
std::string | GetProgramUsageString () |
Get the program usage string. | |
void | SetProgramDescription (const std::string &d) |
Set the program's description. | |
std::string | GetProgramDescription () |
Get the program's description. | |
int | ProcessCommandLine (int &argc, char **argv) |
int | GetNCommandArgs () |
const char * | GetCommandArg (size_t n) |
Get the nth non-switch command line argument. | |
void | SetSavedCfgFile (const std::string &fname) |
Allow classes to read an OLD config file without changing current params. | |
const std::string & | GetSavedCfgFile () |
Allow classes to read a separate config file than the active one. | |
template<class T > | |
bool | LoadCreateParameterList (T *&par, std::string key="", bool registerme=false) |
Load a parameter list from an old config file. | |
template<class T > | |
bool | LoadParameterList (T *par, std::string key="", bool registerme=false) |
Load a parameter list from an old config file with pointer value. | |
void | SetNotes (const std::string &newnotes) |
Set the notes string. | |
const std::string & | GetNotes () |
Get the string containing the notes for this program. | |
void | SetDefaultCfgFile (const std::string &file) |
Set the default cfg file. | |
const std::string & | GetDefaultCfgFile () |
Get the default config file. | |
std::string | FindConfigFile (const std::string &fname) |
Static Public Member Functions | |
static ConfigHandler *const | GetInstance () |
Get the global singleton pointer - only way to construct. | |
Private Types | |
typedef std::set < VCommandSwitch *, OrderCommandSwitchPointers > | SwitchSet |
Private Member Functions | |
ConfigHandler () | |
Default constructor is private; singleton implementation. | |
~ConfigHandler () | |
Destructor also private. | |
ConfigHandler (const ConfigHandler &right) | |
Copy constructor private. | |
ConfigHandler & | operator= (const ConfigHandler &right) |
Copy constructor private. | |
Private Attributes | |
std::string | _program_usage |
String detailing how to use program. | |
std::string | _program_description |
String describing the program. | |
std::string | _notes |
specify comments in a config file | |
std::string | _default_cfg_file |
default config file for this program | |
std::string | _saved_cfg |
name of old config file | |
std::vector< std::string > | _cfg_paths |
list of paths to search for cfg files | |
std::vector< char * > | _cmd_args |
command-line arguments read | |
SwitchSet | _switches |
set of all registered command switches |
Global singleton ParameterList to handle all configuration.
Classes which want their parameters handled by the master config file or which want to have command line switches should register them with ConfigHandler at the beginning of main(), or during a static initialization routine.
Definition at line 35 of file ConfigHandler.hh.
int ConfigHandler::ProcessCommandLine | ( | int & | argc, | |
char ** | argv | |||
) |
Process the command line for the registered switches. Returns 0 in case of success
Definition at line 212 of file ConfigHandler.cc.
int ConfigHandler::GetNCommandArgs | ( | ) | [inline] |
Get the number of non-switch arguments to the command line. Rreturns neg if command line has not been processed yet
Definition at line 88 of file ConfigHandler.hh.