Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_Configuration_Heap Class Reference

The concrete implementation of a allocator based configuration database. More...

#include <Configuration.h>

Inheritance diagram for ACE_Configuration_Heap:

Inheritance graph
[legend]
Collaboration diagram for ACE_Configuration_Heap:

Collaboration graph
[legend]
List of all members.

Public Methods

 ACE_Configuration_Heap (void)
 Default ctor. More...

virtual ~ACE_Configuration_Heap (void)
 Destructor. More...

int open (const ACE_TCHAR *file_name, void *base_address=ACE_DEFAULT_BASE_ADDR, int default_map_size=ACE_DEFAULT_CONFIG_SECTION_SIZE)
 Opens a configuration based on a file name. More...

int open (int default_map_size=ACE_DEFAULT_CONFIG_SECTION_SIZE)
 Opens a heap based configuration. More...

virtual int open_section (const ACE_Configuration_Section_Key &base, const ACE_TCHAR *sub_section, int create, ACE_Configuration_Section_Key &result)
virtual int remove_section (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *sub_section, int recursive)
 Removes a named section. More...

virtual int enumerate_values (const ACE_Configuration_Section_Key &key, int index, ACE_TString &name, VALUETYPE &type)
virtual int enumerate_sections (const ACE_Configuration_Section_Key &key, int index, ACE_TString &name)
virtual int set_string_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, const ACE_TString &value)
 Sets a string-typed value. More...

virtual int set_integer_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, u_int value)
 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)
 Sets a binary-typed value. More...

virtual int get_string_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, ACE_TString &value)
 Gets a string-typed value. More...

virtual int get_integer_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, u_int &value)
 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)
 Gets a binary-typed value. More...

virtual int find_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, VALUETYPE &type)
virtual int remove_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name)
 Removes the the value <name> from <key>. returns non zero on error. More...


Private Methods

int open_simple_section (const ACE_Configuration_Section_Key &base, const ACE_TCHAR *sub_section, int create, ACE_Configuration_Section_Key &result)
 <sub_section> may not contain path separators. More...

int add_section (const ACE_Configuration_Section_Key &base, const ACE_TCHAR *sub_section, ACE_Configuration_Section_Key &result)
 Adds a new section. More...

int create_index (void)
 Helper for the <open> method. More...

int create_index_helper (void *buffer)
 Helper for create_index() method: places hash table into an allocated space. More...

int value_open_helper (size_t hash_table_size, void *buffer)
int section_open_helper (size_t hash_table_size, void *buffer)
int load_key (const ACE_Configuration_Section_Key &key, ACE_TString &name)
int new_section (const ACE_TString &section, ACE_Configuration_Section_Key &result)
 ACE_Configuration_Heap (const ACE_Configuration_Heap &rhs)
ACE_Configuration_Heap & operator= (const ACE_Configuration_Heap &rhs)

Private Attributes

ACE_Allocatorallocator_
SECTION_MAPindex_
int default_map_size_

Detailed Description

The concrete implementation of a allocator based configuration database.

This class uses ACE's Allocators to manage a memory representation of a configuraiton database. A persistent heap may be used to store configurations persistently

Note: Before using this class you must call one of the open methods.

Todo:
-Need to investigate what happens if memory mapped file gets mapped to a location different than it was created with.

Definition at line 766 of file Configuration.h.


Constructor & Destructor Documentation

ACE_Configuration_Heap::ACE_Configuration_Heap void   
 

Default ctor.

Definition at line 1248 of file Configuration.cpp.

References ACE_LIB_TEXT, ACE_NEW, and ACE_Configuration::root_.

01249   : allocator_ (0),
01250     index_ (0),
01251     default_map_size_ (0)
01252 {
01253   ACE_Configuration_Section_Key_Heap *temp = 0;
01254 
01255   ACE_NEW (temp, ACE_Configuration_Section_Key_Heap (ACE_LIB_TEXT ("")));
01256   root_ = ACE_Configuration_Section_Key (temp);
01257 }

ACE_Configuration_Heap::~ACE_Configuration_Heap void    [virtual]
 

Destructor.

Definition at line 1259 of file Configuration.cpp.

References allocator_, and ACE_Allocator::sync.

01260 {
01261   if (allocator_)
01262     allocator_->sync ();
01263 
01264   delete allocator_;
01265 }

ACE_Configuration_Heap::ACE_Configuration_Heap const ACE_Configuration_Heap &    rhs [private]
 


Member Function Documentation

int ACE_Configuration_Heap::add_section const ACE_Configuration_Section_Key   base,
const ACE_TCHAR   sub_section,
ACE_Configuration_Section_Key   result
[private]
 

Adds a new section.

Definition at line 1383 of file Configuration.cpp.

References ACE_ASSERT, ACE_LIB_TEXT, ACE_TCHAR, allocator_, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, int >::bind, ACE_String_Base< char >::fast_rep, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, int >::find, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, ACE_Configuration_Section_IntId >::find, ACE_Allocator::free, index_, ACE_String_Base< char >::length, load_key, ACE_Allocator::malloc, new_section, ACE_Configuration_Section_IntId::section_hash_map_, ACE_OS_String::strcpy, and ACE_OS_String::strlen.

Referenced by open_simple_section.

01386 {
01387   ACE_ASSERT (this->allocator_);
01388   ACE_TString section;
01389   if (load_key (base, section))
01390     return -1;
01391 
01392   // Find the base section
01393   ACE_Configuration_ExtId ExtId (section.fast_rep ());
01394   ACE_Configuration_Section_IntId IntId;
01395   if (index_->find (ExtId, IntId, allocator_))
01396     return -1;
01397 
01398   // See if this section already exists
01399   ACE_Configuration_ExtId SubSectionExtId (sub_section);
01400   int ignored = 0;
01401 
01402   if (!IntId.section_hash_map_->find (SubSectionExtId, ignored, allocator_))
01403     {
01404       // already exists!
01405       errno = EEXIST;
01406       return -1;
01407     }
01408 
01409   // Create the new section name
01410   // only prepend a separater if were not at the root
01411   if (section.length ())
01412     section += ACE_LIB_TEXT ("\\");
01413 
01414   section += sub_section;
01415 
01416   // Add it to the base section
01417   ACE_TCHAR* pers_name = (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (sub_section) + 1) * sizeof (ACE_TCHAR));
01418   ACE_OS::strcpy (pers_name, sub_section);
01419   ACE_Configuration_ExtId SSExtId (pers_name);
01420   if (IntId.section_hash_map_->bind (SSExtId, ignored, allocator_))
01421     {
01422       allocator_->free (pers_name);
01423       return -1;
01424     }
01425   return (new_section (section, result));
01426 }

