Base class for configuration databases. More...
#include <Configuration.h>
Public Types | |
enum | VALUETYPE { STRING, INTEGER, BINARY, INVALID } |
Enumeration for the various types of values we can store. More... | |
Public Member Functions | |
virtual | ~ACE_Configuration (void) |
Destructor. | |
virtual const ACE_Configuration_Section_Key & | root_section (void) const |
Obtain a reference to the root section of this configuration. | |
virtual int | open_section (const ACE_Configuration_Section_Key &base, const ACE_TCHAR *sub_section, int create, ACE_Configuration_Section_Key &result)=0 |
virtual int | remove_section (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *sub_section, bool recursive)=0 |
Removes a named section. | |
virtual int | enumerate_values (const ACE_Configuration_Section_Key &key, int index, ACE_TString &name, VALUETYPE &type)=0 |
virtual int | enumerate_sections (const ACE_Configuration_Section_Key &key, int index, ACE_TString &name)=0 |
virtual int | set_string_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, const ACE_TString &value)=0 |
Sets a string-typed value. | |
virtual int | set_integer_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, u_int value)=0 |
Sets a integer-typed value. | |
virtual int | set_binary_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, const void *data, size_t length)=0 |
Sets a binary-typed value. | |
virtual int | get_string_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, ACE_TString &value)=0 |
Gets a string-typed value. | |
virtual int | get_integer_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, u_int &value)=0 |
Gets an integer-typed value. | |
virtual int | get_binary_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, void *&data, size_t &length)=0 |
Gets a binary-typed value. | |
virtual int | find_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, VALUETYPE &type)=0 |
virtual int | remove_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name)=0 |
Removes a named value. | |
int | expand_path (const ACE_Configuration_Section_Key &key, const ACE_TString &path_in, ACE_Configuration_Section_Key &key_out, int create=1) |
int | export_config (const ACE_TCHAR *filename) |
int | import_config (const ACE_TCHAR *filename) |
bool | operator== (const ACE_Configuration &rhs) const |
bool | operator!= (const ACE_Configuration &rhs) const |
Static Public Attributes | |
static ACE_TCHAR | NULL_String_ = '\0' |
Protected Member Functions | |
ACE_Configuration (void) | |
Default ctor. | |
ACE_Section_Key_Internal * | get_internal_key (const ACE_Configuration_Section_Key &key) |
Resolves the internal key from a section key. | |
int | validate_name (const ACE_TCHAR *name, int allow_path=0) |
int | validate_value_name (const ACE_TCHAR *name) |
ACE_Configuration (const ACE_Configuration &rhs) | |
ACE_Configuration & | operator= (const ACE_Configuration &rhs) |
Protected Attributes | |
ACE_Configuration_Section_Key | root_ |
Base class for configuration databases.
For internal use only.
This class provides an interface for configuration databases. A concrete class is required that implements the interface.
Definition at line 136 of file Configuration.h.
Enumeration for the various types of values we can store.
Definition at line 140 of file Configuration.h.
{ STRING, INTEGER, BINARY, INVALID };
ACE_Configuration::~ACE_Configuration | ( | void | ) | [virtual] |
ACE_Configuration::ACE_Configuration | ( | void | ) | [protected] |
ACE_Configuration::ACE_Configuration | ( | const ACE_Configuration & | rhs | ) | [protected] |
virtual int ACE_Configuration::enumerate_sections | ( | const ACE_Configuration_Section_Key & | key, | |
int | index, | |||
ACE_TString & | name | |||
) | [pure virtual] |
Enumerates through the subsections in a section.
key | Section key to iterate through. | |
index | Iteration position. Must be zero on the first call to iterate through key. Increment index by one on each successive call to this method. | |
name | Receives the subsection's name. |
0 | for success, name has a valid name. | |
1 | there are no more subsections in the section. | |
-1 | for error; ACE_OS::last_error() retrieves error code. |
Implemented in ACE_Configuration_Heap.
virtual int ACE_Configuration::enumerate_values | ( | const ACE_Configuration_Section_Key & | key, | |
int | index, | |||
ACE_TString & | name, | |||
VALUETYPE & | type | |||
) | [pure virtual] |
Enumerates through the values in a section.
key | Section key to iterate through. | |
index | Iteration position. Must be zero on the first call to iterate through key. Increment index by one on each successive call to this method. | |
name | Receives the value's name. | |
type | Receives the value's data type. |
0 | for success, name and type are valid. | |
1 | there are no more values in the section. | |
-1 | for error; ACE_OS::last_error() retrieves error code. |
Implemented in ACE_Configuration_Heap.
int ACE_Configuration::expand_path | ( | const ACE_Configuration_Section_Key & | key, | |
const ACE_TString & | path_in, | |||
ACE_Configuration_Section_Key & | key_out, | |||
int | create = 1 | |||
) |
Expands path_in to key_out from key. If create is true, the subsections are created. Returns 0 on success, non zero on error The path consists of sections separated by the backslash '\' or forward slash '/'. Returns 0 on success, -1 if <create) is 0 and the path refers a nonexistant section
Definition at line 108 of file Configuration.cpp.
{ // Make a copy of key ACE_Configuration_Section_Key current_section = key; ACE_Auto_Basic_Array_Ptr<ACE_TCHAR> pData (path_in.rep ()); ACE_Tokenizer parser (pData.get ()); parser.delimiter_replace ('\\', '\0'); parser.delimiter_replace ('/', '\0'); for (ACE_TCHAR *temp = parser.next (); temp != 0; temp = parser.next ()) { // Open the section if (open_section (current_section, temp, create, key_out)) return -1; current_section = key_out; } return 0; }
int ACE_Configuration::export_config | ( | const ACE_TCHAR * | filename | ) |
Definition at line 141 of file Configuration.cpp.
{ ACE_Registry_ImpExp exporter (*this); return exporter.export_config (filename); }
virtual int ACE_Configuration::find_value | ( | const ACE_Configuration_Section_Key & | key, | |
const ACE_TCHAR * | name, | |||
VALUETYPE & | type | |||
) | [pure virtual] |
Retrieves the type of a named configuration value.
key | Configuration section to look up the name in. | |
name | Name of the configuration value to get the type of. | |
type | Receives the data type of the named value, if it exists. |
0 | for success. | |
-1 | for error; ACE_OS::last_error() retrieves error code. |
Implemented in ACE_Configuration_Heap.
virtual int ACE_Configuration::get_binary_value | ( | const ACE_Configuration_Section_Key & | key, | |
const ACE_TCHAR * | name, | |||
void *& | data, | |||
size_t & | length | |||
) | [pure virtual] |
Gets a binary-typed value.
key | Configuration section to get the value from. | |
name | Name of the configuration value to get. | |
data | Receives a pointer to memory holding the binary data for the value. This method allocates the memory pointed to using operator new[]. The caller is responsible for freeing the memory using operator delete[]. | |
length | Receives the number of bytes in the value. |
0 | for success; caller is responsible for freeing the returned memory. | |
-1 | for error; ACE_OS::last_error() retrieves error code. |
Implemented in ACE_Configuration_Heap.
virtual int ACE_Configuration::get_integer_value | ( | const ACE_Configuration_Section_Key & | key, | |
const ACE_TCHAR * | name, | |||
u_int & | value | |||
) | [pure virtual] |
Gets an integer-typed value.
key | Configuration section to get the value from. | |
name | Name of the configuration value to get. | |
value | Receives the configuration value if it exists and has type INTEGER. |
0 | for success. | |
-1 | for error; ACE_OS::last_error() retrieves error code. |
Implemented in ACE_Configuration_Heap.
ACE_Section_Key_Internal * ACE_Configuration::get_internal_key | ( | const ACE_Configuration_Section_Key & | key | ) | [protected] |
Resolves the internal key from a section key.
Definition at line 102 of file Configuration.cpp.
{ return key.key_; }
virtual int ACE_Configuration::get_string_value | ( | const ACE_Configuration_Section_Key & | key, | |
const ACE_TCHAR * | name, | |||
ACE_TString & | value | |||
) | [pure virtual] |
Gets a string-typed value.
key | Configuration section to get the value from. | |
name | Name of the configuration value to get. | |
value | Receives the configuration value if it exists and has type STRING. |
0 | for success. | |
-1 | for error; ACE_OS::last_error() retrieves error code. |
Implemented in ACE_Configuration_Heap.
int ACE_Configuration::import_config | ( | const ACE_TCHAR * | filename | ) |
Definition at line 148 of file Configuration.cpp.
{ ACE_Registry_ImpExp importer (*this); return importer.import_config (filename); }
virtual int ACE_Configuration::open_section | ( | const ACE_Configuration_Section_Key & | base, | |
const ACE_TCHAR * | sub_section, | |||
int | create, | |||
ACE_Configuration_Section_Key & | result | |||
) | [pure virtual] |
Opens a named section in an existing section.
base | Existing section in which to open the named section. | |
sub_section | Name of the section to open. | |
create | If zero, the named section must exist. If non-zero, the named section will be created if it does not exist. | |
result | Reference; receives the section key for the new section. |
0 | for success. | |
-1 | for error; ACE_OS::last_error() retrieves error code. |
Implemented in ACE_Configuration_Heap.
bool ACE_Configuration::operator!= | ( | const ACE_Configuration & | rhs | ) | const |
Determine if the contents of this object are different from the contents of the object on the right hand side. Returns false if they are equal and true if they are not equal
Definition at line 429 of file Configuration.cpp.
{ return !(*this == rhs); }
ACE_Configuration& ACE_Configuration::operator= | ( | const ACE_Configuration & | rhs | ) | [protected] |
bool ACE_Configuration::operator== | ( | const ACE_Configuration & | rhs | ) | const |
Determine if the contents of this object is the same as the contents of the object on the right hand side. Returns true if they are equal and false if they are not equal
Determine if the contents of this object is the same as the contents of the object on the right hand side. Returns 1 (True) if they are equal and 0 (False) if they are not equal
Definition at line 209 of file Configuration.cpp.
{ bool rc = true; int sectionIndex = 0; ACE_TString sectionName; ACE_Configuration *nonconst_this = const_cast<ACE_Configuration*> (this); ACE_Configuration &nonconst_rhs = const_cast<ACE_Configuration&> (rhs); const ACE_Configuration_Section_Key& rhsRoot = rhs.root_section (); ACE_Configuration_Section_Key rhsSection; ACE_Configuration_Section_Key thisSection; // loop through each section in this object while ((rc) && (nonconst_this->enumerate_sections (this->root_, sectionIndex, sectionName) == 0)) { // find that section in the rhs object if (nonconst_rhs.open_section (rhsRoot, sectionName.c_str (), 0, rhsSection) != 0) { // If the rhs object does not contain the section then we are // not equal. rc = false; } else if (nonconst_this->open_section (this->root_, sectionName.c_str (), 0, thisSection) != 0) { // if there is some error opening the section in this object rc = false; } else { // Well the sections match int valueIndex = 0; ACE_TString valueName; VALUETYPE valueType; VALUETYPE rhsType; // Enumerate each value in this section while ((rc) && nonconst_this->enumerate_values (thisSection, valueIndex, valueName, valueType) == 0) { // look for the same value in the rhs section if (nonconst_rhs.find_value (rhsSection, valueName.c_str (), rhsType) != 0) { // We're not equal if the same value cannot // be found in the rhs object. rc = false; } else if (valueType != rhsType) { // we're not equal if the types do not match. rc = false; } else { // finally compare values. if (valueType == STRING) { ACE_TString thisString, rhsString; if (nonconst_this->get_string_value (thisSection, valueName.c_str (), thisString) != 0) { // we're not equal if we cannot get this string rc = false; } else if (nonconst_rhs.get_string_value ( rhsSection, valueName.c_str (), rhsString) != 0) { // we're not equal if we cannot get rhs string rc = false; } rc = (thisString == rhsString); } else if (valueType == INTEGER) { u_int thisInt = 0; u_int rhsInt = 0; if (nonconst_this->get_integer_value ( thisSection, valueName.c_str (), thisInt) != 0) { // we're not equal if we cannot get this int rc = false; } else if (nonconst_rhs.get_integer_value ( rhsSection, valueName.c_str (), rhsInt) != 0) { // we're not equal if we cannot get rhs int rc = false; } rc = (thisInt == rhsInt); } else if (valueType == BINARY) { void* thisData = 0; void* rhsData = 0; size_t thisLength = 0; size_t rhsLength = 0; if (nonconst_this->get_binary_value (thisSection, valueName.c_str (), thisData, thisLength) != 0) { // we're not equal if we cannot get this data rc = false; } else if (nonconst_rhs.get_binary_value ( rhsSection, valueName.c_str (), rhsData, rhsLength) != 0) { // we're not equal if we cannot get this data rc = false; } rc = (thisLength == rhsLength); // are the length's the same? if (rc) { unsigned char* thisCharData = (unsigned char*)thisData; unsigned char* rhsCharData = (unsigned char*)rhsData; // yes, then check each element for (size_t count = 0; (rc) && (count < thisLength); count++) { rc = (* (thisCharData + count) == * (rhsCharData + count)); } delete [] thisCharData; delete [] rhsCharData; }// end if the length's match } // We should never have valueTypes of INVALID, therefore // we're not comparing them. How would we since we have // no get operation for invalid types. // So, if we have them, we guess they are equal. }// end else if values match. ++valueIndex; }// end value while loop // look in the rhs for values not in this valueIndex = 0; while ((rc) && (nonconst_rhs.enumerate_values (rhsSection, valueIndex, valueName, rhsType) == 0)) { // look for the same value in this section if (nonconst_this->find_value (thisSection, valueName.c_str (), valueType) != 0) { // We're not equal if the same value cannot // be found in the rhs object. rc = false; } ++valueIndex; }// end while for rhs values not in this. }// end else if sections match. ++sectionIndex; }// end section while loop // Finally, make sure that there are no sections in rhs that do not // exist in this sectionIndex = 0; while ((rc) && (nonconst_rhs.enumerate_sections (rhsRoot, sectionIndex, sectionName) == 0)) { // find the section in this if (nonconst_this->open_section (this->root_, sectionName.c_str (), 0, thisSection) != 0) { // if there is some error opening the section in this object rc = false; } else if (nonconst_rhs.open_section (rhsRoot, sectionName.c_str (), 0, rhsSection) != 0) { // If the rhs object does not contain the section then we // are not equal. rc = false; } ++sectionIndex; } return rc; }
virtual int ACE_Configuration::remove_section | ( | const ACE_Configuration_Section_Key & | key, | |
const ACE_TCHAR * | sub_section, | |||
bool | recursive | |||
) | [pure virtual] |
Removes a named section.
key | Section key to remove the named section from. | |
sub_section | Name of the section to remove. | |
recursive | If true, any subkeys below sub_section are removed as well. |
0 | for success. | |
-1 | for error; ACE_OS::last_error() retrieves error code. |
Implemented in ACE_Configuration_Heap.
virtual int ACE_Configuration::remove_value | ( | const ACE_Configuration_Section_Key & | key, | |
const ACE_TCHAR * | name | |||
) | [pure virtual] |
Removes a named value.
key | Configuration section to remove the named value from. | |
name | Name of the configuration value to remove. |
0 | for success. | |
-1 | for error; ACE_OS::last_error() retrieves error code. |
Implemented in ACE_Configuration_Heap.
const ACE_Configuration_Section_Key & ACE_Configuration::root_section | ( | void | ) | const [virtual] |
Obtain a reference to the root section of this configuration.
Definition at line 198 of file Configuration.cpp.
{ return root_; }
virtual int ACE_Configuration::set_binary_value | ( | const ACE_Configuration_Section_Key & | key, | |
const ACE_TCHAR * | name, | |||
const void * | data, | |||
size_t | length | |||
) | [pure virtual] |
Sets a binary-typed value.
key | Configuration section to set the value in. | |
name | Name of the configuration value to set. If a value with the specified name exists, it is replaced. | |
data | Pointer to the binary data for the value. | |
length | Number of bytes for the new value. |
0 | for success. | |
-1 | for error; ACE_OS::last_error() retrieves error code. |
Implemented in ACE_Configuration_Heap.
virtual int ACE_Configuration::set_integer_value | ( | const ACE_Configuration_Section_Key & | key, | |
const ACE_TCHAR * | name, | |||
u_int | value | |||
) | [pure virtual] |
Sets a integer-typed value.
key | Configuration section to set the value in. | |
name | Name of the configuration value to set. If a value with the specified name exists, it is replaced. | |
value | The integer to set the configuration value to. |
0 | for success. | |
-1 | for error; ACE_OS::last_error() retrieves error code. |
Implemented in ACE_Configuration_Heap.
virtual int ACE_Configuration::set_string_value | ( | const ACE_Configuration_Section_Key & | key, | |
const ACE_TCHAR * | name, | |||
const ACE_TString & | value | |||
) | [pure virtual] |
Sets a string-typed value.
key | Configuration section to set the value in. | |
name | Name of the configuration value to set. If a value with the specified name exists, it is replaced. | |
value | The string to set the configuration value to. |
0 | for success. | |
-1 | for error; ACE_OS::last_error() retrieves error code. |
Implemented in ACE_Configuration_Heap.
int ACE_Configuration::validate_name | ( | const ACE_TCHAR * | name, | |
int | allow_path = 0 | |||
) | [protected] |
Tests to see if name is valid. name must be < 255 characters and not contain the path separator '\', brackets [] or = (maybe just restrict to alphanumeric?) returns non zero if name is not valid. The path separator is allowed, except for the first character, if allow_path is true.
Definition at line 155 of file Configuration.cpp.
{ // Invalid character set const ACE_TCHAR* reject = allow_path ? ACE_TEXT ("][") : ACE_TEXT ("\\]["); // Position of the first invalid character or terminating null. size_t const pos = ACE_OS::strcspn (name, reject); // Check if it is an invalid character. if (name[pos] != ACE_TEXT ('\0')) { errno = EINVAL; return -1; } // The first character can never be a path separator. if (name[0] == ACE_TEXT ('\\')) { errno = EINVAL; return -1; } // Validate length. if (pos == 0 || pos > 255) { errno = ENAMETOOLONG; return -1; } return 0; }
int ACE_Configuration::validate_value_name | ( | const ACE_TCHAR * | name | ) | [protected] |
Test to see if name is valid. The default value for a key can be unnamed, which means either name is == 0 or name == '` is valid. Otherwise, it calls validate_name() to test name for the same rules that apply to keys.
Definition at line 189 of file Configuration.cpp.
{ if (name == 0 || *name == this->NULL_String_) return 0; return this->validate_name (name); }
ACE_TCHAR ACE_Configuration::NULL_String_ = '\0' [static] |
* Represents the "NULL" string to simplify the internal logic.
Definition at line 395 of file Configuration.h.
Definition at line 427 of file Configuration.h.