nis-util  1.0.D108
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
configuration Class Reference

#include <configuration.h>

Public Types

typedef boost::shared_ptr
< configuration
pointer
typedef
configuration_section::level_t 
level_t

Public Member Functions

rcstring get_string (const rcstring &section_name, const rcstring &item_name) const
long get_long (const rcstring &section_name, const rcstring &item_name) const
bool get_bool (const rcstring &section_name, const rcstring &item_name) const
void load_command_line_file (const rcstring &filename)
void set_command_line_string (const source_location &locn, const rcstring &section_name, const rcstring &item_name, const rcstring &value)
void set_command_line_long (const source_location &locn, const rcstring &section_name, const rcstring &item_name, long value)
void set_command_line_bool (const source_location &locn, const rcstring &section_name, const rcstring &item_name, bool value)
void set_command_line_bool (const source_location &locn, const rcstring &item_name, bool value)
void set_builtin_string (const rcstring &section_name, const rcstring &item_name, const rcstring &value)
void set_builtin_long (const rcstring &section_name, const rcstring &item_name, long value)
void set_builtin_bool (const rcstring &section_name, const rcstring &item_name, bool value)
void print (void) const

Static Public Member Functions

static configurationget_singleton (void)

Private Types

typedef std::map< rcstring,
configuration_section::pointer
sections_t

Private Member Functions

virtual ~configuration ()
 configuration ()
void load (void)
void parse (level_t level, const input::pointer &src)
void set (const rcstring &section_name, const configuration_item::pointer &item)
 configuration (const configuration &rhs)
configurationoperator= (const configuration &rhs)

Static Private Member Functions

static rcstring canonical_name (const rcstring &name)

Private Attributes

sections_t sections

Static Private Attributes

static configurationsingleton

Detailed Description

The configuration class is used to represent the storage and access of configuration data.

There are several sources of configuration data: 1. the built-in default 2. the /etc/nis-util.conf file 3. the ~/.nis-utilrc file 4. the NIS_UTIL evironment variable 5. the util-specific environment variable 6. cfg file given on the command line 7. command line options

Definition at line 40 of file configuration.h.


Member Typedef Documentation

Definition at line 45 of file configuration.h.

typedef boost::shared_ptr<configuration> configuration::pointer

Definition at line 43 of file configuration.h.

Definition at line 296 of file configuration.h.


Constructor & Destructor Documentation

configuration::~configuration ( ) [private, virtual]

The destructor.

Definition at line 38 of file configuration.cc.

The default constructor. It is private on purpose, use the get_singleton class method instead.

Definition at line 43 of file configuration.cc.

configuration::configuration ( const configuration rhs) [private]

The copy constructor. Do not use.

Parameters:
rhsThe right hand side of the initialization.

Member Function Documentation

rcstring configuration::canonical_name ( const rcstring name) [static, private]

The canonical_name class method is used to convert a string into a canonical section name or item name.

Definition at line 31 of file parse.cc.

bool configuration::get_bool ( const rcstring section_name,
const rcstring item_name 
) const

The get_bool method is used to obtain a boolean configuration value.

Parameters:
section_nameThe name of the section the configuration item appears within, or the empty string for global configuration values.
item_nameThe name of the item, within the section. Names within sections are unique to each section.
Returns:
The value of the item as a boolean. If not set, false will be returned. If the value cannot be interpreted as a boolean, false will be returned.

Definition at line 73 of file configuration.cc.

long configuration::get_long ( const rcstring section_name,
const rcstring item_name 
) const

The get_long method is used to obtain an integer configuration value.

Parameters:
section_nameThe name of the section the configuration item appears within, or the empty string for global configuration values.
item_nameThe name of the item, within the section. Names within sections are unique to each section.
Returns:
The value of the item as an integer. If not set, zero will be returned. If the value cannot be interpreted as an integer, zero will be returned.

Definition at line 85 of file configuration.cc.

The get_singleton class method is used to obtain a reference to the configuration data, possibly reading the configuration sources if required.

Definition at line 49 of file configuration.cc.

rcstring configuration::get_string ( const rcstring section_name,
const rcstring item_name 
) const

The get_string method is used to obtain a string configuration value.

Parameters:
section_nameThe name of the section the configuration item appears within, or the empty string for global configuration values.
item_nameThe name of the item, within the section. Names within sections are unique to each section.
Returns:
The value of the item as a string. If not set, the empty string will be returned.

Definition at line 61 of file configuration.cc.

void configuration::load ( void  ) [private]

The load method is used to load all of the various configuration sources (environment variables, sys cfg files, user cfg files, etc).

Definition at line 142 of file configuration.cc.

void configuration::load_command_line_file ( const rcstring filename)

The load_command_line_file method is used to load a configuration file given on the command line using the --ConFiGuration=filename option.

Configuration file specified on the command line take precedence over everything except specific command line options, e.g. via the set_command_line_string, set_command_line_long and set_command_line_bool methods.