int ACE_Configuration_Heap::create_index void    [private]
 

Helper for the <open> method.

Definition at line 1325 of file Configuration.cpp.

References ACE_CONFIG_SECTION_INDEX, ACE_ERROR, ACE_LIB_TEXT, allocator_, ACE_Allocator::bind, create_index_helper, ACE_Allocator::find, index_, LM_ERROR, ACE_Allocator::malloc, new_section, ACE_Allocator::remove, and ACE_Configuration::root_.

Referenced by open.

01326 {
01327   void *section_index = 0;
01328 
01329   // This is the easy case since if we find hash table in the
01330   // memory-mapped file we know it's already initialized.
01331   if (this->allocator_->find (ACE_CONFIG_SECTION_INDEX, section_index) == 0)
01332     this->index_ = (SECTION_MAP *) section_index;
01333 
01334   // Create a new <index_> (because we've just created a new
01335   // memory-mapped file).
01336   else
01337     {
01338       size_t index_size = sizeof (SECTION_MAP);
01339       section_index = this->allocator_->malloc (index_size);
01340 
01341       if (section_index == 0
01342           || create_index_helper (section_index) == -1
01343           || this->allocator_->bind (ACE_CONFIG_SECTION_INDEX,
01344                                      section_index) == -1)
01345         {
01346           // Attempt to clean up.
01347           ACE_ERROR ((LM_ERROR,
01348                       ACE_LIB_TEXT ("create_index\n")));
01349           this->allocator_->remove ();
01350           return -1;
01351         }
01352       // Add the root section
01353       return new_section (ACE_LIB_TEXT (""), root_);
01354     }
01355   return 0;
01356 }

int ACE_Configuration_Heap::create_index_helper void *    buffer [private]
 

Helper for create_index() method: places hash table into an allocated space.

Definition at line 1359 of file Configuration.cpp.

References ACE_ASSERT, index_, and SECTION_MAP.

Referenced by create_index.

01360 {
01361   ACE_ASSERT (this->allocator_);
01362   this->index_ = new (buffer) SECTION_MAP (this->allocator_);
01363   return 0;
01364 }

