class __EXPORT

load text configuration files into keyword pairs. More...

Definition#include <../common/misc.h>
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Members

Protected Members


Detailed Description

Keydata objects are used to load and hold "configuration" data for a given application. Each "keydata" object holds the key pairs from a [section] of a text readable config file. The /etc directory is presumed to hold the referenced file key set unless a ~ is used.

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.

void * first (size_t size)
[protected]

Allocate first workspace from paged memory. This method scans all currently allocated blocks for available space before adding new pages and hence is both slower and more efficient.

Parameters:
sizeof memory to allocate.

Returns: pointer to allocated memory.

void * alloc (size_t size)
[protected]

Allocate memory from either the currently active page, or allocate a new page for the object.

Parameters:
sizeof memory to allocate.

Returns: pointer to allocated memory.

char * first (char *str)
[protected]

Allocate a string from the memory pager pool and copy the string into it's new memory area. This method allocates memory by first searching for an available page, and then allocating a new page if no space is found.

Parameters:
strto allocate and copy into paged memory pool.

Returns: copy of string from allocated memory.

char * alloc (char *str)
[protected]

Allocate a string from the memory pager pool and copy the string inti it's new memory area. This checks only the last active page for available space before allocating a new page.

Parameters:
strto allocate and copy into paged memory pool.

Returns: copy of string from allocated memory.

MemPager (int pagesize = 4096)
[protected]

Create a paged memory pool for cumulative storage. This pool allocates memory in fixed "pagesize" chunks. Ideal performance is achived when the pool size matches the system page size. This pool can only exist in derived objects.

Parameters:
pagesizeto allocate chunks.

void purge (void)
[protected]

purge the current memory pool.

~MemPager ()
[protected]

Delete the memory pool and all allocated memory.

inline int getPages (void)

Return the total number of pages that have been allocated for this memory pool.

Returns: number of pages allocated.

void Load (const char *keypath)
[protected]

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 /etc section, and then load a matching user specific entry from ~/. to override default system values with user specific keyword values.

Parameters:
keypath(filepath/section)

void Load (KEYDEF *pairs)
[protected]

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.

Parameters:
listof NULL terminated default keyword/value pairs.

Keydata ()

Create an empty key data object.

Keydata (const char *keypath)

Create a new key data object and use "Load" method to load an initial config file section into it.

Parameters:
keypath(filepath/section)

~Keydata ()

Destroy the keydata object and all allocated memory. This may also clear the "cache" file stream if no other keydata objects currently reference it.

void Unlink (void)

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().

int getCount (const char *sym)

Get a count of the number of data "values" that is associated with a specific keyword. Each value is from an accumulation of "load()" requests.

Parameters:
keywordsymbol name.

Returns: count of values associated with keyword.

char * getFirst (const char *sym)

Get the first data value for a given keyword. This will typically be the /etc set global default.

Parameters:
keywordsymbol name.

Returns: first set value for this symbol.

char * getLast (const char *sym)

Get the last (most recently set) value for a given keyword. This is typically the value actually used.

Parameters:
keyworksymbol name.

Returns: last set value for this symbol.

int getIndex (char **data, int max)

Get an index array of ALL keywords that are stored by the current keydata object.

Parameters:
datapointer of array to hold keyword strings.
maxnumber of entries the array can hold.

Returns: number of keywords found.

void setValue (const char *sym, const char *data)

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 getList().

Parameters:
keywordname to set.
datastring to store for the keyword.

char ** getList (const char *sym)

Return a list of all values set for the given keyword returned in order.

Parameters:
keywordname to fetch.

Returns: list pointer of array holding all keyword values.

void clrValue (const char *sym)

Clear all values associated with a given keyword. This does not de-allocate the keyword from memory, however.

Returns: keyword name to clear.

inline char * operator[] (const char *keyword)

A convient notation for accessing the keydata as an associative array of keyword/value pairs through the [] operator.

friend void endKeydata (void)

Shutdown the file stream cache. This should be used before detaching a deamon, exec(), fork(), etc.