#include <Configuration.h>
Inheritance diagram for ACE_Configuration:


| 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, int 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 | |
| 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_ | 
For internal use only.
This class provides an interface for configuration databases. A concrete class is required that implements the interface.
Definition at line 138 of file Configuration.h.
| 
 | 
| Enumeration for the various types of values we can store. 
 Definition at line 142 of file Configuration.h. Referenced by operator==(). 
 | 
| 
 | 
| Destructor. 
 Definition at line 92 of file Configuration.cpp. 
 00093 {
00094 }
 | 
| 
 | 
| Default ctor. 
 Definition at line 87 of file Configuration.cpp. 
 00088 : root_ () 00089 { 00090 } | 
| 
 | 
| 
 | 
| 
 | ||||||||||||||||
| Enumerates through the subsections in a section. 
 
 
 
 Implemented in ACE_Configuration_Win32Registry, and ACE_Configuration_Heap. Referenced by ACE_Ini_ImpExp::export_section(), ACE_Registry_ImpExp::export_section(), and operator==(). | 
| 
 | ||||||||||||||||||||
| Enumerates through the values in a section. 
 
 
 
 Implemented in ACE_Configuration_Win32Registry, and ACE_Configuration_Heap. Referenced by ACE_Ini_ImpExp::export_section(), ACE_Registry_ImpExp::export_section(), and operator==(). | 
| 
 | ||||||||||||||||||||
| Expands to 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 103 of file Configuration.cpp. References ACE_TCHAR, ACE_TString, ACE_Tokenizer::delimiter_replace(), ACE_Auto_Basic_Array_Ptr< X >::get(), ACE_Tokenizer::next(), open_section(), and ACE_String_Base< CHAR >::rep(). Referenced by ACE_Ini_ImpExp::import_config(), and ACE_Registry_ImpExp::import_config(). 
 00107 {
00108   // Make a copy of key
00109   ACE_Configuration_Section_Key current_section = key;
00110   ACE_Auto_Basic_Array_Ptr<ACE_TCHAR> pData (path_in.rep ());
00111   ACE_Tokenizer parser (pData.get ());
00112   parser.delimiter_replace ('\\', '\0');
00113   parser.delimiter_replace ('/', '\0');
00114 
00115   for (ACE_TCHAR *temp = parser.next ();
00116        temp != 0;
00117        temp = parser.next ())
00118     {
00119       // Open the section
00120       if (open_section (current_section,
00121                         temp,
00122                         create,
00123                         key_out))
00124         return -1;
00125 
00126       current_section = key_out;
00127     }
00128 
00129   return 0;
00130 
00131 }
 | 
| 
 | 
| 
 
 Definition at line 136 of file Configuration.cpp. References ACE_TCHAR, and ACE_Registry_ImpExp::export_config(). 
 00137 {
00138   ACE_Registry_ImpExp exporter (*this);
00139   return exporter.export_config (filename);
00140 }
 | 
| 
 | ||||||||||||||||
| Retrieves the type of a named configuration value. 
 
 
 Implemented in ACE_Configuration_Win32Registry, and ACE_Configuration_Heap. Referenced by operator==(). | 
| 
 | ||||||||||||||||||||
| Gets a binary-typed value. 
 
 
 Implemented in ACE_Configuration_Win32Registry, and ACE_Configuration_Heap. Referenced by ACE_Ini_ImpExp::export_section(), ACE_Registry_ImpExp::export_section(), and operator==(). | 
| 
 | ||||||||||||||||
| Gets an integer-typed value. 
 
 
 Implemented in ACE_Configuration_Win32Registry, and ACE_Configuration_Heap. Referenced by ACE_Ini_ImpExp::export_section(), ACE_Registry_ImpExp::export_section(), and operator==(). | 
| 
 | 
| Resolves the internal key from a section key. 
 Definition at line 97 of file Configuration.cpp. References ACE_Configuration_Section_Key::key_. Referenced by ACE_Configuration_Heap::enumerate_sections(), ACE_Configuration_Heap::enumerate_values(), ACE_Configuration_Heap::load_key(), and ACE_Configuration_Win32Registry::load_key(). 
 00098 {
00099   return key.key_;
00100 }
 | 