int ACE_Configuration_Heap::enumerate_sections const ACE_Configuration_Section_Key   key,
int    index,
ACE_TString   name
[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.

Implements ACE_Configuration.

Definition at line 1750 of file Configuration.cpp.

References ACE_ASSERT, ACE_NEW_RETURN, allocator_, ACE_Hash_Map_Manager_Ex< ACE_Configuration_ExtId, int, ACE_Hash< ACE_Configuration_ExtId >, ACE_Equal_To< ACE_Configuration_ExtId >, ACE_Null_Mutex >::begin, ACE_Hash_Map_Entry::ext_id_, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, ACE_Configuration_Section_IntId >::find, ACE_Configuration::get_internal_key, index_, ACE_Configuration_Section_Key_Heap::path_, ACE_Configuration_Section_IntId::section_hash_map_, and ACE_Configuration_Section_Key_Heap::section_iter_.

Referenced by remove_section.

01753 {
01754   ACE_ASSERT (this->allocator_);
01755   // cast to a heap section key
01756   ACE_Configuration_Section_Key_Heap* pKey =
01757     ACE_dynamic_cast (ACE_Configuration_Section_Key_Heap*,
01758                       get_internal_key (key));
01759   if (!pKey)
01760     return -1;  // not a heap key!
01761 
01762   // resolve the section
01763   ACE_Configuration_ExtId ExtId (pKey->path_);
01764   ACE_Configuration_Section_IntId IntId;
01765   if (index_->find (ExtId, IntId, allocator_))
01766     return -1; // unknown section
01767 
01768   // Handle iterator resets
01769   if (index == 0)
01770     {
01771       if (pKey->section_iter_)
01772         delete pKey->section_iter_;
01773 
01774       ACE_NEW_RETURN (pKey->section_iter_,
01775                       SUBSECTION_HASH::ITERATOR (IntId.section_hash_map_->begin ()),
01776                       -1);
01777     }
01778 
01779   // Get the next entry
01780   ACE_Hash_Map_Entry<ACE_Configuration_ExtId, int>* entry;
01781   if (!pKey->section_iter_->next (entry))
01782     return 1;
01783 
01784   // Return the value of the iterator and advance it
01785   pKey->section_iter_->advance ();
01786   name = entry->ext_id_.name_;
01787 
01788   return 0;
01789 }

int ACE_Configuration_Heap::enumerate_values const ACE_Configuration_Section_Key   key,
int    index,
ACE_TString   name,
VALUETYPE   type
[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.

Implements ACE_Configuration.

Definition at line 1700 of file Configuration.cpp.

References ACE_ASSERT, ACE_NEW_RETURN, allocator_, ACE_Hash_Map_Entry::ext_id_, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, ACE_Configuration_Section_IntId >::find, ACE_Configuration::get_internal_key, index_, ACE_Hash_Map_Entry::int_id_, ACE_Configuration_Section_Key_Heap::path_, ACE_Configuration_Section_IntId::value_hash_map_, and ACE_Configuration_Section_Key_Heap::value_iter_.

01704 {
01705   ACE_ASSERT (this->allocator_);
01706   ACE_Configuration_Section_Key_Heap* pKey =
01707     ACE_dynamic_cast (ACE_Configuration_Section_Key_Heap*,
01708                       get_internal_key (key));
01709   if (!pKey)
01710     return -1;
01711 
01712   name = pKey->path_;
01713 
01714   // resolve the section
01715   ACE_Configuration_ExtId ExtId (pKey->path_);
01716   ACE_Configuration_Section_IntId IntId;
01717   if (index_->find (ExtId, IntId, allocator_))
01718     return -1;
01719 
01720   // Handle iterator resets
01721   if (index == 0)
01722     {
01723       ACE_Hash_Map_Manager_Ex<ACE_Configuration_ExtId ,
01724                               ACE_Configuration_Value_IntId,
01725                               ACE_Hash<ACE_Configuration_ExtId>,
01726                               ACE_Equal_To<ACE_Configuration_ExtId>,
01727                               ACE_Null_Mutex>* hash_map = IntId.value_hash_map_;
01728       delete pKey->value_iter_;
01729 
01730       ACE_NEW_RETURN (pKey->value_iter_,
01731                       VALUE_HASH::ITERATOR (hash_map->begin ()),
01732                       -1);
01733     }
01734 
01735   // Get the next entry
01736   ACE_Hash_Map_Entry<ACE_Configuration_ExtId, ACE_Configuration_Value_IntId>* entry;
01737 
01738   if (!pKey->value_iter_->next (entry))
01739     return 1;
01740 
01741   // Return the value of the iterator and advance it
01742   name = entry->ext_id_.name_;
01743   type = entry->int_id_.type_;
01744   pKey->value_iter_->advance ();
01745 
01746   return 0;
01747 }

int ACE_Configuration_Heap::find_value const ACE_Configuration_Section_Key   key,
const ACE_TCHAR   name,
VALUETYPE   type
[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.

Implements ACE_Configuration.

Definition at line 2110 of file Configuration.cpp.

References ACE_ASSERT, ACE_TCHAR, allocator_, ACE_String_Base< char >::fast_rep, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, ACE_Configuration_Section_IntId >::find, index_, ACE_Hash_Map_Entry< ACE_Configuration_ExtId, ACE_Configuration_Value_IntId >::int_id_, load_key, ACE_Configuration_Value_IntId::type_, ACE_Configuration::validate_name, and ACE_Configuration_Section_IntId::value_hash_map_.

02113 {
02114   ACE_ASSERT (this->allocator_);
02115   if (validate_name (name))
02116     return -1;
02117 
02118   // Get the section name from the key
02119   ACE_TString section;
02120   if (load_key (key, section))
02121     return -1;
02122 
02123   // Find this section
02124   ACE_Configuration_ExtId ExtId (section.fast_rep ());
02125   ACE_Configuration_Section_IntId IntId;
02126   if (index_->find (ExtId, IntId, allocator_))
02127     return -1;    // section does not exist
02128 
02129   // Find it
02130   ACE_Configuration_ExtId ValueExtId (name);
02131   VALUE_ENTRY* value_entry;
02132   if (((VALUE_HASH *) IntId.value_hash_map_)->find (ValueExtId, value_entry))
02133     return -1;  // value does not exist
02134 
02135   type_out = value_entry->int_id_.type_;
02136   return 0;
02137 }

int ACE_Configuration_Heap::get_binary_value const ACE_Configuration_Section_Key   key,
const ACE_TCHAR   name,
void *&    data,
size_t &    length
[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.

Implements ACE_Configuration.

Definition at line 2069 of file Configuration.cpp.

References ACE_ASSERT, ACE_NEW_RETURN, ACE_TCHAR, allocator_, ACE_Configuration::BINARY, ACE_Configuration_Value_IntId::data_, ACE_String_Base< char >::fast_rep, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, ACE_Configuration_Value_IntId >::find, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, ACE_Configuration_Section_IntId >::find, index_, ACE_Configuration_Value_IntId::length_, load_key, ACE_OS_String::memcpy, ACE_Configuration_Value_IntId::type_, ACE_Configuration::validate_name, and ACE_Configuration_Section_IntId::value_hash_map_.

02073 {
02074   ACE_ASSERT (this->allocator_);
02075   if (validate_name (name))
02076     return -1;
02077 
02078   // Get the section name from the key
02079   ACE_TString section;
02080   if (load_key (key, section))
02081     return -1;
02082 
02083   // Find this section
02084   ACE_Configuration_ExtId ExtId (section.fast_rep ());
02085   ACE_Configuration_Section_IntId IntId;
02086   if (index_->find (ExtId, IntId, allocator_))
02087     return -1;    // section does not exist
02088 
02089   ACE_Configuration_ExtId VExtId (name);
02090   ACE_Configuration_Value_IntId VIntId;
02091   // See if it exists first
02092   if (IntId.value_hash_map_->find (VExtId, VIntId, allocator_))
02093     return -1;    // unknown value
02094 
02095   // Check type
02096   if (VIntId.type_ != ACE_Configuration::BINARY)
02097     {
02098       errno = ENOENT;
02099       return -1;
02100     }
02101 
02102   // Make a copy
02103   ACE_NEW_RETURN (data, char[VIntId.length_], -1);
02104   ACE_OS::memcpy (data, VIntId.data_.ptr_, VIntId.length_);
02105   length = VIntId.length_;
02106   return 0;
02107 }

int ACE_Configuration_Heap::get_integer_value const ACE_Configuration_Section_Key   key,
const ACE_TCHAR   name,
u_int &    value
[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.

Implements ACE_Configuration.

Definition at line 2030 of file Configuration.cpp.

References ACE_ASSERT, ACE_TCHAR, allocator_, ACE_Configuration_Value_IntId::data_, ACE_String_Base< char >::fast_rep, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, ACE_Configuration_Value_IntId >::find, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, ACE_Configuration_Section_IntId >::find, index_, ACE_Configuration::INTEGER, load_key, ACE_Configuration_Value_IntId::type_, ACE_Configuration::validate_name, and ACE_Configuration_Section_IntId::value_hash_map_.

02033 {
02034   ACE_ASSERT (this->allocator_);
02035   if (validate_name (name))
02036     return -1;
02037 
02038   // Get the section name from the key
02039   ACE_TString section;
02040   if (load_key (key, section))
02041     return -1;
02042 
02043   // Find this section
02044   ACE_Configuration_ExtId ExtId (section.fast_rep ());
02045   ACE_Configuration_Section_IntId IntId;
02046   if (index_->find (ExtId, IntId, allocator_))
02047     return -1;    // section does not exist
02048 
02049 
02050   // See if it exists first
02051   ACE_Configuration_ExtId VExtId (name);
02052   ACE_Configuration_Value_IntId VIntId;
02053   if (IntId.value_hash_map_->find (VExtId, VIntId, allocator_))
02054     return -1;    // unknown value
02055 
02056   // Check type
02057   if (VIntId.type_ != ACE_Configuration::INTEGER)
02058     {
02059       errno = ENOENT;
02060       return -1;
02061     }
02062 
02063   // Everythings ok, return the data
02064   value = VIntId.data_.int_;
02065   return 0;
02066 }

int ACE_Configuration_Heap::get_string_value const ACE_Configuration_Section_Key   key,
const ACE_TCHAR   name,
ACE_TString   value
[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.

Implements ACE_Configuration.

Definition at line 1992 of file Configuration.cpp.

References ACE_ASSERT, ACE_TCHAR, allocator_, ACE_Configuration_Value_IntId::data_, ACE_String_Base< char >::fast_rep, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, ACE_Configuration_Value_IntId >::find, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, ACE_Configuration_Section_IntId >::find, index_, load_key, ACE_Configuration::STRING, ACE_Configuration_Value_IntId::type_, ACE_Configuration::validate_name, and ACE_Configuration_Section_IntId::value_hash_map_.

01995 {
01996   ACE_ASSERT (this->allocator_);
01997   if (validate_name (name))
01998     return -1;
01999 
02000   // Get the section name from the key
02001   ACE_TString section;
02002   if (load_key (key, section))
02003     return -1;
02004 
02005   // Find this section
02006   ACE_Configuration_ExtId ExtId (section.fast_rep ());
02007   ACE_Configuration_Section_IntId IntId;
02008   if (index_->find (ExtId, IntId, allocator_))
02009     return -1;    // section does not exist
02010 
02011   // See if it exists first
02012   ACE_Configuration_ExtId VExtId (name);
02013   ACE_Configuration_Value_IntId VIntId;
02014   if (IntId.value_hash_map_->find (VExtId, VIntId, allocator_))
02015     return -1;    // unknown value
02016 
02017   // Check type
02018   if (VIntId.type_ != ACE_Configuration::STRING)
02019     {
02020       errno = ENOENT;
02021       return -1;
02022     }
02023 
02024   // everythings ok, return the data
02025   value = ACE_static_cast (ACE_TCHAR*, VIntId.data_.ptr_);
02026   return 0;
02027 }

int ACE_Configuration_Heap::load_key const ACE_Configuration_Section_Key   key,
ACE_TString   name
[private]
 

Definition at line 1367 of file Configuration.cpp.

References ACE_ASSERT, ACE_Configuration::get_internal_key, and ACE_Configuration_Section_Key_Heap::path_.

Referenced by add_section, find_value, get_binary_value, get_integer_value, get_string_value, open_simple_section, remove_section, remove_value, set_binary_value, set_integer_value, and set_string_value.

01369 {
01370   ACE_ASSERT (this->allocator_);
01371   ACE_Configuration_Section_Key_Heap* pKey =
01372     ACE_dynamic_cast (ACE_Configuration_Section_Key_Heap*,
01373                       get_internal_key (key));
01374   if (!pKey)
01375     return -1;
01376 
01377   name = pKey->path_;
01378   return 0;
01379 }

int ACE_Configuration_Heap::new_section const ACE_TString   section,
ACE_Configuration_Section_Key   result
[private]
 

Definition at line 1429 of file Configuration.cpp.

References ACE_ASSERT, ACE_NEW_RETURN, ACE_TCHAR, allocator_, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, ACE_Configuration_Section_IntId >::bind, default_map_size_, ACE_String_Base< char >::fast_rep, ACE_Allocator::free, index_, ACE_String_Base< char >::length, ACE_Allocator::malloc, section_open_helper, ACE_OS_String::strcpy, ACE_Allocator::sync, and value_open_helper.

Referenced by add_section, and create_index.

01431 {
01432   ACE_ASSERT (this->allocator_);
01433   // Create a new section and add it to the global list
01434 
01435   // Allocate memory for items to be stored in the table.
01436   size_t section_len = section.length () + 1;
01437   ACE_TCHAR *ptr = (ACE_TCHAR*) this->allocator_->malloc (section_len * sizeof (ACE_TCHAR));
01438 
01439   int return_value = -1;
01440 
01441   if (ptr == 0)
01442     return -1;
01443   else
01444     {
01445       // Populate memory with data.
01446       ACE_OS::strcpy (ptr, section.fast_rep ());
01447 
01448       void *value_hash_map = 0;
01449       size_t map_size = sizeof (VALUE_MAP);
01450       value_hash_map = this->allocator_->malloc (map_size);
01451 
01452       // If allocation failed ...
01453       if (value_hash_map == 0)
01454         return -1;
01455 
01456       // Initialize allocated hash map through placement new.
01457       if (value_open_helper (default_map_size_, value_hash_map ) == -1)
01458         {
01459           this->allocator_->free (value_hash_map );
01460           return -1;
01461         }
01462 
01463       // create the section map
01464       void* section_hash_map = 0;
01465       map_size = sizeof (SUBSECTION_MAP);
01466       section_hash_map = this->allocator_->malloc (map_size);
01467 
01468       // If allocation failed
01469       if (section_hash_map == 0)
01470         return -1;
01471 
01472       // initialize allocated hash map through placement new
01473       if (section_open_helper (default_map_size_, section_hash_map) == -1)
01474         {
01475           this->allocator_->free (value_hash_map );
01476           this->allocator_->free (section_hash_map);
01477           return -1;
01478         }
01479 
01480       ACE_Configuration_ExtId name (ptr);
01481       ACE_Configuration_Section_IntId entry ((VALUE_MAP*) value_hash_map ,
01482  (SUBSECTION_MAP*) section_hash_map);
01483 
01484       // Do a normal bind.  This will fail if there's already an
01485       // entry with the same name.
01486       return_value = this->index_->bind (name, entry, this->allocator_);
01487 
01488       if (return_value == 1)
01489         {
01490           // Entry already existed so bind failed. Free our dynamically
01491           // allocated memory.
01492           this->allocator_->free ((void *) ptr);
01493           return return_value;
01494         }
01495 
01496       if (return_value == -1)
01497         // Free our dynamically allocated memory.
01498         this->allocator_->free ((void *) ptr);
01499       else
01500         // If bind () succeed, it will automatically sync
01501         // up the map manager entry.  However, we must sync up our
01502         // name/value memory.
01503         this->allocator_->sync (ptr, section_len);
01504 
01505     }
01506 
01507   // set the result
01508   ACE_Configuration_Section_Key_Heap *temp;
01509   ACE_NEW_RETURN (temp,
01510                   ACE_Configuration_Section_Key_Heap (section.fast_rep ()),
01511                   -1);
01512   result = ACE_Configuration_Section_Key (temp);
01513   return return_value;
01514 }

int ACE_Configuration_Heap::open int    default_map_size = ACE_DEFAULT_CONFIG_SECTION_SIZE
 

Opens a heap based configuration.

Definition at line 1268 of file Configuration.cpp.

References ACE_NEW_RETURN, create_index, and default_map_size_.

01269 {
01270   default_map_size_ = default_map_size;
01271   // Create the allocator with the appropriate options.
01272   // The name used for  the lock is the same as one used
01273   // for the file.
01274   ACE_NEW_RETURN (this->allocator_,
01275                   HEAP_ALLOCATOR (),
01276                   -1);
01277   return create_index ();
01278 }

int ACE_Configuration_Heap::open const ACE_TCHAR   file_name,
void *    base_address = ACE_DEFAULT_BASE_ADDR,
int    default_map_size = ACE_DEFAULT_CONFIG_SECTION_SIZE
 

Opens a configuration based on a file name.

Definition at line 1282 of file Configuration.cpp.

References ACE_OS::access, ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_NEW_RETURN, ACE_TCHAR, create_index, default_map_size_, F_OK, LM_ERROR, MAXNAMELEN, MAXPATHLEN, ACE_MMAP_Memory_Pool::OPTIONS, and ACE_OS_String::strlen.

01285 {
01286   default_map_size_ = default_map_size;
01287 
01288   // Make sure that the file name is of the legal length.
01289   if (ACE_OS::strlen (file_name) >= MAXNAMELEN + MAXPATHLEN)
01290     {
01291       errno = ENAMETOOLONG;
01292       return -1;
01293     }
01294 
01295 #if !defined (CHORUS)
01296   ACE_MMAP_Memory_Pool::OPTIONS options (base_address);
01297 #else
01298   // Use base address == 0, don't use a fixed address.
01299   ACE_MMAP_Memory_Pool::OPTIONS options (0,
01300                                          0,
01301                                          0,
01302                                          ACE_CHORUS_LOCAL_NAME_SPACE_T_SIZE);
01303 #endif /* CHORUS */
01304 
01305   // Create the allocator with the appropriate options.  The name used
01306   // for  the lock is the same as one used for the file.
01307   ACE_NEW_RETURN (this->allocator_,
01308                   PERSISTENT_ALLOCATOR (file_name,
01309                                         file_name,
01310                                         &options),
01311                   -1);
01312 
01313 #if !defined (ACE_LACKS_ACCESS)
01314   // Now check if the backing store has been created successfully.
01315   if (ACE_OS::access (file_name, F_OK) != 0)
01316     ACE_ERROR_RETURN ((LM_ERROR,
01317                        ACE_LIB_TEXT ("create_index\n")),
01318                       -1);
01319 #endif /* ACE_LACKS_ACCESS */
01320 
01321   return create_index ();
01322 }

int ACE_Configuration_Heap::open_section const ACE_Configuration_Section_Key   base,
const ACE_TCHAR   sub_section,
int    create,
ACE_Configuration_Section_Key   result
[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.

Implements ACE_Configuration.

Definition at line 1535 of file Configuration.cpp.

References ACE_ASSERT, ACE_TCHAR, ACE_TEXT, ACE_String_Base< char >::c_str, open_simple_section, ACE_OS_String::strchr, and ACE_Configuration::validate_name.

Referenced by remove_section.

01539 {
01540   ACE_ASSERT (this->allocator_);
01541   if (validate_name (sub_section, 1))    // 1 == allow_path
01542     return -1;
01543 
01544   result = base;
01545 
01546   for (const ACE_TCHAR* separator;
01547        (separator = ACE_OS_String::strchr (sub_section, ACE_TEXT ('\\'))) != 0;
01548        )
01549     {
01550       ACE_TString simple_section (sub_section, separator - sub_section);
01551       int ret_val =
01552         open_simple_section (result, simple_section.c_str (), create, result);
01553       if (ret_val)
01554         return ret_val;
01555       sub_section = separator + 1;
01556     }
01557 
01558   return open_simple_section (result, sub_section, create, result);
01559 }

int ACE_Configuration_Heap::open_simple_section const ACE_Configuration_Section_Key   base,
const ACE_TCHAR   sub_section,
int    create,
ACE_Configuration_Section_Key   result
[private]
 

<sub_section> may not contain path separators.

Definition at line 1562 of file Configuration.cpp.

References ACE_LIB_TEXT, ACE_NEW_RETURN, ACE_TCHAR, add_section, allocator_, ACE_String_Base< char >::fast_rep, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, ACE_Configuration_Section_IntId >::find, index_, ACE_String_Base< char >::length, and load_key.

Referenced by open_section.

01566 {
01567   ACE_TString section;
01568   if (load_key (base, section))
01569     return -1;
01570 
01571   // Only add the \\ if were not at the root
01572   if (section.length ())
01573     section += ACE_LIB_TEXT ("\\");
01574 
01575   section += sub_section;
01576 
01577   // resolve the section
01578   ACE_Configuration_ExtId ExtId (section.fast_rep ());
01579   ACE_Configuration_Section_IntId IntId;
01580   if (index_->find (ExtId, IntId, allocator_))
01581     {
01582       if (!create)
01583         {
01584           errno = ENOENT;
01585           return -1;
01586         }
01587       return add_section (base, sub_section, result);
01588     }
01589 
01590   ACE_Configuration_Section_Key_Heap *temp;
01591 
01592   ACE_NEW_RETURN (temp,
01593                   ACE_Configuration_Section_Key_Heap (section.fast_rep ()),
01594                   -1);
01595   result = ACE_Configuration_Section_Key (temp);
01596 
01597   return 0;
01598 }

ACE_Configuration_Heap& ACE_Configuration_Heap::operator= const ACE_Configuration_Heap &    rhs [private]
 

int ACE_Configuration_Heap::remove_section const ACE_Configuration_Section_Key   key,
const ACE_TCHAR   sub_section,
int    recursive
[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 non zero, any subkeys below sub_section are removed as well.
Return values:
0  for success.
-1  for error; ACE_OS::last_error() retrieves error code.

Implements ACE_Configuration.

Definition at line 1601 of file Configuration.cpp.

References ACE_ASSERT, ACE_LIB_TEXT, ACE_TCHAR, allocator_, ACE_Hash_Map_Manager_Ex< ACE_Configuration_ExtId, ACE_Configuration_Value_IntId, ACE_Hash< ACE_Configuration_ExtId >, ACE_Equal_To< ACE_Configuration_ExtId >, ACE_Null_Mutex >::begin, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, int >::close, ACE_Hash_Map_Manager_Ex< ACE_Configuration_ExtId, ACE_Configuration_Value_IntId, ACE_Hash< ACE_Configuration_ExtId >, ACE_Equal_To< ACE_Configuration_ExtId >, ACE_Null_Mutex >::close, ACE_Hash_Map_Manager_Ex< ACE_Configuration_ExtId, int, ACE_Hash< ACE_Configuration_ExtId >, ACE_Equal_To< ACE_Configuration_ExtId >, ACE_Null_Mutex >::current_size, enumerate_sections, ACE_Hash_Map_Entry< ACE_Configuration_ExtId, ACE_Configuration_Value_IntId >::ext_id_, ACE_Hash_Map_Entry< ACE_Configuration_ExtId, ACE_Configuration_Section_IntId >::ext_id_, ACE_Hash_Map_Entry< ACE_Configuration_ExtId, int >::ext_id_, ACE_String_Base< char >::fast_rep, ACE_Hash_Map_Manager_Ex< ACE_Configuration_ExtId, ACE_Configuration_Section_IntId, ACE_Hash< ACE_Configuration_ExtId >, ACE_Equal_To< ACE_Configuration_ExtId >, ACE_Null_Mutex >::find, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, ACE_Configuration_Section_IntId >::find, ACE_Configuration_Section_IntId::free, ACE_Configuration_Value_IntId::free, ACE_Configuration_ExtId::free, index_, ACE_Hash_Map_Entry< ACE_Configuration_ExtId, ACE_Configuration_Value_IntId >::int_id_, ACE_Hash_Map_Entry< ACE_Configuration_ExtId, ACE_Configuration_Section_IntId >::int_id_, ACE_String_Base< char >::length, load_key, open_section, ACE_Configuration_Section_IntId::section_hash_map_, ACE_Hash_Map_Manager_Ex< ACE_Configuration_ExtId, ACE_Configuration_Section_IntId, ACE_Hash< ACE_Configuration_ExtId >, ACE_Equal_To< ACE_Configuration_ExtId >, ACE_Null_Mutex >::unbind, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, int >::unbind, ACE_Configuration::validate_name, and ACE_Configuration_Section_IntId::value_hash_map_.

01604 {
01605   ACE_ASSERT (this->allocator_);
01606   if (validate_name (sub_section))
01607     return -1;
01608 
01609   ACE_TString section;
01610   if (load_key (key, section))
01611     return -1;
01612 
01613   // Find this key
01614   ACE_Configuration_ExtId ParentExtId (section.fast_rep ());
01615   ACE_Configuration_Section_IntId ParentIntId;
01616   if (index_->find (ParentExtId, ParentIntId, allocator_))
01617     return -1;// no parent key
01618 
01619   // Find this subkey
01620   if (section.length ())
01621     section += ACE_LIB_TEXT ("\\");
01622 
01623   section += sub_section;
01624   ACE_Configuration_ExtId SectionExtId (section.fast_rep ());
01625   SECTION_ENTRY* section_entry;
01626   SECTION_HASH* hashmap = index_;
01627   if (hashmap->find (SectionExtId, section_entry))
01628     return -1;
01629 
01630   if (recursive)
01631     {
01632       ACE_Configuration_Section_Key section;
01633       if (open_section (key, sub_section, 0, section))
01634         return -1;
01635 
01636       int index = 0;
01637       ACE_TString name;
01638       while (!enumerate_sections (section, index, name))
01639         {
01640           if (remove_section (section, name.fast_rep (), 1))
01641             return -1;
01642 
01643           index++;
01644         }
01645     }
01646 
01647   // Now make sure we dont have any subkeys
01648   if (section_entry->int_id_.section_hash_map_->current_size ())
01649     {
01650       errno = ENOTEMPTY;
01651       return -1;
01652     }
01653 
01654   // Now remove subkey from parent key
01655   ACE_Configuration_ExtId SubSExtId (sub_section);
01656   SUBSECTION_ENTRY* subsection_entry;
01657   if (((SUBSECTION_HASH*)ParentIntId.section_hash_map_)->
01658       find (SubSExtId, subsection_entry))
01659     return -1;
01660 
01661   if (ParentIntId.section_hash_map_->unbind (SubSExtId, allocator_))
01662     return -1;
01663 
01664   subsection_entry->ext_id_.free (allocator_);
01665 
01666   // Remember the pointers so we can free them after we unbind
01667   ACE_Configuration_ExtId ExtIdToFree (section_entry->ext_id_);
01668   ACE_Configuration_Section_IntId IntIdToFree (section_entry->int_id_);
01669 
01670   // iterate over all values and free memory
01671   VALUE_HASH* value_hash_map = section_entry->int_id_.value_hash_map_;
01672   VALUE_HASH::ITERATOR value_iter = value_hash_map->begin ();
01673   while (!value_iter.done ())
01674     {
01675       VALUE_ENTRY* value_entry;
01676       if (!value_iter.next (value_entry))
01677         return 1;
01678 
01679       value_entry->ext_id_.free (allocator_);
01680       value_entry->int_id_.free (allocator_);
01681 
01682       value_iter.advance ();
01683     }
01684 
01685   // remove it
01686   if (index_->unbind (SectionExtId, allocator_))
01687     return -1;
01688 
01689   value_hash_map->close ();
01690   section_entry->int_id_.section_hash_map_->close (allocator_);
01691 
01692   // Free the memory
01693   ExtIdToFree.free (allocator_);
01694   IntIdToFree.free (allocator_);
01695 
01696   return 0;
01697 }

int ACE_Configuration_Heap::remove_value const ACE_Configuration_Section_Key   key,
const ACE_TCHAR   name
[virtual]
 

Removes the the value <name> from <key>. returns non zero on error.

Implements ACE_Configuration.

Definition at line 2140 of file Configuration.cpp.

References ACE_ASSERT, ACE_TCHAR, allocator_, ACE_Hash_Map_Entry< ACE_Configuration_ExtId, ACE_Configuration_Value_IntId >::ext_id_, ACE_String_Base< char >::fast_rep, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, ACE_Configuration_Section_IntId >::find, ACE_Configuration_Value_IntId::free, ACE_Configuration_ExtId::free, index_, ACE_Hash_Map_Entry< ACE_Configuration_ExtId, ACE_Configuration_Value_IntId >::int_id_, load_key, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, ACE_Configuration_Value_IntId >::unbind, ACE_Configuration::validate_name, and ACE_Configuration_Section_IntId::value_hash_map_.

02142 {
02143   ACE_ASSERT (this->allocator_);
02144   if (validate_name (name))
02145     return -1;
02146 
02147   // Get the section name from the key
02148   ACE_TString section;
02149   if (load_key (key, section))
02150     return -1;
02151 
02152   // Find this section
02153   ACE_Configuration_ExtId ExtId (section.fast_rep ());
02154   ACE_Configuration_Section_IntId IntId;
02155   if (index_->find (ExtId, IntId, allocator_))
02156     return -1;    // section does not exist
02157 
02158   // Find it
02159   ACE_Configuration_ExtId ValueExtId (name);
02160   VALUE_ENTRY* value_entry;
02161   if (((VALUE_HASH *) IntId.value_hash_map_)->find (ValueExtId, value_entry))
02162     return -1;
02163 
02164   // free it
02165   value_entry->ext_id_.free (allocator_);
02166   value_entry->int_id_.free (allocator_);
02167 
02168   // Unbind it
02169   if (IntId.value_hash_map_->unbind (ValueExtId, allocator_))
02170     return -1;
02171 
02172   return 0;
02173 }

int ACE_Configuration_Heap::section_open_helper size_t    hash_table_size,
void *    buffer
[private]
 

Definition at line 1526 of file Configuration.cpp.

References ACE_ASSERT, and SUBSECTION_MAP.

Referenced by new_section.

01528 {
01529   ACE_ASSERT (this->allocator_);
01530   new (buffer) SUBSECTION_MAP (hash_table_size, this->allocator_);
01531   return 0;
01532 }

int ACE_Configuration_Heap::set_binary_value const ACE_Configuration_Section_Key   key,
const ACE_TCHAR   name,
const void *    data,
size_t    length
[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.

Implements ACE_Configuration.

Definition at line 1896 of file Configuration.cpp.

References ACE_ASSERT, ACE_TCHAR, allocator_, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, ACE_Configuration_Value_IntId >::bind, ACE_String_Base< char >::fast_rep, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, ACE_Configuration_Section_IntId >::find, ACE_Allocator::free, ACE_Configuration_Value_IntId::free, index_, ACE_Hash_Map_Entry< ACE_Configuration_ExtId, ACE_Configuration_Value_IntId >::int_id_, load_key, ACE_Allocator::malloc, ACE_OS_String::memcpy, ACE_OS_String::strcpy, ACE_OS_String::strlen, ACE_Configuration::validate_name, and ACE_Configuration_Section_IntId::value_hash_map_.

01900 {
01901   ACE_ASSERT (this->allocator_);
01902   if (validate_name (name))
01903     return -1;
01904 
01905   // Get the section name from the key
01906   ACE_TString section;
01907   if (load_key (key, section))
01908     return -1;
01909 
01910   // Find this section
01911   ACE_Configuration_ExtId section_ext (section.fast_rep ());
01912   ACE_Configuration_Section_IntId section_int;
01913   if (index_->find (section_ext, section_int, allocator_))
01914     return -1;    // section does not exist
01915 
01916   // Get the entry for this item (if it exists)
01917   VALUE_ENTRY* entry;
01918   ACE_Configuration_ExtId item_name (name);
01919   if (section_int.value_hash_map_->VALUE_HASH::find (item_name, entry) == 0)
01920     {
01921       // found item, replace it
01922       // Free the old value
01923       entry->int_id_.free (allocator_);
01924       // Allocate the new value in this heap
01925       ACE_TCHAR* pers_value = (ACE_TCHAR *) allocator_->malloc (length);
01926       ACE_OS::memcpy (pers_value, data, length);
01927       ACE_Configuration_Value_IntId new_value_int (pers_value, length);
01928       entry->int_id_ = new_value_int;
01929     }
01930   else
01931     {
01932       // it doesn't exist, bind it
01933       ACE_TCHAR* pers_name =
01934  (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (name) + 1) * sizeof (ACE_TCHAR));
01935       ACE_OS::strcpy (pers_name, name);
01936       ACE_TCHAR* pers_value = (ACE_TCHAR *) allocator_->malloc (length);
01937       ACE_OS::memcpy (pers_value, data, length);
01938       ACE_Configuration_ExtId item_name (pers_name);
01939       ACE_Configuration_Value_IntId item_value (pers_value, length);
01940       if (section_int.value_hash_map_->bind (item_name, item_value, allocator_))
01941         {
01942           allocator_->free (pers_value);
01943           allocator_->free (pers_name);
01944           return -1;
01945         }
01946       return 0;
01947     }
01948 
01949 /*
01950   // Find this section
01951   ACE_Configuration_ExtId ExtId (section.fast_rep ());
01952   ACE_Configuration_Section_IntId IntId;
01953   if (index_->find (ExtId, IntId, allocator_))
01954     return -1;    // section does not exist
01955 
01956   // See if the value exists first
01957   ACE_Configuration_ExtId VExtIdFind (name);
01958   ACE_Configuration_Value_IntId VIntIdFind;
01959   if (IntId.value_hash_map_->find (VExtIdFind, VIntIdFind, allocator_))
01960     {
01961       // it doesn't exist, bind it
01962       ACE_TCHAR* pers_name =
01963  (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (name) + 1) * sizeof (ACE_TCHAR));
01964       ACE_OS::strcpy (pers_name, name);
01965       ACE_TCHAR* pers_value =
01966  (ACE_TCHAR *) allocator_->malloc (length);
01967       ACE_OS::memcpy (pers_value, data, length);
01968       ACE_Configuration_ExtId VExtId (pers_name);
01969       ACE_Configuration_Value_IntId VIntId (pers_value, length);
01970       if (IntId.value_hash_map_->bind (VExtId, VIntId, allocator_))
01971         {
01972           allocator_->free (pers_value);
01973           allocator_->free (pers_name);
01974           return -1;
01975         }
01976       return 0;
01977     }
01978   else
01979     {
01980       // it does exist, free the old value memory
01981       VIntIdFind.free (allocator_);
01982       // Assign a new value
01983       ACE_TCHAR* pers_value = (ACE_TCHAR *) allocator_->malloc (length);
01984       ACE_OS::memcpy (pers_value, data, length);
01985       VIntIdFind = ACE_Configuration_Value_IntId (pers_value, length);
01986     }
01987 */
01988   return 0;
01989 }

int ACE_Configuration_Heap::set_integer_value const ACE_Configuration_Section_Key   key,
const ACE_TCHAR   name,
u_int    value
[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.

Implements ACE_Configuration.

Definition at line 1848 of file Configuration.cpp.

References ACE_ASSERT, ACE_TCHAR, allocator_, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, ACE_Configuration_Value_IntId >::bind, ACE_String_Base< char >::fast_rep, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, ACE_Configuration_Section_IntId >::find, ACE_Allocator::free, index_, ACE_Hash_Map_Entry< ACE_Configuration_ExtId, ACE_Configuration_Value_IntId >::int_id_, load_key, ACE_Allocator::malloc, ACE_OS_String::strcpy, ACE_OS_String::strlen, ACE_Configuration::validate_name, and ACE_Configuration_Section_IntId::value_hash_map_.

01851 {
01852   ACE_ASSERT (this->allocator_);
01853   if (validate_name (name))
01854     return -1;
01855 
01856   // Get the section name from the key
01857   ACE_TString section;
01858   if (load_key (key, section))
01859     return -1;
01860 
01861   // Find this section
01862   ACE_Configuration_ExtId section_ext (section.fast_rep ());
01863   ACE_Configuration_Section_IntId section_int;
01864   if (index_->find (section_ext, section_int, allocator_))
01865     return -1;  // section does not exist
01866 
01867   // Get the entry for this item (if it exists)
01868   VALUE_ENTRY* entry;
01869   ACE_Configuration_ExtId item_name (name);
01870   if (section_int.value_hash_map_->VALUE_HASH::find (item_name, entry) == 0)
01871     {
01872       // found item, replace it
01873       ACE_Configuration_Value_IntId new_value_int (value);
01874       entry->int_id_ = new_value_int;
01875     }
01876   else
01877     {
01878       // it doesn't exist, bind it
01879       ACE_TCHAR* pers_name =
01880  (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (name) + 1) * sizeof (ACE_TCHAR));
01881       ACE_OS::strcpy (pers_name, name);
01882       ACE_Configuration_ExtId item_name (pers_name);
01883       ACE_Configuration_Value_IntId item_value (value);
01884       if (section_int.value_hash_map_->bind (item_name, item_value, allocator_))
01885         {
01886           allocator_->free (pers_name);
01887           return -1;
01888         }
01889       return 0;
01890     }
01891 
01892   return 0;
01893 }

int ACE_Configuration_Heap::set_string_value const ACE_Configuration_Section_Key   key,
const ACE_TCHAR   name,
const ACE_TString   value
[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.

Implements ACE_Configuration.

Definition at line 1792 of file Configuration.cpp.

References ACE_ASSERT, ACE_TCHAR, allocator_, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, ACE_Configuration_Value_IntId >::bind, ACE_String_Base< char >::fast_rep, ACE_Hash_Map_With_Allocator< ACE_Configuration_ExtId, ACE_Configuration_Section_IntId >::find, ACE_Allocator::free, ACE_Configuration_Value_IntId::free, index_, ACE_Hash_Map_Entry< ACE_Configuration_ExtId, ACE_Configuration_Value_IntId >::int_id_, ACE_String_Base< char >::length, load_key, ACE_Allocator::malloc, ACE_OS_String::strcpy, ACE_OS_String::strlen, ACE_Configuration::validate_name, and ACE_Configuration_Section_IntId::value_hash_map_.

01795 {
01796   ACE_ASSERT (this->allocator_);
01797   if (validate_name (name))
01798     return -1;
01799 
01800   ACE_TString section;
01801   if (load_key (key, section))
01802     return -1;
01803 
01804   ACE_Configuration_ExtId section_ext (section.fast_rep ());
01805   ACE_Configuration_Section_IntId section_int;
01806   if (index_->find (section_ext, section_int, allocator_))
01807     return -1;
01808 
01809   // Get the entry for this item (if it exists)
01810   VALUE_ENTRY* entry;
01811   ACE_Configuration_ExtId item_name (name);
01812   if (section_int.value_hash_map_->VALUE_HASH::find (item_name, entry) == 0)
01813     {
01814       // found item, replace it
01815       // Free the old value
01816       entry->int_id_.free (allocator_);
01817       // Allocate the new value in this heap
01818       ACE_TCHAR* pers_value =
01819  (ACE_TCHAR *) allocator_->malloc ((value.length () + 1) * sizeof (ACE_TCHAR));
01820       ACE_OS::strcpy (pers_value, value.fast_rep ());
01821       ACE_Configuration_Value_IntId new_value_int (pers_value);
01822       entry->int_id_ = new_value_int;
01823     }
01824   else
01825     {
01826       // it doesn't exist, bind it
01827       ACE_TCHAR* pers_name =
01828  (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (name) + 1) * sizeof (ACE_TCHAR));
01829       ACE_OS::strcpy (pers_name, name);
01830       ACE_TCHAR* pers_value =
01831  (ACE_TCHAR *) allocator_->malloc ((value.length () + 1) * sizeof (ACE_TCHAR));
01832       ACE_OS::strcpy (pers_value, value.fast_rep ());
01833       ACE_Configuration_ExtId item_name (pers_name);
01834       ACE_Configuration_Value_IntId item_value (pers_value);
01835       if (section_int.value_hash_map_->bind (item_name, item_value, allocator_))
01836         {
01837           allocator_->free (pers_value);
01838           allocator_->free (pers_name);
01839           return -1;
01840         }
01841       return 0;
01842     }
01843 
01844   return 0;
01845 }

int ACE_Configuration_Heap::value_open_helper size_t    hash_table_size,
void *    buffer
[private]
 

Definition at line 1517 of file Configuration.cpp.

References ACE_ASSERT, and VALUE_MAP.

Referenced by new_section.

01519 {
01520   ACE_ASSERT (this->allocator_);
01521   new (buffer) VALUE_MAP (hash_table_size, this->allocator_);
01522   return 0;
01523 }


Member Data Documentation

ACE_Allocator* ACE_Configuration_Heap::allocator_ [private]
 

Definition at line 864 of file Configuration.h.

Referenced by add_section, create_index, enumerate_sections, enumerate_values, find_value, get_binary_value, get_integer_value, get_string_value, new_section, open_simple_section, remove_section, remove_value, set_binary_value, set_integer_value, set_string_value, and ~ACE_Configuration_Heap.

int ACE_Configuration_Heap::default_map_size_ [private]
 

Definition at line 866 of file Configuration.h.

Referenced by new_section, and open.

SECTION_MAP* ACE_Configuration_Heap::index_ [private]
 

Definition at line 865 of file Configuration.h.

Referenced by add_section, create_index, create_index_helper, enumerate_sections, enumerate_values, find_value, get_binary_value, get_integer_value, get_string_value, new_section, open_simple_section, remove_section, remove_value, set_binary_value, set_integer_value, and set_string_value.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:46:48 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002