Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes

ACE_Configuration Class Reference

Base class for configuration databases. More...

#include <Configuration.h>

Inheritance diagram for ACE_Configuration:
Inheritance graph
[legend]
Collaboration diagram for ACE_Configuration:
Collaboration graph
[legend]

List of all members.

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_Internalget_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_Configurationoperator= (const ACE_Configuration &rhs)

Protected Attributes

ACE_Configuration_Section_Key root_

Detailed Description

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.

See also:
ACE_Configuration_Heap
ACE_Configuration_Win32Registry

Definition at line 136 of file Configuration.h.


Member Enumeration Documentation

Enumeration for the various types of values we can store.

Enumerator:
STRING 
INTEGER 
BINARY 
INVALID 

Definition at line 140 of file Configuration.h.

  {
    STRING,
    INTEGER,
    BINARY,
    INVALID
  };


Constructor & Destructor Documentation

ACE_Configuration::~ACE_Configuration ( void   )  [virtual]

Destructor.

Definition at line 97 of file Configuration.cpp.

{
}

ACE_Configuration::ACE_Configuration ( void   )  [protected]

Default ctor.

Definition at line 92 of file Configuration.cpp.

  : root_ ()
{
}

ACE_Configuration::ACE_Configuration ( const ACE_Configuration rhs  )  [protected]

Member Function Documentation

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.

Parameters:
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.
Note:
You may not modify the key section while enumerating. If the section is modified during enumeration, results are undefined; you must restart the enumeration from index 0.
Return values:
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.

Parameters:
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.
Note:
You may not delete or add values while enumerating. If the section is modified during enumeration, results are undefined; you must restart the enumeration from index 0.
Return values:
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  ) 
Deprecated:
Exports the configuration database to filename. If filename is already present, it is overwritten. This function is deprecated and will be removed in a future version of ACE. Please use either ACE_Registry_ImpExp or ACE_Ini_ImpExp instead.

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.

Parameters:
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.
Return values:
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.

Parameters:
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.
Return values:
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.

Parameters:
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.
Return values:
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.

Parameters:
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.
Return values:
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  ) 
Deprecated:
Imports the configuration database from filename. Any existing data is not removed. This function is deprecated and will be removed in a future version of ACE. Please use ACE_Registry_ImpExp or ACE_Ini_ImpExp instead.

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.

Parameters:
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.
Return values:
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.

Parameters:
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.
Return values:
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.

Parameters:
key Configuration section to remove the named value from.
name Name of the configuration value to remove.
Return values:
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.

Parameters:
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.
Return values:
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.

Parameters:
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.
Return values:
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.

Parameters:
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.
Return values:
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);
}


Member Data Documentation

* 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.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines