#include <config_processor.hh>
Inheritance diagram for mpcl::util::prefs::TConfigProcessor:
Public Types | |
typedef vector< TOption > | TOptionVector |
Vector of options type. | |
Public Methods | |
TConfigProcessor (void) | |
Builds a new instance. | |
TConfigProcessor (int iPARAMETER_COUNT, const char **ppkcPARAMETERS) | |
virtual | ~TConfigProcessor (void) |
Destroyes the instance. | |
virtual void | addOption (const TString &rkyNAME, const TString &rkySHORTCUT) |
virtual void | addOption (const TString &rkyNAME, const TString &rkySHORTCUT, const TString &rkyDEFAULT_VALUE) |
void | addEnvironmentVariable (const char *pkcENVIRONMENT_NAME, bool gREQUIRED=false) throw (TVariableNotFoundException) |
virtual void | processOptions (void) |
Loads options from configuration file and command-line, if any. | |
void | setConfigFileName (const char *pkcCONFIG_FILE_NAME) |
Sets configuration file name. | |
void | setCommandLineParameters (int iPARAMETER_COUNT, const char **ppkcPARAMETERS) |
void | setCurrentNameSpace (const TString &rkyNAME_SPACE) |
void | setUsageStringHeader (const TString &rkyUSAGE_HEADER) |
Sets the usage header string. | |
TString | argumentValue (size_type zARGUMENT_INDEX) const |
TString | environmentValue (const char *pkcENVIRONMENT_NAME) const |
bool | hasArguments (void) const |
size_type | numberOfArguments (void) const |
Gets number of arguments in command line. | |
TOption & | operator[] (const char *pkcNAME) throw (TVariableNotFoundException) |
const TOption & | operator[] (const char *pkcNAME) const throw (TVariableNotFoundException) |
TOption & | optionWithName (const TString &rkyNAME) |
Gets option corresponding to name rkyNAME. | |
TString | formatUsageString (void) const |
Print all options with it's help string, if any. | |
const TString | programFileName (void) const |
Gets program name. | |
void | saveConfigFile (void) const throw (TFileErrorException) |
Saves the configuration file with the current values. | |
Protected Methods | |
virtual void | processCommandLine (void) |
Updates options with command-line settings. | |
virtual void | processConfigFile (void) |
Updates options with configuration file settings. | |
void | read (std::basic_istream< char_type, traits_type > &rtSOURCE_ISTREAM) |
virtual TOption & | updateOptionWithName (const TString &rkyNAME, const TString &rkyVALUE) |
virtual TOption & | updateOptionWithShortcut (const TString &rkySHORTCUT, const TString &rkyVALUE) |
bool | isThereOptionWithName (const char *pkcNAME) const |
bool | isThereOptionWithShortcut (const char *pkcSHORTCUT) const |
unsigned int | longestOptionLength (void) const |
Returns the longest string identifiying an option (needed for formatting). | |
TString | nameSpace (const TString &rkyNAME) const |
TString | nameForShortcut (const TString &rkySHORTCUT) const |
Gets option name corresponding to shortcut rkySHORTCUT. | |
TString | shortcutForName (const TString &rkyNAME) const |
Gets option command-line name corresponding to name rkyNAME. | |
void | write (std::basic_ostream< char_type, traits_type > &rtTARGET_OSTREAM) const |
Protected Attributes | |
bool | gInputConfigFile |
Boolean that tells if there is a config-file. | |
bool | gOptionsProcessed |
Boolean that tells if options have been processed. | |
int | iParametersCount |
const char ** | ppkcParametersList |
Pointer to the array of command-line parameters. | |
vector< TString > | tCommandLineArgumentsArray |
TStringToStringMap | tEnvironmentVariableMap |
Map with environment variables. | |
TOptionVector | tOptionVector |
std::set< TString > | tValidNameSpaceSet |
Set of valid name spaces. | |
TString | yConfigFileName |
TString | yCurrentNameSpace |
TString | yUsageHeader |
String with the header of the usage message. | |
Static Protected Attributes | |
const unsigned int | _kuiMinPadding = 5 |
Minimun padding size for Usage formatting. | |
const unsigned int | _kuiTerminalWidth = 80 |
Column width for Usage formatting. |
The configuration file is searched first in the current directory and then, if it isn't found, it is searched in the "home" directory of the user (using environment variable 'HOME').
All the possible options must be initially added to the instance with its name in the configuration file, its possible name in command-line, and its default value.
The option name and the option command-line name mustn't contain any punctuation character. The next regular expression, defines then valid set of characters:
[0-9a-zA-Z_.]+
This class makes distinctions between arguments (they don't begin with hyphen(s)), and options (that begin with one or two hyphens). The arguments can be positioned in any position in the command-line (even between options).
Option names are kept internally in lowercase. Lines in configuration files beginning with '#' are ignored.
Definition at line 81 of file util/prefs/config_processor.hh.
|
Builds a new instance.
Reimplemented in mpcl::net::cgi::TConfigProcessor. Definition at line 206 of file util/prefs/config_processor.hh. References addEnvironmentVariable(), gInputConfigFile, gOptionsProcessed, iParametersCount, ppkcParametersList, programFileName(), tCommandLineArgumentsArray, tEnvironmentVariableMap, tOptionVector, tValidNameSpaceSet, yConfigFileName, yCurrentNameSpace, and yUsageHeader. |
|
Adds a new accessible environment variable. Only variables added with this member function, are recognized later. If gREQUIRED is true and variable named pkcENVIRONMENT_NAME does not exist an exception is thrown, else if gREQUIRED is false, then if variable doesn't exist, it is asigned an empty value. Definition at line 123 of file util/prefs/config_processor.cc. References mpcl::text::Format(), and mpcl::text::TString. Referenced by TConfigProcessor(), and mpcl::net::cgi::TConfigProcessor::TConfigProcessor(). |
|
Adds a new option. Only options added with this member function, are recognized later.
Definition at line 81 of file util/prefs/config_processor.cc. References mpcl::text::Format(), gOptionsProcessed, tOptionVector, mpcl::text::TString, and yCurrentNameSpace. |
|
Adds a new option. Only options added with this member function, are recognized later.
Definition at line 41 of file util/prefs/config_processor.cc. References mpcl::text::Format(), gOptionsProcessed, tOptionVector, mpcl::text::TString, and yCurrentNameSpace. |
|
Gets argument value whose index is zARGUMENT_INDEX. Arguments don't include the program name.
Definition at line 371 of file util/prefs/config_processor.hh. References tCommandLineArgumentsArray, and mpcl::text::TString. |
|
Gets environment variable value for the one named pkcENVIRONMENT_NAME (must be added before). Definition at line 380 of file util/prefs/config_processor.hh. References tEnvironmentVariableMap, and mpcl::text::TString. Referenced by mpcl::net::cgi::TAbstractApplication::fullName(), mpcl::net::cgi::TConfigProcessor::processOptions(), and mpcl::net::cgi::TAbstractApplication::TAbstractApplication(). |
|
Returns true if has arguments in command line.
Definition at line 390 of file util/prefs/config_processor.hh. References numberOfArguments(). |
|
Returns true if there is an option named pkcNAME.
|
|
Returns true if there is an option with short-cut pkcSHORTCUT.
|
|
Returns the substring from the first character to the last occurrence of the dot character (but not including it). If the string has no name space, then it returns an empty string.
Definition at line 429 of file util/prefs/config_processor.cc. References mpcl::text::TString. Referenced by read(). |
|
Gets option corresponding to name pkcNAME.
Definition at line 444 of file util/prefs/config_processor.cc. References mpcl::text::Format(), and mpcl::text::TString. |
|
Gets option corresponding to name pkcNAME.
Definition at line 474 of file util/prefs/config_processor.cc. References mpcl::text::Format(), and mpcl::text::TString. Referenced by optionWithName(). |
|
Reads the instance from stream rtSOURCE_ISTREAM.
Definition at line 249 of file util/prefs/config_processor.cc. References nameSpace(), mpcl::text::TString, tValidNameSpaceSet, updateOptionWithName(), and yConfigFileName. Referenced by processConfigFile(). |
|
Sets command-line parameters.
Definition at line 286 of file util/prefs/config_processor.hh. References gOptionsProcessed, iParametersCount, and ppkcParametersList. |
|
Sets current name space. Any option added after calling this method, will be renamed prepending to its name, the string rkyNAME_SPACE plus a dot.
Definition at line 305 of file util/prefs/config_processor.hh. References mpcl::text::TString, tValidNameSpaceSet, and yCurrentNameSpace. |
|
Updates option named rkyNAME with value rkyVALUE.
Reimplemented in mpcl::net::cgi::TConfigProcessor. Definition at line 316 of file util/prefs/config_processor.cc. References mpcl::text::Format(), tOptionVector, and mpcl::text::TString. Referenced by processCommandLine(), and read(). |
|
Updates option with shortcut rkySHORTCUT, with value rkyVALUE.
Definition at line 349 of file util/prefs/config_processor.cc. References mpcl::text::Format(), tOptionVector, and mpcl::text::TString. Referenced by processCommandLine(). |
|
Writes the instance onto stream rtTARGET_OSTREAM.
Definition at line 603 of file util/prefs/config_processor.cc. References tOptionVector. |
|
Integer with the number of command-line parameters. The term 'parameter' includes arguments and options. Definition at line 114 of file util/prefs/config_processor.hh. Referenced by processCommandLine(), mpcl::net::cgi::TConfigProcessor::processCommandLine(), setCommandLineParameters(), and TConfigProcessor(). |
|
Vector with command-line arguments. The arguments are taken from command-line and they are the parameters that aren't options. For example: executable_file --file=/etc/exec_conf main.c main.h Where "main.c" and "main.h" are arguments. Definition at line 129 of file util/prefs/config_processor.hh. Referenced by argumentValue(), numberOfArguments(), processCommandLine(), and TConfigProcessor(). |
|
Vector with options. Options are taken from command-line and from configuration file. From command-line they would appear as: executable_file --file=/etc/exec_conf executable_file -f=/etc/exec_conf -f=/var/tmp And from configuration file: : file=/etc/exec_conf file=/var/tmp : There can be quoted strings too: : command="/usr/bin/ls -l" : Definition at line 154 of file util/prefs/config_processor.hh. Referenced by addOption(), formatUsageString(), mpcl::net::cgi::TConfigProcessor::hasOption(), longestOptionLength(), nameForShortcut(), shortcutForName(), TConfigProcessor(), updateOptionWithName(), mpcl::net::cgi::TConfigProcessor::updateOptionWithName(), updateOptionWithShortcut(), and write(). |
|
String with the name of the config-file (if any). If the file can't be opened, then it will be searched in the home directory (environment variable 'HOME'). Definition at line 164 of file util/prefs/config_processor.hh. Referenced by processConfigFile(), read(), setConfigFileName(), and TConfigProcessor(). |
|
String with current name space. It is empty when options are in the root name space). Definition at line 170 of file util/prefs/config_processor.hh. Referenced by addOption(), setCurrentNameSpace(), and TConfigProcessor(). |