#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 91 of file Configuration.cpp.
00092 { 00093 } |
|
Default ctor.
Definition at line 86 of file Configuration.cpp.
00087 : root_ () 00088 { 00089 } |
|
|
|
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 . 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 102 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().
00106 { 00107 // Make a copy of key 00108 ACE_Configuration_Section_Key current_section = key; 00109 ACE_Auto_Basic_Array_Ptr<ACE_TCHAR> pData (path_in.rep ()); 00110 ACE_Tokenizer parser (pData.get ()); 00111 parser.delimiter_replace ('\\', '\0'); 00112 parser.delimiter_replace ('/', '\0'); 00113 00114 for (ACE_TCHAR *temp = parser.next (); 00115 temp != 0; 00116 temp = parser.next ()) 00117 { 00118 // Open the section 00119 if (open_section (current_section, 00120 temp, 00121 create, 00122 key_out)) 00123 return -1; 00124 00125 current_section = key_out; 00126 } 00127 00128 return 0; 00129 00130 } |
|
Definition at line 135 of file Configuration.cpp. References ACE_TCHAR, and ACE_Registry_ImpExp::export_config().
00136 { 00137 ACE_Registry_ImpExp exporter (*this); 00138 return exporter.export_config (filename); 00139 } |
|
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 96 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().
00097 { 00098 return key.key_; 00099 } |
|
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 142 of file Configuration.cpp. References ACE_TCHAR, and ACE_Registry_ImpExp::import_config().
00143 { 00144 ACE_Registry_ImpExp importer (*this); 00145 return importer.import_config (filename); 00146 } |
|
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 423 of file Configuration.cpp.
00424 { 00425 return !(*this == rhs); 00426 } |
|
|
|
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 203 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.
00204 { 00205 bool rc = true; 00206 int sectionIndex = 0; 00207 ACE_TString sectionName; 00208 ACE_Configuration *nonconst_this = const_cast<ACE_Configuration*> (this); 00209 ACE_Configuration &nonconst_rhs = const_cast<ACE_Configuration&> (rhs); 00210 00211 const ACE_Configuration_Section_Key& rhsRoot = rhs.root_section (); 00212 ACE_Configuration_Section_Key rhsSection; 00213 ACE_Configuration_Section_Key thisSection; 00214 00215 // loop through each section in this object 00216 while ((rc) && (nonconst_this->enumerate_sections (this->root_, 00217 sectionIndex, 00218 sectionName) == 0)) 00219 { 00220 // find that section in the rhs object 00221 if (nonconst_rhs.open_section (rhsRoot, 00222 sectionName.c_str (), 00223 0, 00224 rhsSection) != 0) 00225 { 00226 // If the rhs object does not contain the section then we are 00227 // not equal. 00228 rc = false; 00229 } 00230 else if (nonconst_this->open_section (this->root_, 00231 sectionName.c_str (), 00232 0, 00233 thisSection) != 0) 00234 { 00235 // if there is some error opening the section in this object 00236 rc = false; 00237 } 00238 else 00239 { 00240 // Well the sections match 00241 int valueIndex = 0; 00242 ACE_TString valueName; 00243 VALUETYPE valueType; 00244 VALUETYPE rhsType; 00245 00246 // Enumerate each value in this section 00247 while ((rc) && nonconst_this->enumerate_values (thisSection, 00248 valueIndex, 00249 valueName, 00250 valueType) == 0) 00251 { 00252 // look for the same value in the rhs section 00253 if (nonconst_rhs.find_value (rhsSection, 00254 valueName.c_str (), 00255 rhsType) != 0) 00256 { 00257 // We're not equal if the same value cannot 00258 // be found in the rhs object. 00259 rc = false; 00260 } 00261 else if (valueType != rhsType) 00262 { 00263 // we're not equal if the types do not match. 00264 rc = false; 00265 } 00266 else 00267 { 00268 // finally compare values. 00269 if (valueType == STRING) 00270 { 00271 ACE_TString thisString, rhsString; 00272 if (nonconst_this->get_string_value (thisSection, 00273 valueName.c_str (), 00274 thisString) != 0) 00275 { 00276 // we're not equal if we cannot get this string 00277 rc = false; 00278 } 00279 else if (nonconst_rhs.get_string_value ( 00280 rhsSection, 00281 valueName.c_str (), 00282 rhsString) != 0) 00283 { 00284 // we're not equal if we cannot get rhs string 00285 rc = false; 00286 } 00287 rc = (thisString == rhsString); 00288 } 00289 else if (valueType == INTEGER) 00290 { 00291 u_int thisInt = 0; 00292 u_int rhsInt = 0; 00293 if (nonconst_this->get_integer_value ( 00294 thisSection, 00295 valueName.c_str (), 00296 thisInt) != 0) 00297 { 00298 // we're not equal if we cannot get this int 00299 rc = false; 00300 } 00301 else if (nonconst_rhs.get_integer_value ( 00302 rhsSection, 00303 valueName.c_str (), 00304 rhsInt) != 0) 00305 { 00306 // we're not equal if we cannot get rhs int 00307 rc = false; 00308 } 00309 rc = (thisInt == rhsInt); 00310 } 00311 else if (valueType == BINARY) 00312 { 00313 void* thisData = 0; 00314 void* rhsData = 0; 00315 size_t thisLength = 0; 00316 size_t rhsLength = 0; 00317 if (nonconst_this->get_binary_value (thisSection, 00318 valueName.c_str (), 00319 thisData, 00320 thisLength) != 0) 00321 { 00322 // we're not equal if we cannot get this data 00323 rc = false; 00324 } 00325 else if (nonconst_rhs.get_binary_value ( 00326 rhsSection, 00327 valueName.c_str (), 00328 rhsData, 00329 rhsLength) != 0) 00330 { 00331 // we're not equal if we cannot get this data 00332 rc = false; 00333 } 00334 00335 rc = (thisLength == rhsLength); 00336 // are the length's the same? 00337 00338 if (rc) 00339 { 00340 unsigned char* thisCharData = 00341 (unsigned char*)thisData; 00342 unsigned char* rhsCharData = (unsigned char*)rhsData; 00343 // yes, then check each element 00344 for (size_t count = 0; 00345 (rc) && (count < thisLength); 00346 count++) 00347 { 00348 rc = (* (thisCharData + count) == * (rhsCharData + count)); 00349 } 00350 00351 delete [] thisCharData; 00352 delete [] rhsCharData; 00353 }// end if the length's match 00354 } 00355 // We should never have valueTypes of INVALID, therefore 00356 // we're not comparing them. How would we since we have 00357 // no get operation for invalid types. 00358 // So, if we have them, we guess they are equal. 00359 00360 }// end else if values match. 00361 00362 ++valueIndex; 00363 00364 }// end value while loop 00365 00366 // look in the rhs for values not in this 00367 valueIndex = 0; 00368 while ((rc) && (nonconst_rhs.enumerate_values (rhsSection, 00369 valueIndex, 00370 valueName, 00371 rhsType) == 0)) 00372 { 00373 // look for the same value in this section 00374 if (nonconst_this->find_value (thisSection, 00375 valueName.c_str (), 00376 valueType) != 0) 00377 { 00378 // We're not equal if the same value cannot 00379 // be found in the rhs object. 00380 rc = false; 00381 } 00382 ++valueIndex; 00383 }// end while for rhs values not in this. 00384 00385 }// end else if sections match. 00386 00387 sectionIndex++; 00388 00389 }// end section while loop 00390 00391 // Finally, make sure that there are no sections in rhs that do not 00392 // exist in this 00393 sectionIndex = 0; 00394 while ((rc) 00395 && (nonconst_rhs.enumerate_sections (rhsRoot, 00396 sectionIndex, 00397 sectionName) == 0)) 00398 { 00399 // find the section in this 00400 if (nonconst_this->open_section (this->root_, 00401 sectionName.c_str (), 00402 0, 00403 thisSection) != 0) 00404 { 00405 // if there is some error opening the section in this object 00406 rc = false; 00407 } 00408 else if (nonconst_rhs.open_section (rhsRoot, 00409 sectionName.c_str (), 00410 0, 00411 rhsSection) != 0) 00412 { 00413 // If the rhs object does not contain the section then we 00414 // are not equal. 00415 rc = false; 00416 } 00417 ++sectionIndex; 00418 } 00419 return rc; 00420 } |
|
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 192 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==().
00193 { 00194 return root_; 00195 } |
|
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 is valid. 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 149 of file Configuration.cpp. References ACE_LIB_TEXT, ACE_TCHAR, and ACE_OS::strcspn(). Referenced by ACE_Configuration_Heap::open_section(), ACE_Configuration_Heap::remove_section(), and validate_value_name().
00150 { 00151 // Invalid character set 00152 const ACE_TCHAR* reject = 00153 allow_path ? ACE_LIB_TEXT ("][") : ACE_LIB_TEXT ("\\]["); 00154 00155 // Position of the first invalid character or terminating null. 00156 size_t pos = ACE_OS::strcspn (name, reject); 00157 00158 // Check if it is an invalid character. 00159 if (name[pos] != ACE_LIB_TEXT ('\0')) 00160 { 00161 errno = EINVAL; 00162 return -1; 00163 } 00164 00165 // The first character can never be a path separator. 00166 if (name[0] == ACE_LIB_TEXT ('\\')) 00167 { 00168 errno = EINVAL; 00169 return -1; 00170 } 00171 00172 // Validate length. 00173 if (pos == 0 || pos > 255) 00174 { 00175 errno = ENAMETOOLONG; 00176 return -1; 00177 } 00178 00179 return 0; 00180 } |
|
Test to see if is valid. The default value for a key can be unnamed, which means either is == 0 or == '` is valid. Otherwise, it calls validate_name() to test for the same rules that apply to keys. Definition at line 183 of file Configuration.cpp. References ACE_TCHAR, NULL_String_, and validate_name(). 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::remove_value(), ACE_Configuration_Heap::set_binary_value(), ACE_Configuration_Heap::set_integer_value(), and ACE_Configuration_Heap::set_string_value().
00184 { 00185 if (name == 0 || *name == this->NULL_String_) 00186 return 0; 00187 00188 return this->validate_name (name); 00189 } |
|
* Represents the "NULL" string to simplify the internal logic. Definition at line 84 of file Configuration.cpp. Referenced by validate_value_name(). |
|
Definition at line 429 of file Configuration.h. Referenced by root_section(). |