ConfigHandler Class Reference
[ConfigHandler - Runtime configuration from command line or config files]

Global singleton ParameterList to handle all configuration. More...

#include <ConfigHandler.hh>

Inheritance diagram for ConfigHandler:
ParameterList VParameterNode

List of all members.

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 &parameter="")
 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.
ConfigHandleroperator= (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

Detailed Description

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.

Todo:
What happens if two classes try to register params/switches with the same name, especially statically?

Definition at line 35 of file ConfigHandler.hh.


Member Function Documentation

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.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on 20 Jun 2014 for daqman by  doxygen 1.6.1