| 
 | ||||||||||||||||
| Gets a string-typed value. 
 
 
 Implemented in ACE_Configuration_Win32Registry, and ACE_Configuration_Heap. Referenced by ACE_Ini_ImpExp::export_section(), ACE_Registry_ImpExp::export_section(), and operator==(). | 
| 
 | 
| 
 
 Definition at line 143 of file Configuration.cpp. References ACE_TCHAR, and ACE_Registry_ImpExp::import_config(). 
 00144 {
00145   ACE_Registry_ImpExp importer (*this);
00146   return importer.import_config (filename);
00147 }
 | 
| 
 | ||||||||||||||||||||
| Opens a named section in an existing section. 
 
 
 Implemented in ACE_Configuration_Win32Registry, and ACE_Configuration_Heap. Referenced by expand_path(), ACE_Ini_ImpExp::export_section(), ACE_Registry_ImpExp::export_section(), and operator==(). | 
| 
 | 
| Determine if the contents of this object are different from the contents of the object on the right hand side. Returns 0 (False) if they are equal and 1 (True) if they are not equal Definition at line 424 of file Configuration.cpp. 
 00425 {
00426   return !(*this == rhs);
00427 }
 | 
| 
 | 
| 
 | 
| 
 | 
| 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 204 of file Configuration.cpp. References ACE_TString, BINARY, ACE_String_Base< CHAR >::c_str(), enumerate_sections(), enumerate_values(), find_value(), get_binary_value(), get_integer_value(), get_string_value(), INTEGER, open_section(), root_section(), STRING, and VALUETYPE. 
 00205 {
00206   bool rc = true;
00207   int sectionIndex = 0;
00208   ACE_TString sectionName;
00209   ACE_Configuration *nonconst_this = const_cast<ACE_Configuration*> (this);
00210   ACE_Configuration &nonconst_rhs  = const_cast<ACE_Configuration&> (rhs);
00211 
00212   const ACE_Configuration_Section_Key& rhsRoot = rhs.root_section ();
00213   ACE_Configuration_Section_Key rhsSection;
00214   ACE_Configuration_Section_Key thisSection;
00215 
00216   // loop through each section in this object
00217   while ((rc) && (nonconst_this->enumerate_sections (this->root_,
00218                                                      sectionIndex,
00219                                                      sectionName) == 0))
00220     {
00221       // find that section in the rhs object
00222       if (nonconst_rhs.open_section (rhsRoot,
00223                                      sectionName.c_str (),
00224                                      0,
00225                                      rhsSection) != 0)
00226         {
00227           // If the rhs object does not contain the section then we are
00228           // not equal.
00229           rc = false;
00230         }
00231       else if (nonconst_this->open_section (this->root_,
00232                                             sectionName.c_str (),
00233                                             0,
00234                                             thisSection) != 0)
00235         {
00236           // if there is some error opening the section in this object
00237           rc = false;
00238         }
00239       else
00240         {
00241           // Well the sections match
00242           int         valueIndex = 0;
00243           ACE_TString valueName;
00244           VALUETYPE   valueType;
00245           VALUETYPE   rhsType;
00246 
00247           // Enumerate each value in this section
00248           while ((rc) && nonconst_this->enumerate_values (thisSection,
00249                                                           valueIndex,
00250                                                           valueName,
00251                                                           valueType) == 0)
00252             {
00253               // look for the same value in the rhs section
00254               if (nonconst_rhs.find_value (rhsSection,
00255                                            valueName.c_str (),
00256                                            rhsType) != 0)
00257                 {
00258                   // We're not equal if the same value cannot
00259                   // be found in the rhs object.
00260                   rc = false;
00261                 }
00262               else if (valueType != rhsType)
00263                 {
00264                   // we're not equal if the types do not match.
00265                   rc = false;
00266                 }
00267               else
00268                 {
00269                   // finally compare values.
00270                   if (valueType == STRING)
00271                     {
00272                       ACE_TString thisString, rhsString;
00273                       if (nonconst_this->get_string_value (thisSection,
00274                                                            valueName.c_str (),
00275                                                            thisString) != 0)
00276                         {
00277                           // we're not equal if we cannot get this string
00278                           rc = false;
00279                         }
00280                       else if (nonconst_rhs.get_string_value (
00281                                  rhsSection,
00282                                  valueName.c_str (),
00283                                  rhsString) != 0)
00284                         {
00285                           // we're not equal if we cannot get rhs string
00286                           rc = false;
00287                         }
00288                       rc = (thisString == rhsString);
00289                     }
00290                   else if (valueType == INTEGER)
00291                     {
00292                       u_int thisInt = 0;
00293                       u_int rhsInt = 0;
00294                       if (nonconst_this->get_integer_value (
00295                             thisSection,
00296                             valueName.c_str (),
00297                             thisInt) != 0)
00298                         {
00299                           // we're not equal if we cannot get this int
00300                           rc = false;
00301                         }
00302                       else if (nonconst_rhs.get_integer_value (
00303                                  rhsSection,
00304                                  valueName.c_str (),
00305                                  rhsInt) != 0)
00306                         {
00307                           // we're not equal if we cannot get rhs int
00308                           rc = false;
00309                         }
00310                       rc = (thisInt == rhsInt);
00311                     }
00312                   else if (valueType == BINARY)
00313                     {
00314                       void* thisData = 0;
00315                       void* rhsData = 0;
00316                       size_t thisLength = 0;
00317                       size_t rhsLength = 0;
00318                       if (nonconst_this->get_binary_value (thisSection,
00319                                                            valueName.c_str (),
00320                                                            thisData,
00321                                                            thisLength) != 0)
00322                         {
00323                           // we're not equal if we cannot get this data
00324                           rc = false;
00325                         }
00326                       else if (nonconst_rhs.get_binary_value (
00327                                  rhsSection,
00328                                  valueName.c_str (),
00329                                  rhsData,
00330                                  rhsLength) != 0)
00331                         {
00332                           // we're not equal if we cannot get this data
00333                           rc = false;
00334                         }
00335 
00336                       rc = (thisLength == rhsLength);
00337                       // are the length's the same?
00338 
00339                       if (rc)
00340                         {
00341                           unsigned char* thisCharData =
00342                             (unsigned char*)thisData;
00343                           unsigned char* rhsCharData = (unsigned char*)rhsData;
00344                           // yes, then check each element
00345                           for (size_t count = 0;
00346                                (rc) && (count < thisLength);
00347                                count++)
00348                             {
00349                               rc = (* (thisCharData + count) == * (rhsCharData + count));
00350                             }
00351 
00352                           delete [] thisCharData;
00353                           delete [] rhsCharData;
00354                         }// end if the length's match
00355                     }
00356                   // We should never have valueTypes of INVALID, therefore
00357                   // we're not comparing them.  How would we since we have
00358                   // no get operation for invalid types.
00359                   // So, if we have them, we guess they are equal.
00360 
00361                 }// end else if values match.
00362 
00363               ++valueIndex;
00364 
00365             }// end value while loop
00366 
00367           // look in the rhs for values not in this
00368           valueIndex = 0;
00369           while ((rc) && (nonconst_rhs.enumerate_values (rhsSection,
00370                                                          valueIndex,
00371                                                          valueName,
00372                                                          rhsType) == 0))
00373             {
00374               // look for the same value in this section
00375               if (nonconst_this->find_value (thisSection,
00376                                              valueName.c_str (),
00377                                              valueType) != 0)
00378                 {
00379                   // We're not equal if the same value cannot
00380                   // be found in the rhs object.
00381                   rc = false;
00382                 }
00383               ++valueIndex;
00384             }// end while for rhs values not in this.
00385 
00386         }// end else if sections match.
00387 
00388       ++sectionIndex;
00389 
00390     }// end section while loop
00391 
00392   // Finally, make sure that there are no sections in rhs that do not
00393   // exist in this
00394   sectionIndex = 0;
00395   while ((rc)
00396          && (nonconst_rhs.enumerate_sections (rhsRoot,
00397                                               sectionIndex,
00398                                               sectionName) == 0))
00399     {
00400       // find the section in this
00401       if (nonconst_this->open_section (this->root_,
00402                                        sectionName.c_str (),
00403                                        0,
00404                                        thisSection) != 0)
00405         {
00406           // if there is some error opening the section in this object
00407           rc = false;
00408         }
00409       else if (nonconst_rhs.open_section (rhsRoot,
00410                                           sectionName.c_str (),
00411                                           0,
00412                                           rhsSection) != 0)
00413         {
00414           // If the rhs object does not contain the section then we
00415           // are not equal.
00416           rc = false;
00417         }
00418       ++sectionIndex;
00419     }
00420   return rc;
00421 }
 | 
