TaPAS  0.2
Macros | Typedefs | Functions
ccl-config-table.h File Reference

Implementation of some kind of "preferences" table. More...

#include <ccl/ccl-common.h>
#include <ccl/ccl-list.h>

Go to the source code of this file.

Macros

#define ccl_config_table_create()   ccl_config_table_inherits (NULL)
 Builds an empty table.
 

Typedefs

typedef struct ccl_config_table_st ccl_config_table
 Abstract type for "preferences" table.
 

Functions

ccl_config_tableccl_config_table_add_reference (ccl_config_table *conf)
 Adds one reference to conf. More...
 
void ccl_config_table_del_reference (ccl_config_table *conf)
 Removes one reference to conf. More...
 
ccl_config_tableccl_config_table_inherits (ccl_config_table *parent)
 Builds a locally empty table but inherits content from parent. More...
 
int ccl_config_table_is_changed (ccl_config_table *conf)
 Checks if the content of the table has changed. More...
 
void ccl_config_table_set (ccl_config_table *conf, const char *name, const char *value)
 Adds the couple (name, value) into conf. More...
 
int ccl_config_table_has (ccl_config_table *conf, const char *name)
 Checks if the table conf contains an entry for the option name. More...
 
const char * ccl_config_table_set_if_null (ccl_config_table *conf, const char *name, const char *value)
 Add the couple (name, value) if the entry does not exist. More...
 
void ccl_config_table_add (ccl_config_table *conf, ccl_config_table *others)
 Adds all (local) preferences of others to conf. More...
 
const char * ccl_config_table_get (ccl_config_table *conf, const char *name)
 Returns the value for the configuration option name. More...
 
int ccl_config_table_get_integer (ccl_config_table *conf, const char *name)
 Returns the value for the configuration option name but the value is interpreted as an integer. More...
 
int ccl_config_table_get_boolean (ccl_config_table *conf, const char *name)
 Returns the value for the configuration option name but the value is interpreted as a Boolean value. More...
 
ccl_listccl_config_table_get_names (ccl_config_table *conf)
 Returns the list of valued options. More...
 
void ccl_config_table_save (ccl_config_table *conf, FILE *output)
 Writes the content of conf onto the output stream. More...
 
void ccl_config_table_load (ccl_config_table *conf, FILE *input)
 Reads configuration options from the input stream and adds them into the conf table. More...
 
void ccl_config_table_display (ccl_config_table *conf)
 Display on the CCL_LOG_DISPLAY stream the entries of conf. More...
 

Detailed Description

Implementation of some kind of "preferences" table.

This module implements hierarchical associative tables. Each ccl_config_table stores couple of strings (identifier, value). A table may inherits content from another which means that is an identifier is not found locally in a table, the search is transfered to the parent table (until the identifier is found or no more ancestor exists).

Definition in file ccl-config-table.h.

Function Documentation

void ccl_config_table_add ( ccl_config_table conf,
ccl_config_table others 
)

Adds all (local) preferences of others to conf.

Parameters
confthe configuration table
othersanother configuration table
Precondition
conf != NULL
others != NULL
ccl_config_table* ccl_config_table_add_reference ( ccl_config_table conf)

Adds one reference to conf.

The function increments the counter of references of conf.

Parameters
confthe configuration table
Precondition
conf != NULL
Returns
conf
void ccl_config_table_del_reference ( ccl_config_table conf)

Removes one reference to conf.

If the counter of references of conf falls to zero then the resources allocated to conf are released.

Parameters
confthe configuration table
Precondition
conf != NULL
void ccl_config_table_display ( ccl_config_table conf)

Display on the CCL_LOG_DISPLAY stream the entries of conf.

Parameters
confthe configuration table
Precondition
conf != NULL
const char* ccl_config_table_get ( ccl_config_table conf,
const char *  name 
)

Returns the value for the configuration option name.

If the option is not found then a message is sent on CCL_LOG_WARNING.

Parameters
confthe configuration table
namethe name of the option
Precondition
conf != NULL
name != NULL
Returns
the value for the configuration option name or NULL if the option is not set.
int ccl_config_table_get_boolean ( ccl_config_table conf,
const char *  name 
)

Returns the value for the configuration option name but the value is interpreted as a Boolean value.

Parameters
confthe configuration table
namethe name of the option
Precondition
conf != NULL
name != NULL
Returns
the value for the configuration option name but the value is interpreted as a Boolean value.
int ccl_config_table_get_integer ( ccl_config_table conf,
const char *  name 
)

Returns the value for the configuration option name but the value is interpreted as an integer.

Parameters
confthe configuration table
namethe name of the option
Precondition
conf != NULL
name != NULL
Returns
the value for the configuration option name but the value is interpreted as an integer.
ccl_list* ccl_config_table_get_names ( ccl_config_table conf)

Returns the list of valued options.

The function collects in conf and its parents the name of options that have been set.

Parameters
confthe configuration table
Precondition
conf != NULL
Returns
a newly allocated list of strings. Strings contained into the list must not be deleted.
int ccl_config_table_has ( ccl_config_table conf,
const char *  name 
)

Checks if the table conf contains an entry for the option name.

Parameters
confthe configuration table
namethe name of the configuration option
Precondition
conf != NULL
name != NULL
Returns
a non-null value if conf contains an entry for the option name.
ccl_config_table* ccl_config_table_inherits ( ccl_config_table parent)

Builds a locally empty table but inherits content from parent.

Parameters
parentthe configuration table used as parent
Precondition
parent != NULL
Returns
a new empty table
int ccl_config_table_is_changed ( ccl_config_table conf)

Checks if the content of the table has changed.

The table maintains a flag indicating if the value of one entry has been changed since the creation of the table or its loading. New entries are no considered here.

Parameters
confthe configuration table
Precondition
conf != NULL
Returns
a non-null value if the content of conf or those of one of its parents has changed.
void ccl_config_table_load ( ccl_config_table conf,
FILE *  input 
)

Reads configuration options from the input stream and adds them into the conf table.

input must be a stream containing data previously saved with the ccl_config_table_save function.

Parameters
confthe configuration table
inputthe input stream
Precondition
conf != NULL
input != NULL
void ccl_config_table_save ( ccl_config_table conf,
FILE *  output 
)

Writes the content of conf onto the output stream.

Parameters
confthe configuration table
outputthe output stream
Precondition
conf != NULL
output != NULL
void ccl_config_table_set ( ccl_config_table conf,
const char *  name,
const char *  value 
)

Adds the couple (name, value) into conf.

If the entry name exists in the table then the old value is replaced.

Parameters
confthe configuration table
namethe option name
valuethe value of the option
Precondition
conf != NULL
name != NULL
value != NULL
const char* ccl_config_table_set_if_null ( ccl_config_table conf,
const char *  name,
const char *  value 
)

Add the couple (name, value) if the entry does not exist.

If the entry name does not exist in conf, then the entry is created with the couple (name, value); else, the existing value is not modified.

Parameters
confthe configuration table
namethe name of the option to assign
valuethe value assigned to the option
Precondition
conf != NULL
name != NULL
value != NULL
Returns
the value of the option name