bes Updated for version 3.20.13
|
mapping of key/value pairs defining different behaviors of an application. More...
#include <TheBESKeys.h>
Public Types | |
typedef std::map< std::string, std::vector< std::string > >::const_iterator | Keys_citer |
Public Member Functions | |
virtual std::string | dump () const |
dumps information about this object | |
virtual void | dump (std::ostream &strm) const |
dumps information about this object | |
std::string | get_as_config () const |
void | get_value (const std::string &s, std::string &val, bool &found) |
Retrieve the value of a given key, if set. | |
void | get_values (const std::string &, std::map< std::string, std::map< std::string, std::vector< std::string > > > &map, const bool &case_insensitive_map_keys, bool &found) |
void | get_values (const std::string &, std::map< std::string, std::string > &map_values, const bool &case_insensitive_map_keys, bool &found) |
void | get_values (const std::string &s, std::vector< std::string > &vals, bool &found) |
Retrieve the values of a given key, if set. | |
Keys_citer | keys_begin () |
Keys_citer | keys_end () |
std::string | keys_file_name () const |
void | load_dynamic_config (std::string name) |
Loads the the applicable dynamic configuration or nothing if no configuration is applicable. | |
bool | read_bool_key (const std::string &key, bool default_value) |
Read a boolean-valued key from the bes.conf file. | |
int | read_int_key (const std::string &key, int default_value) |
Read an integer-valued key from the bes.conf file. | |
std::string | read_string_key (const std::string &key, const std::string &default_value) |
Read a string-valued key from the bes.conf file. | |
void | set_key (const std::string &key, const std::string &val, bool addto=false) |
allows the user to set key/value pairs from within the application. | |
void | set_key (const std::string &pair) |
allows the user to set key/value pairs from within the application. | |
void | set_keys (const std::string &key, const std::map< std::string, std::string > &values, const bool case_insensitive_map_keys, bool addto) |
allows the user to encode a map in the Keys from within the application. | |
void | set_keys (const std::string &key, const std::vector< std::string > &values, bool addto) |
allows the user to set key/value pairs from within the application. | |
bool | using_dynamic_config () |
virtual | ~TheBESKeys () |
cleans up the key/value pair mapping | |
Static Public Member Functions | |
static TheBESKeys * | TheKeys () |
Static Public Attributes | |
static std::string | ConfigFile = "" |
static TheBESKeys * | d_instance = 0 |
Protected Member Functions | |
TheBESKeys (const std::string &keys_file_name) | |
default constructor that reads loads key/value pairs from the specified file. | |
Friends | |
class | keysT |
mapping of key/value pairs defining different behaviors of an application.
TheBESKeys 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=email: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 85 of file TheBESKeys.h.
typedef std::map<std::string,std::vector<std::string>>::const_iterator TheBESKeys::Keys_citer |
Definition at line 167 of file TheBESKeys.h.
|
protected |
default constructor that reads loads key/value pairs from the specified file.
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.
BESInternalFatalError | thrown 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 123 of file TheBESKeys.cc.
|
virtual |
cleans up the key/value pair mapping
Definition at line 141 of file TheBESKeys.cc.
|
virtual |
dumps information about this object
Definition at line 486 of file TheBESKeys.cc.
|
virtual |
dumps information about this object
Displays the pointer value of this instance along with all of the keys.
strm | C++ i/o stream to dump the information to |
Implements BESObj.
Definition at line 476 of file TheBESKeys.cc.
string TheBESKeys::get_as_config | ( | ) | const |
Definition at line 528 of file TheBESKeys.cc.
void TheBESKeys::get_value | ( | const std::string & | s, |
std::string & | val, | ||
bool & | found | ||
) |
Retrieve the value of a given key, if set.
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.
s | The key the user is looking for |
val | The value of the key the user is looking for |
found | Set 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. |
BESSyntaxUserError | if multiple values are available for the specified key |
Definition at line 340 of file TheBESKeys.cc.
void TheBESKeys::get_values | ( | const std::string & | key, |
std::map< std::string, std::map< std::string, std::vector< std::string > > > & | primary_map, | ||
const bool & | case_insensitive_map_keys, | ||
bool & | found | ||
) |
key | |
map_values | |
case_insensitive_map_keys | |
found |
Definition at line 611 of file TheBESKeys.cc.
void TheBESKeys::get_values | ( | const std::string & | key, |
std::map< std::string, std::string > & | map_values, | ||
const bool & | case_insensitive_map_keys, | ||
bool & | found | ||
) |
key | |
map_values | |
case_insensitive_map_keys | |
found |
Definition at line 576 of file TheBESKeys.cc.
void TheBESKeys::get_values | ( | const std::string & | s, |
std::vector< std::string > & | vals, | ||
bool & | found | ||
) |
Retrieve the values of a given key, if set.
This method allows the user of BESKeys to retrieve the value of the specified key.
s | The key the user is looking for |
vals | The value set for the specified key |
found | Set 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 371 of file TheBESKeys.cc.
|
inline |
Definition at line 169 of file TheBESKeys.h.
|
inline |
Definition at line 173 of file TheBESKeys.h.
|
inline |
Definition at line 137 of file TheBESKeys.h.
void TheBESKeys::load_dynamic_config | ( | std::string | name | ) |
Loads the the applicable dynamic configuration or nothing if no configuration is applicable.
name |
Definition at line 682 of file TheBESKeys.cc.
Read a boolean-valued key from the bes.conf file.
Look-up the bes key
key | The key to loop up |
default_value | Return this value if
|
Definition at line 398 of file TheBESKeys.cc.
Read an integer-valued key from the bes.conf file.
Look-up the bes key
key | The key to loop up |
default_value | Return this value if
|
Definition at line 450 of file TheBESKeys.cc.
string TheBESKeys::read_string_key | ( | const std::string & | key, |
const std::string & | default_value | ||
) |
Read a string-valued key from the bes.conf file.
Look-up the bes key
key | The key to loop up |
default_value | Return this value if
|
Definition at line 423 of file TheBESKeys.cc.
void TheBESKeys::set_key | ( | const std::string & | key, |
const std::string & | val, | ||
bool | addto = false |
||
) |
allows the user to set key/value pairs from within the application.
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
key | name of the key/value pair to be set |
val | value of the key to be set |
addto | Specifies whether to add the value to the key or set the value. Default is to set, not add to |
Definition at line 206 of file TheBESKeys.cc.
void TheBESKeys::set_key | ( | const std::string & | pair | ) |
allows the user to set key/value pairs from within the application.
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.
pair | the key/value pair passed as key=value |
Definition at line 317 of file TheBESKeys.cc.
void TheBESKeys::set_keys | ( | const std::string & | key, |
const std::map< std::string, std::string > & | values, | ||
const bool | case_insensitive_map_keys, | ||
bool | addto | ||
) |
allows the user to encode a map in the Keys from within the application.
This method allows users of BESKeys to set the value of a kep to be a map of 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
key | name of the key/value pair to be set |
values | A map of key value pairs to associate with the key |
addto | Specifies whether to append the values to the key or set the value. Default is to set, not append to |
Definition at line 272 of file TheBESKeys.cc.
void TheBESKeys::set_keys | ( | const std::string & | key, |
const std::vector< std::string > & | values, | ||
bool | addto | ||
) |
allows the user to set key/value pairs from within the application.
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
key | name of the key/value pair to be set |
values | A collection of values to to associate with the key |
addto | Specifies whether to append the values to the key or set the value. Default is to set, not append to |
Definition at line 236 of file TheBESKeys.cc.
|
static |
Access to the singleton.
Definition at line 71 of file TheBESKeys.cc.
bool TheBESKeys::using_dynamic_config | ( | ) |
Definition at line 674 of file TheBESKeys.cc.
|
friend |
Definition at line 87 of file TheBESKeys.h.
|
static |
TheBESKeys::ConfigFile provides a way for the daemon and test code to set the location of a particular configuration file.
Definition at line 185 of file TheBESKeys.h.
|
static |
Definition at line 133 of file TheBESKeys.h.