| 
 | ||||||||||||||||
| Removes a named section. 
 
 
 Implemented in ACE_Configuration_Win32Registry, and ACE_Configuration_Heap. | 
| 
 | ||||||||||||
| Removes a named value. 
 
 
 Implemented in ACE_Configuration_Win32Registry, and ACE_Configuration_Heap. | 
| 
 | 
| Obtain a reference to the root section of this configuration. 
 Definition at line 193 of file Configuration.cpp. References root_. Referenced by ACE_Ini_ImpExp::export_config(), ACE_Registry_ImpExp::export_config(), ACE_Ini_ImpExp::import_config(), ACE_Registry_ImpExp::import_config(), and operator==(). 
 00194 {
00195   return root_;
00196 }
 | 
| 
 | ||||||||||||||||||||
| Sets a binary-typed value. 
 
 
 Implemented in ACE_Configuration_Win32Registry, and ACE_Configuration_Heap. Referenced by ACE_Registry_ImpExp::import_config(). | 
| 
 | ||||||||||||||||
| Sets a integer-typed value. 
 
 
 Implemented in ACE_Configuration_Win32Registry, and ACE_Configuration_Heap. Referenced by ACE_Registry_ImpExp::import_config(), and ACE_Registry_ImpExp::process_previous_line_format(). | 
