#include <misc.h>
Inheritance diagram for Keydata::
Public Methods | |
CCXX_MEMBER_EXPORT (CCXX_EMPTY) Keydata() | |
Create an empty key data object. More... | |
CCXX_MEMBER_EXPORT (CCXX_EMPTY) Keydata(const char *keypath, const char *environment="CONFIG_KEYDATA") | |
Create a new key data object and use "Load" method to load an initial config file section into it. More... | |
CCXX_MEMBER_EXPORT (virtual)~Keydata() | |
Destroy the keydata object and all allocated memory. More... | |
CCXX_MEMBER_EXPORT (void) Unlink(void) | |
Unlink the keydata object from the cache file stream. More... | |
CCXX_MEMBER_EXPORT (int) getCount(const char *sym) | |
Get a count of the number of data "values" that is associated with a specific keyword. More... | |
CCXX_MEMBER_EXPORT (const char *) getFirst(const char *sym) | |
Get the first data value for a given keyword. More... | |
CCXX_MEMBER_EXPORT (const char *) getLast(const char *sym) | |
Get the last (most recently set) value for a given keyword. More... | |
CCXX_MEMBER_EXPORT (int) getIndex(char **data, int max) | |
Get an index array of ALL keywords that are stored by the current keydata object. More... | |
CCXX_MEMBER_EXPORT (void) setValue(const char *sym, const char *data) | |
Set (replace) the value of a given keyword. More... | |
CCXX_MEMBER_EXPORT (const char *const *) getList(const char *sym) | |
Return a list of all values set for the given keyword returned in order. More... | |
CCXX_MEMBER_EXPORT (void) clrValue(const char *sym) | |
Clear all values associated with a given keyword. More... | |
const char * | operator[] (const char *keyword) |
A convient notation for accessing the keydata as an associative array of keyword/value pairs through the [] operator. More... | |
friend | CCXX_EXPORT (void) endKeydata(void) |
Shutdown the file stream cache. More... | |
Protected Methods | |
CCXX_MEMBER_EXPORT (keysym_t *) getSymbol(const char *sym, bool create) | |
CCXX_MEMBER_EXPORT (void) Load(const char *keypath, const char *environment="CONFIG_KEYDATA") | |
Load additional key values into the currrent object from the specfied config source (a config file/section pair). More... | |
CCXX_MEMBER_EXPORT (void) Load(KEYDEF *pairs) | |
Load default keywords into the current object. More... |
This class is used to load and then hold "keyword = value
" pairs parsed from a text based "config" file that has been divided into "[sections]
". The syntax is:
[section_name]
key1=value1
key2=value2
Essentially, the "path" is a "keypath" into a theoretical namespace of key pairs, hence one does not use "real" filepaths that may be OS dependent. The "/
" path refers to "/etc
" prefixed (on UNIX) directories and this is processed within the constructor. It could refer to the /config
prefix on QNX, or even, gasp, a "C:\WINDOWS
". Hence, a keypath of "/bayonne.d/vmhost/smtp
" actually resolves to a "/etc/bayonne.d/vmhost.conf
" and loads key value pairs from the [smtp]
section of that .conf
file.
Similarly, something like "~bayonne/smtp
" path refers to a "~/.bayonnerc
" and loads key pairs from the [smtp]
section. This coercion occurs before the name is passed to the open call.
I actually use derived keydata based classes as global initialized objects, and they hence automatically load and parse config file entries even before "main" has started.
Keydata can hold multiple values for the same key pair. This can occur either from storing a "list" of data items in a config file, or when overlaying multiple config sources (such as /etc/....conf
and ~/.confrc
segments) into a single object. The keys are stored as cumulative (read-only/replacable) config values under a hash index system for quick retrieval.
Keydata can also load a table of "initialization" values for keyword pairs that were not found in the external file.
One typically derives an application specific keydata class to load a specific portion of a known config file and initialize it's values. One can then declare a global instance of these objects and have configuration data initialized automatically as the executable is loaded.
Hence, if I have a "[paths]" section in a "/etc/server.conf?
" file, I might define something like:
class KeyPaths : public Keydata
{
public:
KeyPaths() : Keydata("/server/paths")
{
static KEYDEF *defvalues = {
{"datafiles", "/var/server"},
{NULL, NULL}};
// override with [paths] from "~/.serverrc" if avail.
Load("~server/paths");
Load(defvalues);
}
};
KeyPaths keypaths;
|
Shutdown the file stream cache.
This should be used before detaching a deamon, |
|
Clear all values associated with a given keyword. This does not de-allocate the keyword from memory, however.
|
|
Return a list of all values set for the given keyword returned in order.
|
|
Set (replace) the value of a given keyword.
This new value will become the value returned from getLast(), while the prior value will still be stored and found from
|
|
Get an index array of ALL keywords that are stored by the current keydata object.
|
|
Get the last (most recently set) value for a given keyword. This is typically the value actually used.
|
|
Get the first data value for a given keyword.
This will typically be the
|
|
Get a count of the number of data "values" that is associated with a specific keyword.
Each value is from an accumulation of "
|
|
Unlink the keydata object from the cache file stream. This should be used if you plan to keepa Keydata object after it is loaded once all keydata objects have been loaded, otherwise the cfgFile stream will remain open. You can also use endKeydata(). |
|
Destroy the keydata object and all allocated memory. This may also clear the "cache" file stream if no other keydata objects currently reference it. |
|
Create a new key data object and use "Load" method to load an initial config file section into it.
|
|
Create an empty key data object.
|
|
Load default keywords into the current object. This only loads keyword entries which have not already been defined to reduce memory usage. This form of Load is also commonly used in the constructor of a derived Keydata class.
|
|
Load additional key values into the currrent object from the specfied config source (a config file/section pair).
These values will overlay the current keywords when matches are found. This can be used typically in a derived config object class constructor to first load a
|
|
|
|
A convient notation for accessing the keydata as an associative array of keyword/value pairs through the [] operator.
|