#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 Methods | |
| virtual | ~ACE_Configuration (void) |
| Destructor. More... | |
| virtual const ACE_Configuration_Section_Key & | root_section (void) const |
| Obtain a reference to the root section of this configuration. More... | |
| 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. More... | |
| 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. More... | |
| virtual int | set_integer_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, u_int value)=0 |
| Sets a integer-typed value. More... | |
| 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. More... | |
| virtual int | get_string_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, ACE_TString &value)=0 |
| Gets a string-typed value. More... | |
| virtual int | get_integer_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, u_int &value)=0 |
| Gets an integer-typed value. More... | |
| 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. More... | |
| 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. More... | |
| 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) |
| int | operator== (const ACE_Configuration &rhs) const |
| int | operator!= (const ACE_Configuration &rhs) const |
Protected Methods | |
| ACE_Configuration (void) | |
| Default ctor. More... | |
| ACE_Section_Key_Internal * | get_internal_key (const ACE_Configuration_Section_Key &key) |
| Resolves the internal key from a section key. More... | |
| int | validate_name (const ACE_TCHAR *name, int allow_path=0) |
| ACE_Configuration (const ACE_Configuration &rhs) | |
| ACE_Configuration & | operator= (const ACE_Configuration &rhs) |
Protected Attributes | |
| ACE_Configuration_Section_Key | root_ |
|
|
Enumeration for the various types of values we can store.
Definition at line 136 of file Configuration.h. Referenced by ACE_Ini_ImpExp::export_section, ACE_Registry_ImpExp::export_section, and operator==.
|
|
|
Destructor.
Definition at line 158 of file Configuration.cpp.
00159 {
00160 }
|
|
|
Default ctor.
Definition at line 153 of file Configuration.cpp.
00154 : root_ () 00155 { 00156 } |
|
|
|
|
||||||||||||||||
|
Enumerates through the subsections in a section.
Implemented in ACE_Configuration_Win32Registry. 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. Referenced by ACE_Ini_ImpExp::export_section, ACE_Registry_ImpExp::export_section, and operator==. |
|
||||||||||||||||||||
|
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 169 of file Configuration.cpp. References ACE_TCHAR, ACE_Tokenizer::delimiter_replace, ACE_Auto_Basic_Array_Ptr::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.
00173 {
00174 // Make a copy of key
00175 ACE_Configuration_Section_Key current_section = key;
00176 ACE_Auto_Basic_Array_Ptr<ACE_TCHAR> pData (path_in.rep ());
00177 ACE_Tokenizer parser (pData.get ());
00178 parser.delimiter_replace ('\\', '\0');
00179 parser.delimiter_replace ('/', '\0');
00180
00181 for (ACE_TCHAR *temp = parser.next ();
00182 temp != 0;
00183 temp = parser.next ())
00184 {
00185 // Open the section
00186 if (open_section (current_section,
00187 temp,
00188 create,
00189 key_out))
00190 return -1;
00191
00192 current_section = key_out;
00193 }
00194
00195 return 0;
00196
00197 }
|
|
|
Definition at line 202 of file Configuration.cpp. References ACE_TCHAR, and ACE_Registry_ImpExp::export_config.
00203 {
00204 ACE_Registry_ImpExp exporter (*this);
00205 return exporter.export_config (filename);
00206 }
|
|
||||||||||||||||
|
Retrieves the type of a named configuration value.
Implemented in ACE_Configuration_Win32Registry. Referenced by operator==. |
|
||||||||||||||||||||
|
Gets a binary-typed value.
Implemented in ACE_Configuration_Win32Registry. Referenced by ACE_Ini_ImpExp::export_section, ACE_Registry_ImpExp::export_section, and operator==. |
|
||||||||||||||||
|
Gets an integer-typed value.
Implemented in ACE_Configuration_Win32Registry. 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 163 of file Configuration.cpp. References ACE_Configuration_Section_Key::key_. Referenced by ACE_Configuration_Heap::enumerate_sections, ACE_Configuration_Heap::enumerate_values, and ACE_Configuration_Heap::load_key.
00164 {
00165 return key.key_;
00166 }
|
|
||||||||||||||||
|
Gets a string-typed value.
Implemented in ACE_Configuration_Win32Registry. Referenced by ACE_Ini_ImpExp::export_section, ACE_Registry_ImpExp::export_section, and operator==. |
|
|
Definition at line 209 of file Configuration.cpp. References ACE_TCHAR, and ACE_Registry_ImpExp::import_config.
00210 {
00211 ACE_Registry_ImpExp importer (*this);
00212 return importer.import_config (filename);
00213 }
|
|
||||||||||||||||||||
|
Opens a named section in an existing section.
Implemented in ACE_Configuration_Win32Registry. 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 386 of file Configuration.h.
00386 {return !(*this == rhs);}
|
|
|
|
|
|
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 261 of file Configuration.cpp. References 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.
00262 {
00263 int rc = 1;
00264 int sectionIndex = 0;
00265 ACE_TString sectionName;
00266 ACE_Configuration *nonconst_this = ACE_const_cast (ACE_Configuration*, this);
00267 ACE_Configuration &nonconst_rhs = ACE_const_cast (ACE_Configuration&, rhs);
00268
00269 const ACE_Configuration_Section_Key& rhsRoot = rhs.root_section ();
00270 ACE_Configuration_Section_Key rhsSection;
00271 ACE_Configuration_Section_Key thisSection;
00272
00273 // loop through each section in this object
00274 while ((rc) && (!nonconst_this->enumerate_sections (this->root_,
00275 sectionIndex,
00276 sectionName)))
00277 {
00278 // find that section in the rhs object
00279 if (nonconst_rhs.open_section (rhsRoot,
00280 sectionName.c_str (),
00281 0,
00282 rhsSection) != 0)
00283 {
00284 // If the rhs object does not contain the section then we are
00285 // not equal.
00286 rc = 0;
00287 }
00288 else if (nonconst_this->open_section (this->root_,
00289 sectionName.c_str (),
00290 0,
00291 thisSection) != 0)
00292 {
00293 // if there is some error opening the section in this object
00294 rc = 0;
00295 }
00296 else
00297 {
00298 // Well the sections match
00299 int valueIndex = 0;
00300 ACE_TString valueName;
00301 VALUETYPE valueType;
00302 VALUETYPE rhsType;
00303
00304 // Enumerate each value in this section
00305 while ((rc) && nonconst_this->enumerate_values (thisSection,
00306 valueIndex,
00307 valueName,
00308 valueType))
00309 {
00310 // look for the same value in the rhs section
00311 if (nonconst_rhs.find_value (rhsSection,
00312 valueName.c_str (),
00313 rhsType) != 0)
00314 {
00315 // We're not equal if the same value cannot
00316 // be found in the rhs object.
00317 rc = 0;
00318 }
00319 else if (valueType != rhsType)
00320 {
00321 // we're not equal if the types do not match.
00322 rc = 0;
00323 }
00324 else
00325 {
00326 // finally compare values.
00327 if (valueType == STRING)
00328 {
00329 ACE_TString thisString, rhsString;
00330 if (nonconst_this->get_string_value (thisSection,
00331 valueName.c_str (),
00332 thisString) != 0)
00333 {
00334 // we're not equal if we cannot get this string
00335 rc = 0;
00336 }
00337 else if (nonconst_rhs.get_string_value (rhsSection,
00338 valueName.c_str (),
00339 rhsString) != 0)
00340 {
00341 // we're not equal if we cannot get rhs string
00342 rc = 0;
00343 }
00344 rc = thisString == rhsString;
00345 }
00346 else if (valueType == INTEGER)
00347 {
00348 u_int thisInt, rhsInt;
00349 if (nonconst_this->get_integer_value (thisSection,
00350 valueName.c_str (),
00351 thisInt) != 0)
00352 {
00353 // we're not equal if we cannot get this int
00354 rc = 0;
00355 }
00356 else if (nonconst_rhs.get_integer_value (rhsSection,
00357 valueName.c_str (),
00358 rhsInt) != 0)
00359 {
00360 // we're not equal if we cannot get rhs int
00361 rc = 0;
00362 }
00363 rc = thisInt == rhsInt;
00364 }
00365 else if (valueType == BINARY)
00366 {
00367 void* thisData = 0;
00368 void* rhsData = 0;
00369 size_t thisLength, rhsLength;
00370 if (nonconst_this->get_binary_value (thisSection,
00371 valueName.c_str (),
00372 thisData,
00373 thisLength) != 0)
00374 {
00375 // we're not equal if we cannot get this data
00376 rc = 0;
00377 }
00378 else if (nonconst_rhs.get_binary_value (rhsSection,
00379 valueName.c_str (),
00380 rhsData,
00381 rhsLength) != 0)
00382 {
00383 // we're not equal if we cannot get this data
00384 rc = 0;
00385 }
00386
00387 rc = thisLength == rhsLength;
00388 // are the length's the same?
00389
00390 if (rc)
00391 {
00392 unsigned char* thisCharData = (unsigned char*)thisData;
00393 unsigned char* rhsCharData = (unsigned char*)rhsData;
00394 // yes, then check each element
00395 for (size_t count = 0;
00396 (rc) && (count < thisLength);
00397 count++)
00398 {
00399 rc = (* (thisCharData + count) == * (rhsCharData + count));
00400 }
00401
00402 delete [] thisCharData;
00403 delete [] rhsCharData;
00404 }// end if the length's match
00405
00406
00407 }
00408 // We should never have valueTypes of INVALID, therefore
00409 // we're not comparing them. How would we since we have
00410 // no get operation for invalid types.
00411 // So, if we have them, we guess they are equal.
00412
00413 }// end else if values match.
00414
00415 valueIndex++;
00416
00417 }// end value while loop
00418
00419 // look in the rhs for values not in this
00420 valueIndex = 0;
00421 while ((rc) &&
00422 (!nonconst_rhs.enumerate_values (rhsSection,
00423 valueIndex,
00424 valueName,
00425 rhsType)))
00426 {
00427 // look for the same value in this section
00428 if (nonconst_this->find_value (thisSection,
00429 valueName.c_str (),
00430 valueType) != 0)
00431 {
00432 // We're not equal if the same value cannot
00433 // be found in the rhs object.
00434 rc = 0;
00435 }
00436 valueIndex++;
00437 }// end while for rhs values not in this.
00438
00439 }// end else if sections match.
00440
00441 sectionIndex++;
00442
00443 }// end section while loop
00444
00445 // Finally, make sure that there are no sections in rhs that do not
00446 // exist in this
00447 sectionIndex = 0;
00448 while ((rc)
00449 && (!nonconst_rhs.enumerate_sections (rhsRoot,
00450 sectionIndex,
00451 sectionName)))
00452 {
00453 // find the section in this
00454 if (nonconst_this->open_section (this->root_,
00455 sectionName.c_str (),
00456 0,
00457 thisSection) != 0)
00458 {
00459 // if there is some error opening the section in this object
00460 rc = 0;
00461 }
00462 else if (nonconst_rhs.open_section (rhsRoot,
00463 sectionName.c_str (),
00464 0,
00465 rhsSection) != 0)
00466 {
00467 // If the rhs object does not contain the section then we
00468 // are not equal.
00469 rc = 0;
00470 }
00471 sectionIndex++;
00472 }
00473 return rc;
00474 }
|
|
||||||||||||||||
|
Removes a named section.
Implemented in ACE_Configuration_Win32Registry. |
|
||||||||||||
|
Removes a named value.
Implemented in ACE_Configuration_Win32Registry. |
|
|
Obtain a reference to the root section of this configuration.
Definition at line 251 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==.
00252 {
00253 return root_;
00254 }
|
|
||||||||||||||||||||
|
Sets a binary-typed value.
Implemented in ACE_Configuration_Win32Registry. Referenced by ACE_Registry_ImpExp::import_config. |
|
||||||||||||||||
|
Sets a integer-typed value.
Implemented in ACE_Configuration_Win32Registry. 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. 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 <allow_path> is true. Definition at line 216 of file Configuration.cpp. References ACE_LIB_TEXT, ACE_TCHAR, and ACE_OS_String::strcspn. Referenced by ACE_Configuration_Heap::find_value, ACE_Configuration_Heap::get_binary_value, ACE_Configuration_Heap::get_integer_value, ACE_Configuration_Heap::get_string_value, ACE_Configuration_Heap::open_section, ACE_Configuration_Heap::remove_section, ACE_Configuration_Heap::remove_value, ACE_Configuration_Heap::set_binary_value, ACE_Configuration_Heap::set_integer_value, and ACE_Configuration_Heap::set_string_value.
00217 {
00218 // Invalid character set
00219 const ACE_TCHAR* reject =
00220 allow_path ? ACE_LIB_TEXT ("][") : ACE_LIB_TEXT ("\\][");
00221
00222 // Position of the first invalid character or terminating null.
00223 size_t pos = ACE_OS_String::strcspn (name, reject);
00224
00225 // Check if it is an invalid character.
00226 if (name[pos] != ACE_LIB_TEXT ('\0'))
00227 {
00228 errno = EINVAL;
00229 return -1;
00230 }
00231
00232 // The first character can never be a path separator.
00233 if (name[0] == ACE_LIB_TEXT ('\\'))
00234 {
00235 errno = EINVAL;
00236 return -1;
00237 }
00238
00239 // Validate length.
00240 if (pos == 0 || pos > 255)
00241 {
00242 errno = ENAMETOOLONG;
00243 return -1;
00244 }
00245
00246 return 0;
00247 }
|
|
|
Definition at line 410 of file Configuration.h. Referenced by ACE_Configuration_Heap::ACE_Configuration_Heap, ACE_Configuration_Heap::create_index, and root_section. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002