PUMA Library Reference Manual
Loading...
Searching...
No Matches
Puma::Config Class Reference

#include <Puma/Config.h>

Description

Load and hold PUMA configuration options in the correct order from the command line or a configuration file.

Public Types

enum  OPTIONS {
  SET_OPTION ,
  SET_OPTION_ARG
}
 Configuration option types. More...
 

Public Member Functions

 Config (ErrorStream &err)
 Constructor.
 
 Config (ErrorStream &err, const char *path)
 Constructor.
 
 Config (ErrorStream &err, int &argc, char **&argv)
 Constructor.
 
 Config (ErrorStream &err, const char *path, int &argc, char **&argv)
 Constructor.
 
 Config (const Config &copy)
 Copy-constructor.
 
 ~Config ()
 Destroy this configuration object.
 
void Join (const Config &other)
 Join this configuration with another.
 
void Read (const char *path=(const char *) 0)
 Read the given configuration file, or the file given in PUMA_CONFIG environment variable if path is NULL, or /etc/puma.config otherwise.
 
void Read (int &argc, char **&argv)
 Read configuration options from the command line and remove all recognized options from the command line.
 
void Add (const ConfOption *option)
 Add a configuration option to the configuration.
 
void Add (const char *option, bool system=false)
 Add a configuration option to the configuration.
 
void Add (const char *option, const char *arg, bool system=false)
 Add a configuration option to the configuration.
 
void Add (const char *option, const char *arg1, const char *arg2, bool system=false)
 Add a configuration option to the configuration.
 
void Remove (const ConfOption *option)
 Remove an option from the configuration.
 
unsigned Options () const
 Get the number options collected.
 
const ConfOptionOption (unsigned n) const
 Get the n-th option in this configuration.
 
const ConfOptionOption (const char *option) const
 Get a specific option in this configuration.
 
bool CustomConfigFile (int argc, char **argv)
 Check if a configuration file is given on the command line.
 
bool CustomSystemConfigFile (int argc, char **argv)
 Check if a system configuration file (lower priority options) is given on the command line.
 
void PrintOption (OptsParser::Option &option, std::ostream &os) const
 Print the given option on an output stream.
 
void PrintOptions (std::ostream &os) const
 Print the collected options on the given output stream.
 

Member Enumeration Documentation

◆ OPTIONS

Configuration option types.

Enumerator
SET_OPTION 

Option without argument.

SET_OPTION_ARG 

Option with argument.

Constructor & Destructor Documentation

◆ Config() [1/5]

Puma::Config::Config ( ErrorStream & err)
inline

Constructor.

Parameters
errThe error stream to use.

◆ Config() [2/5]

Puma::Config::Config ( ErrorStream & err,
const char * path )
inline

Constructor.

Read the given configuration file. See Read() for details.

Parameters
errThe error stream to use.
pathPath to the configuration file, or NULL.

◆ Config() [3/5]

Puma::Config::Config ( ErrorStream & err,
int & argc,
char **& argv )
inline

Constructor.

Read configuration options from the command line. See Read() for details.

Parameters
errThe error stream to use.
argcThe number of command line arguments.
argvThe command line arguments.

◆ Config() [4/5]

Puma::Config::Config ( ErrorStream & err,
const char * path,
int & argc,
char **& argv )
inline

Constructor.

Read the configuration from a configuration file and the command line. See Read() for details.

Parameters
errThe error stream to use.
pathPath to the configuration file, or NULL.
argcThe number of command line arguments.
argvThe command line arguments.

◆ Config() [5/5]

Puma::Config::Config ( const Config & copy)
inline

Copy-constructor.

Parameters
copyThe configuration to copy.

◆ ~Config()

Puma::Config::~Config ( )

Destroy this configuration object.

Member Function Documentation

◆ Add() [1/4]

void Puma::Config::Add ( const char * option,
bool system = false )
inline

Add a configuration option to the configuration.

Parameters
optionThe option to add.
systemTrue if this option shall be added as a system priority option.

◆ Add() [2/4]

void Puma::Config::Add ( const char * option,
const char * arg,
bool system = false )
inline

Add a configuration option to the configuration.

Parameters
optionThe option to add.
argThe argument or the option.
systemTrue if this option shall be added as a system priority option.

◆ Add() [3/4]

void Puma::Config::Add ( const char * option,
const char * arg1,
const char * arg2,
bool system = false )
inline

Add a configuration option to the configuration.

Parameters
optionThe option to add.
arg1The first argument or the option.
arg2The second argument or the option.
systemTrue if this option shall be added as a system priority option.

◆ Add() [4/4]

void Puma::Config::Add ( const ConfOption * option)

Add a configuration option to the configuration.

Parameters
optionThe option to add.

◆ CustomConfigFile()

bool Puma::Config::CustomConfigFile ( int argc,
char ** argv )

Check if a configuration file is given on the command line.

Parameters
argcThe number of command line arguments.
argvThe command line arguments.
Returns
True if a custom configuration file is given on the command line.

◆ CustomSystemConfigFile()

bool Puma::Config::CustomSystemConfigFile ( int argc,
char ** argv )

Check if a system configuration file (lower priority options) is given on the command line.

Parameters
argcThe number of command line arguments.
argvThe command line arguments.
Returns
True if a system custom configuration file is given on the command line.

◆ Join()

void Puma::Config::Join ( const Config & other)

Join this configuration with another.

Parameters
otherThe configuration to join with.

◆ Option() [1/2]

const ConfOption * Puma::Config::Option ( const char * option) const

Get a specific option in this configuration.

Parameters
optionThe name of the option to get.
Returns
A pointer to the option.

◆ Option() [2/2]

const ConfOption * Puma::Config::Option ( unsigned n) const

Get the n-th option in this configuration.

Parameters
nThe index of the option to get.
Returns
A pointer to the option.

◆ Options()

unsigned Puma::Config::Options ( ) const

Get the number options collected.

Returns
The number of options in this configuration.

◆ PrintOption()

void Puma::Config::PrintOption ( OptsParser::Option & option,
std::ostream & os ) const

Print the given option on an output stream.

Parameters
optionThe option to print.
osThe output stream.

◆ PrintOptions()

void Puma::Config::PrintOptions ( std::ostream & os) const

Print the collected options on the given output stream.

Parameters
osThe output stream.

◆ Read() [1/2]

void Puma::Config::Read ( const char * path = (const char *) 0)

Read the given configuration file, or the file given in PUMA_CONFIG environment variable if path is NULL, or /etc/puma.config otherwise.

Parameters
pathThe path to the configuration file, or NULL.

◆ Read() [2/2]

void Puma::Config::Read ( int & argc,
char **& argv )

Read configuration options from the command line and remove all recognized options from the command line.

Parameters
argcThe number of command line arguments.
argvThe command line arguments.

◆ Remove()

void Puma::Config::Remove ( const ConfOption * option)

Remove an option from the configuration.

Parameters
optionThe option to remove.