#include <Configuration_Import_Export.h>
Inheritance diagram for ACE_Ini_ImpExp:


Public Methods | |
| ACE_Ini_ImpExp (ACE_Configuration &) | |
| virtual | ~ACE_Ini_ImpExp (void) |
| virtual int | import_config (const ACE_TCHAR *filename) |
| virtual int | export_config (const ACE_TCHAR *filename) |
Private Methods | |
| int | export_section (const ACE_Configuration_Section_Key §ion, const ACE_TString &path, FILE *out) |
| ACE_TCHAR * | squish (ACE_TCHAR *src) |
| ACE_Ini_ImpExp (const ACE_Ini_ImpExp &) | |
| ACE_Ini_ImpExp & | operator= (const ACE_Ini_ImpExp &) |
This method allows for lines in the .ini or .conf file like this:
TimeToLive = 100 Delay = FALSE Flags = FF34 Heading = "ACE - Adaptive Communication Environment"
(note leading whitespace (tabs) in examples below)
SeekIndex = 14 TraceLevel = 6 # Can comment lines like this Justification = left_justified
The caller can then retrieve the string with the regular <get_string_value> function and convert the string to the desired data type.
Definition at line 160 of file Configuration_Import_Export.h.
|
|
Construction Definition at line 337 of file Configuration_Import_Export.cpp.
00338 : ACE_Config_ImpExp_Base (config) 00339 { 00340 } |
|
|
Destructor Definition at line 342 of file Configuration_Import_Export.cpp.
00343 {
00344 }
|
|
|
|
|
|
This method exports the entire configuration database to filename. Once the file is opened this method calls export_section() passing the root section. Implements ACE_Config_ImpExp_Base. Definition at line 447 of file Configuration_Import_Export.cpp. References ACE_LIB_TEXT, ACE_TCHAR, ACE_Config_ImpExp_Base::config_, export_section, ACE_OS::fclose, ACE_OS::fopen, and ACE_Configuration::root_section.
00448 {
00449 if (0 == filename)
00450 {
00451 errno = EINVAL;
00452 return -1;
00453 }
00454 int result = -1;
00455
00456 FILE* out = ACE_OS::fopen (filename, ACE_LIB_TEXT ("w"));
00457 if (out)
00458 {
00459 result = this->export_section (config_.root_section (),
00460 ACE_LIB_TEXT (""),
00461 out);
00462 ACE_OS::fclose (out);
00463 }
00464 return result;
00465 }
|
|
||||||||||||||||
|
Method provided by derived classes in order to write one section to the file specified. Called by export_config() when exporting the entire configuration object. Definition at line 472 of file Configuration_Import_Export.cpp. References ACE_LIB_TEXT, ACE_TCHAR, ACE_Configuration::BINARY, ACE_Config_ImpExp_Base::config_, ACE_Configuration::enumerate_sections, ACE_Configuration::enumerate_values, ACE_String_Base< char >::fast_rep, ACE_OS::fputs, ACE_Configuration::get_binary_value, ACE_Configuration::get_integer_value, ACE_Configuration::get_string_value, ACE_Configuration::INTEGER, ACE_Configuration::INVALID, ACE_String_Base< char >::length, ACE_Configuration::open_section, ACE_OS::sprintf, ACE_Configuration::STRING, and ACE_Configuration::VALUETYPE. Referenced by export_config.
00475 {
00476 // don't export the root
00477 if (path.length ())
00478 {
00479 // Write out the section header
00480 ACE_TString header = ACE_LIB_TEXT ("[");
00481 header += path;
00482 header += ACE_LIB_TEXT ("]\n");
00483 if (ACE_OS::fputs (header.fast_rep (), out) < 0)
00484 return -1;
00485 // Write out each value
00486 int index = 0;
00487 ACE_TString name;
00488 ACE_Configuration::VALUETYPE type;
00489 ACE_TString line;
00490 ACE_TCHAR int_value[32];
00491 ACE_TCHAR bin_value[3];
00492 void* binary_data;
00493 size_t binary_length;
00494 ACE_TString string_value;
00495 while (!config_.enumerate_values (section, index, name, type))
00496 {
00497 line = name + ACE_LIB_TEXT ("=");
00498 switch (type)
00499 {
00500 case ACE_Configuration::INTEGER:
00501 {
00502 u_int value;
00503 if (config_.get_integer_value (section, name.fast_rep (), value))
00504 return -2;
00505 ACE_OS::sprintf (int_value, ACE_LIB_TEXT ("%08x"), value);
00506 line += int_value;
00507 break;
00508 }
00509 case ACE_Configuration::STRING:
00510 {
00511 if (config_.get_string_value (section,
00512 name.fast_rep (),
00513 string_value))
00514 return -2;
00515 line += string_value;
00516 break;
00517 }
00518 #ifdef _WIN32
00519 case ACE_Configuration::INVALID:
00520 break; // JDO added break. Otherwise INVALID is processed
00521 // like BINARY. If that's correct, please remove the
00522 // break and these comments
00523 #endif
00524 case ACE_Configuration::BINARY:
00525 {
00526 // not supported yet - maybe use BASE64 codeing?
00527 if (config_.get_binary_value (section,
00528 name.fast_rep (),
00529 binary_data,
00530 binary_length))
00531 return -2;
00532 line += ACE_LIB_TEXT ("\"");
00533 unsigned char* ptr = (unsigned char*)binary_data;
00534 while (binary_length)
00535 {
00536 if (ptr != binary_data)
00537 {
00538 line += ACE_LIB_TEXT (",");
00539 }
00540 ACE_OS::sprintf (bin_value, ACE_LIB_TEXT ("%02x"), *ptr);
00541 line += bin_value;
00542 --binary_length;
00543 ++ptr;
00544 }
00545 line += ACE_LIB_TEXT ("\"");
00546 delete [] (char *) binary_data;
00547 break;
00548 }
00549 default:
00550 return -3;
00551
00552 }// end switch on type
00553
00554 line += ACE_LIB_TEXT ("\n");
00555 if (ACE_OS::fputs (line.fast_rep (), out) < 0)
00556 return -4;
00557 index++;
00558 }// end while enumerating values
00559 }
00560 // Export all sub sections
00561 int index = 0;
00562 ACE_TString name;
00563 ACE_Configuration_Section_Key sub_key;
00564 ACE_TString sub_section;
00565 while (!config_.enumerate_sections (section, index, name))
00566 {
00567 ACE_TString sub_section (path);
00568 if (path.length ())
00569 sub_section += ACE_LIB_TEXT ("\\");
00570 sub_section += name;
00571 if (config_.open_section (section, name.fast_rep (), 0, sub_key))
00572 return -5;
00573 if (export_section (sub_key, sub_section.fast_rep (), out))
00574 return -6;
00575 index++;
00576 }
00577 return 0;
00578
00579 }
|
|
|
Imports the configuration database from filename. No existing data is removed. Implements ACE_Config_ImpExp_Base. Definition at line 348 of file Configuration_Import_Export.cpp. References ACE_LIB_TEXT, ACE_TCHAR, ACE_Config_ImpExp_Base::config_, ACE_Configuration::expand_path, ACE_OS::fclose, ACE_OS::fgets, ACE_OS::fopen, ACE_Configuration::root_section, ACE_Configuration::set_string_value, squish, ACE_OS_String::strchr, ACE_OS_String::strlen, and ACE_OS_String::strrchr.
00349 {
00350 if (0 == filename)
00351 {
00352 errno = EINVAL;
00353 return -1;
00354 }
00355 FILE* in = ACE_OS::fopen (filename, ACE_LIB_TEXT ("r"));
00356 if (!in)
00357 return -1;
00358
00359 // @@ Make this a dynamic size!
00360 ACE_TCHAR buffer[4096];
00361 ACE_Configuration_Section_Key section;
00362 while (ACE_OS::fgets (buffer, sizeof buffer, in))
00363 {
00364 ACE_TCHAR *line = this->squish (buffer);
00365 // Check for a comment and blank line
00366 if (line[0] == ACE_LIB_TEXT (';') ||
00367 line[0] == ACE_LIB_TEXT ('#') ||
00368 line[0] == '\0')
00369 continue;
00370
00371 if (line[0] == ACE_LIB_TEXT ('['))
00372 {
00373 // We have a new section here, strip out the section name
00374 ACE_TCHAR* end = ACE_OS::strrchr (line, ACE_LIB_TEXT (']'));
00375 if (!end)
00376 {
00377 ACE_OS::fclose (in);
00378 return -3;
00379 }
00380 *end = 0;
00381
00382 if (config_.expand_path (config_.root_section (),
00383 line + 1,
00384 section,
00385 1))
00386 {
00387 ACE_OS::fclose (in);
00388 return -3;
00389 }
00390
00391 continue;
00392 }
00393
00394 // We have a line; name ends at equal sign.
00395 ACE_TCHAR *end = ACE_OS::strchr (line, ACE_LIB_TEXT ('='));
00396 if (end == 0) // No '='
00397 {
00398 ACE_OS::fclose (in);
00399 return -3;
00400 }
00401 *end++ = '\0';
00402 ACE_TCHAR *name = this->squish (line);
00403 if (ACE_OS::strlen (name) == 0) // No name; just an '='
00404 {
00405 ACE_OS::fclose (in);
00406 return -3;
00407 }
00408
00409 // Now find the start of the value
00410 ACE_TCHAR *value = this->squish (end);
00411 size_t value_len = ACE_OS::strlen (value);
00412 if (value_len > 0)
00413 {
00414 // ACE 5.2 (and maybe earlier) exported strings may be enclosed
00415 // in quotes. If string is quote-delimited, strip the quotes.
00416 // Newer exported files don't have quote delimiters.
00417 if (value[0] == ACE_LIB_TEXT ('"') &&
00418 value[value_len - 1] == ACE_LIB_TEXT ('"'))
00419 {
00420 // Strip quotes off both ends.
00421 value[value_len - 1] = '\0';
00422 value++;
00423 }
00424 }
00425
00426 if (config_.set_string_value (section, name, value))
00427 {
00428 ACE_OS::fclose (in);
00429 return -4;
00430 }
00431 } // end while fgets
00432
00433 if (ferror (in))
00434 {
00435 ACE_OS::fclose (in);
00436 return -1;
00437 }
00438
00439 ACE_OS::fclose (in);
00440 return 0;
00441 }
|
|
|
|
|
|
Method to squish leading and trailing whitespaces in a string. Whitespace is defined as: spaces (' '), tabs ('\t') or cr/lf. Returns a pointer to the first non-whitespace character in the buffer provided, or a pointer to the terminating null if the string is all whitespace. The terminating null is moved forward to the first character past the last non-whitespace. Definition at line 589 of file Configuration_Import_Export.cpp. References ACE_OS_String::ace_isspace, ACE_TCHAR, and ACE_OS_String::strlen. Referenced by import_config.
00590 {
00591 ACE_TCHAR *cp;
00592
00593 if (src == 0)
00594 return 0;
00595
00596 // Start at the end and work backwards over all whitespace.
00597 for (cp = src + ACE_OS_String::strlen (src) - 1;
00598 cp != src;
00599 --cp)
00600 if (!ACE_OS_String::ace_isspace (*cp))
00601 break;
00602 cp[1] = '\0'; // Chop trailing whitespace
00603
00604 // Now start at the beginning and move over all whitespace.
00605 for (cp = src; ACE_OS_String::ace_isspace (*cp); ++cp)
00606 continue;
00607
00608 return cp;
00609 }
|
1.2.14 written by Dimitri van Heesch,
© 1997-2002