| 
 | ||||||||||||||||
| Sets a string-typed value. 
 
 
 Implemented in ACE_Configuration_Win32Registry, and ACE_Configuration_Heap. Referenced by ACE_Ini_ImpExp::import_config(), ACE_Registry_ImpExp::import_config(), and ACE_Registry_ImpExp::process_previous_line_format(). | 
| 
 | ||||||||||||
| 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 is true. Definition at line 150 of file Configuration.cpp. References ACE_TCHAR, ACE_TEXT, and ACE_OS::strcspn(). Referenced by ACE_Configuration_Heap::open_section(), ACE_Configuration_Win32Registry::open_section(), ACE_Configuration_Heap::remove_section(), ACE_Configuration_Win32Registry::remove_section(), and validate_value_name(). 
 00151 {
00152   // Invalid character set
00153   const ACE_TCHAR* reject =
00154     allow_path ? ACE_TEXT ("][") : ACE_TEXT ("\\][");
00155 
00156   // Position of the first invalid character or terminating null.
00157   size_t pos = ACE_OS::strcspn (name, reject);
00158 
00159   // Check if it is an invalid character.
00160   if (name[pos] != ACE_TEXT ('\0'))
00161     {
00162       errno = EINVAL;
00163       return -1;
00164     }
00165 
00166   // The first character can never be a path separator.
00167   if (name[0] == ACE_TEXT ('\\'))
00168     {
00169       errno = EINVAL;
00170       return -1;
00171     }
00172 
00173   // Validate length.
00174   if (pos == 0 || pos > 255)
00175     {
00176       errno = ENAMETOOLONG;
00177       return -1;
00178     }
00179 
00180   return 0;
00181 }
 | 
| 
 | 
| 
 | 
| * Represents the "NULL" string to simplify the internal logic. Definition at line 85 of file Configuration.cpp. Referenced by validate_value_name(). | 
| 
 | 
| 
 Definition at line 429 of file Configuration.h. Referenced by root_section(). | 
 1.3.6
 
1.3.6