bes  Updated for version 3.17.4
BESKeys Class Reference

mapping of key/value pairs defining different behaviors of an application. More...

#include <BESKeys.h>

Inheritance diagram for BESKeys:
Inheritance graph

Public Types

typedef map< string, vector< string > >::const_iterator Keys_citer
 

Public Member Functions

virtual void dump (ostream &strm) const
 dumps information about this object More...
 
void get_value (const string &s, string &val, bool &found)
 Retrieve the value of a given key, if set. More...
 
void get_values (const string &s, vector< string > &vals, bool &found)
 Retrieve the values of a given key, if set. More...
 
Keys_citer keys_begin ()
 
Keys_citer keys_end ()
 
string keys_file_name () const
 
void set_key (const string &key, const string &val, bool addto=false)
 allows the user to set key/value pairs from within the application. More...
 
void set_key (const string &pair)
 allows the user to set key/value pairs from within the application. More...
 
virtual ~BESKeys ()
 cleans up the key/value pair mapping
 

Protected Member Functions

 BESKeys (const string &keys_file_name)
 default constructor that reads loads key/value pairs from the specified file. More...
 

Detailed Description

BESKeys provides a mechanism to define the behavior of an application given key/value pairs. For example, how authentication will work, database access information, level of debugging and where log files are to be located.

Key/value pairs can be loaded from an external initialization file or set within the application itself, for example from the command line.

If from a file the key/value pair is set one per line and cannot span multiple lines. Comments are allowed using the pound (#) character. For example:

#
# Who is responsible for this server
#
BES.ServerAdministrator=support@opendap.org

#
# Default server port and unix socket information and whether the server
#is secure or not.
#
BES.ServerPort=10022
BES.ServerUnixSocket=/tmp/bes.socket
BES.ServerSecure=no
* 

Key/value pairs can also be set by passing in a key=value string, or by passing in a key and value string to the object.

BES provides a single object for access to a single BESKeys object, TheBESKeys.

Definition at line 84 of file BESKeys.h.

Constructor & Destructor Documentation

◆ BESKeys()

BESKeys::BESKeys ( const string &  keys_file_name)
protected

This constructor uses the specified file to load key/value pairs. This file holds different key/value pairs for the application, one key/value pair per line separated by an equal (=) sign.

key=value

Comments are allowed in the file and must begin with a pound (#) sign at the beginning of the line. No comments are allowed at the end of lines.

Exceptions
BESInternalFatalErrorthrown if there is an error reading the initialization file or a syntax error in the file, i.e. a malformed key/value pair.

Definition at line 79 of file BESKeys.cc.

Member Function Documentation

◆ dump()

void BESKeys::dump ( ostream &  strm) const
virtual

Displays the pointer value of this instance along with all of the keys.

Parameters
strmC++ i/o stream to dump the information to

Implements BESObj.

Definition at line 536 of file BESKeys.cc.

◆ get_value()

void BESKeys::get_value ( const string &  s,
string &  val,
bool &  found 
)

This method allows the user of BESKeys to retrieve the value of the specified key. If multiple values are set then an exception is thrown.

Parameters
sThe key the user is looking for
valThe value of the key the user is looking for
foundSet to true of the key is set or false if the key is not set. The value of a key can be set to the empty string, which is why this boolean is provided.
Exceptions
BESSyntaxUserErrorif multiple values are available for the specified key

Definition at line 483 of file BESKeys.cc.

◆ get_values()

void BESKeys::get_values ( const string &  s,
vector< string > &  vals,
bool &  found 
)

This method allows the user of BESKeys to retrieve the value of the specified key.

Parameters
sThe key the user is looking for
valsThe value set for the specified key
foundSet to true of the key is set or false if the key is not set. The value of a key can be set to the empty string, which is why this boolean is provided.

Definition at line 518 of file BESKeys.cc.

◆ set_key() [1/2]

void BESKeys::set_key ( const string &  key,
const string &  val,
bool  addto = false 
)

This method allows users of BESKeys to set key/value pairs from within the application, such as for testing purposes, key/value pairs from the command line, etc...

If addto is set to true then the value is added to the list of values for key

If addto is false, and the key is already set then this value replaces all values for the key

Parameters
keyname of the key/value pair to be set
valvalue of the key to be set
addtoSpecifies whether to add the value to the key or set the value. Default is to set, not add to

Definition at line 432 of file BESKeys.cc.

◆ set_key() [2/2]

void BESKeys::set_key ( const string &  pair)

This method allows users of BESKeys to set key/value pairs from within the application, such as for testing purposes, key/value pairs from the command line, etc...

If the key is already set then this value replaces the value currently held in the keys map.

Parameters
pairthe key/value pair passed as key=value

Definition at line 460 of file BESKeys.cc.

References set_key().


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