Parameters:
filenameThe name of the file to be read, or "-" to indocate the standard input.

Definition at line 212 of file configuration.cc.

configuration& configuration::operator= ( const configuration rhs) [private]

The assignment operator. Do not use.

Parameters:
rhsThe right hand side of the assignment.
void configuration::parse ( level_t  level,
const input::pointer src 
) [private]

The parse method is used to read the given input (usually a file, but not always and squirrel away each of the configuration settings, provided they are of higher precedence than any extant setting.

Parameters:
levelThe configuration level (or precedence) of the settings within the file being parsed.
srcThe source of input being parsed.

Definition at line 61 of file parse.cc.

void configuration::print ( void  ) const

The print method is used to print the configuration data to the standard output. Mostly useful for debugging.

Definition at line 305 of file configuration.cc.

void configuration::set ( const rcstring section_name,
const configuration_item::pointer item 
) [private]

The set method is used to insert a configuration item into the known settings, provoded it is a high enough precedence level.

This is intentionally private, to re-inforce the idea that settings must not be able to be given arbitrary precedence levels.

Parameters:
section_nameThe section the setting blongs in, or "" for the global section.
itemThe item to be inserted in the named section.

Definition at line 97 of file configuration.cc.

void configuration::set_builtin_bool ( const rcstring section_name,
const rcstring item_name,
bool  value 
)

The set_builtin_bool method is used to set a boolean configuration item with builtin precedence (the lowest precedence).

Parameters:
section_nameThe name of the section the configuration item appears within, or the empty string for global configuration values.
item_nameThe name of the item, within the section. Names within sections are unique to each section.
valueThe new value of the item.

Definition at line 293 of file configuration.cc.

void configuration::set_builtin_long ( const rcstring section_name,
const rcstring item_name,
long  value 
)

The set_builtin_long method is used to set an integer configuration item with builtin precedence (the lowest precedence).

Parameters:
section_nameThe name of the section the configuration item appears within, or the empty string for global configuration values.
item_nameThe name of the item, within the section. Names within sections are unique to each section.
valueThe new value of the item.

Definition at line 281 of file configuration.cc.

void configuration::set_builtin_string ( const rcstring section_name,
const rcstring item_name,
const rcstring value 
)

The set_builtin_string method is used to set a string configuration item with builtin precedence (the lowest precedence).

Parameters:
section_nameThe name of the section the configuration item appears within, or the empty string for global configuration values.
item_nameThe name of the item, within the section. Names within sections are unique to each section.
valueThe new value of the item.

Definition at line 269 of file configuration.cc.

void configuration::set_command_line_bool ( const source_location locn,
const rcstring section_name,
const rcstring item_name,
bool  value 
)

The set_command_line_bool method is used to set a boolean configuration item from the command line.

The command line options take precendence over all other configuration settings.

Parameters:
locnThe source code location of the setting
section_nameThe name of the section the configuration item appears within, or the empty string for global configuration values.
item_nameThe name of the item, within the section. Names within sections are unique to each section.
valueThe new value of the item.

Definition at line 244 of file configuration.cc.

void configuration::set_command_line_bool ( const source_location locn,
const rcstring item_name,
bool  value 
)

The set_command_line_bool method is used to set a boolean configuration item from the command line. It will be placed in the global section.

The command line options take precendence over all other configuration settings.

Parameters:
locnThe source code location of the setting
item_nameThe name of the item, within the section. Names within sections are unique to each section.
valueThe new value of the item.

Definition at line 255 of file configuration.cc.

void configuration::set_command_line_long ( const source_location locn,
const rcstring section_name,
const rcstring item_name,
long  value 
)

The set_command_line_long method is used to set an integer configuration item from the command line.

The command line options take precendence over all other configuration settings.

Parameters:
locnThe source code location of the setting
section_nameThe name of the section the configuration item appears within, or the empty string for global configuration values.
item_nameThe name of the item, within the section. Names within sections are unique to each section.
valueThe new value of the item.

Definition at line 233 of file configuration.cc.

void configuration::set_command_line_string ( const source_location locn,
const rcstring section_name,
const rcstring item_name,
const rcstring value 
)

The set_command_line_string method is used to set a string configuration item from the command line.

The command line options take precendence over all other configuration settings.

Parameters:
locnThe source code location of the setting
section_nameThe name of the section the configuration item appears within, or the empty string for global configuration values.
item_nameThe name of the item, within the section. Names within sections are unique to each section.
valueThe new value of the item.

Definition at line 221 of file configuration.cc.


Field Documentation

The sections instance variable is used to remember all of the sections specified in the various configuration sources. This is added to by the set method, and read by the various "get" methods.

Definition at line 304 of file configuration.h.

The singleton class variable is used to remember the one instance of this class for the whole program. It is instantiated by the get_singleton class method.

Definition at line 311 of file configuration.h.


The documentation for this class was generated from the following files: