The concrete implementation of a allocator based configuration database. More...
#include <Configuration.h>


Public Member Functions | |
| ACE_Configuration_Heap (void) | |
| Default ctor. | |
| virtual | ~ACE_Configuration_Heap (void) |
| Destructor. | |
| int | open (const ACE_TCHAR *file_name, void *base_address=ACE_DEFAULT_BASE_ADDR, size_t default_map_size=ACE_DEFAULT_CONFIG_SECTION_SIZE) |
| int | open (size_t default_map_size=ACE_DEFAULT_CONFIG_SECTION_SIZE) |
| 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, bool recursive) |
| Removes a named section. | |
| 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. | |
| virtual int | set_integer_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, u_int value) |
| 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) |
| Sets a binary-typed value. | |
| virtual int | get_string_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, ACE_TString &value) |
| Gets a string-typed value. | |
| virtual int | get_integer_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, u_int &value) |
| 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) |
| Gets a binary-typed value. | |
| 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. | |
Private Member Functions | |
| 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 | |
| int | add_section (const ACE_Configuration_Section_Key &base, const ACE_TCHAR *sub_section, ACE_Configuration_Section_Key &result) |
| Adds a new section. | |
| int | create_index (void) |
| Helper for the <open> method. | |
| int | create_index_helper (void *buffer) |
| 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 §ion, 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_Allocator * | allocator_ |
| SECTION_MAP * | index_ |
| size_t | default_map_size_ |
The concrete implementation of a allocator based configuration database.
This class uses ACE's Allocators to manage a memory representation of a configuration database. A persistent heap may be used to store configurations persistently
Definition at line 784 of file Configuration.h.
| ACE_Configuration_Heap::ACE_Configuration_Heap | ( | void | ) |
Default ctor.
Definition at line 1240 of file Configuration.cpp.
: allocator_ (0), index_ (0), default_map_size_ (0) { ACE_Configuration_Section_Key_Heap *temp = 0; ACE_NEW (temp, ACE_Configuration_Section_Key_Heap (ACE_TEXT (""))); root_ = ACE_Configuration_Section_Key (temp); }
| ACE_Configuration_Heap::~ACE_Configuration_Heap | ( | void | ) | [virtual] |
Destructor.
Definition at line 1251 of file Configuration.cpp.
{
if (allocator_)
allocator_->sync ();
delete allocator_;
}
| ACE_Configuration_Heap::ACE_Configuration_Heap | ( | const ACE_Configuration_Heap & | rhs | ) | [private] |
| 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 1382 of file Configuration.cpp.
{
ACE_ASSERT (this->allocator_);
ACE_TString section;
if (load_key (base, section))
return -1;
// Find the base section
ACE_Configuration_ExtId ExtId (section.fast_rep ());
ACE_Configuration_Section_IntId IntId;
if (index_->find (ExtId, IntId, allocator_))
return -1;
// See if this section already exists
ACE_Configuration_ExtId SubSectionExtId (sub_section);
int ignored = 0;
if (!IntId.section_hash_map_->find (SubSectionExtId, ignored, allocator_))
{
// already exists!
errno = EEXIST;
return -1;
}
// Create the new section name
// only prepend a separater if were not at the root
if (section.length ())
section += ACE_TEXT ("\\");
section += sub_section;
// Add it to the base section
ACE_TCHAR* pers_name = (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (sub_section) + 1) * sizeof (ACE_TCHAR));
ACE_OS::strcpy (pers_name, sub_section);
ACE_Configuration_ExtId SSExtId (pers_name);
if (IntId.section_hash_map_->bind (SSExtId, ignored, allocator_))
{
allocator_->free (pers_name);
return -1;
}
return (new_section (section, result));
}
| int ACE_Configuration_Heap::create_index | ( | void | ) | [private] |
Helper for the <open> method.
Definition at line 1321 of file Configuration.cpp.
{
void *section_index = 0;
// This is the easy case since if we find hash table in the
// memory-mapped file we know it's already initialized.
if (this->allocator_->find (ACE_CONFIG_SECTION_INDEX, section_index) == 0)
this->index_ = (SECTION_MAP *) section_index;
// Create a new <index_> (because we've just created a new
// memory-mapped file).
else
{
size_t index_size = sizeof (SECTION_MAP);
section_index = this->allocator_->malloc (index_size);
if (section_index == 0
|| create_index_helper (section_index) == -1
|| this->allocator_->bind (ACE_CONFIG_SECTION_INDEX,
section_index) == -1)
{
// Attempt to clean up.
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("create_index failed\n")));
this->allocator_->remove ();
return -1;
}
// Add the root section
return new_section (ACE_TEXT (""), root_);
}
return 0;
}
| 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 1355 of file Configuration.cpp.
{
ACE_ASSERT (this->allocator_);
this->index_ = new (buffer) SECTION_MAP (this->allocator_);
return 0;
}
| 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.
| 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. |
| 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 1748 of file Configuration.cpp.
{
ACE_ASSERT (this->allocator_);
// cast to a heap section key
ACE_Configuration_Section_Key_Heap* pKey =
dynamic_cast<ACE_Configuration_Section_Key_Heap*> (get_internal_key (key));
if (!pKey)
return -1; // not a heap key!
// resolve the section
ACE_Configuration_ExtId ExtId (pKey->path_);
ACE_Configuration_Section_IntId IntId;
if (index_->find (ExtId, IntId, allocator_))
return -1; // unknown section
// Handle iterator resets
if (index == 0)
{
if (pKey->section_iter_)
delete pKey->section_iter_;
ACE_NEW_RETURN (pKey->section_iter_,
SUBSECTION_HASH::ITERATOR (IntId.section_hash_map_->begin ()),
-1);
}
// Get the next entry
ACE_Hash_Map_Entry<ACE_Configuration_ExtId, int>* entry = 0;
if (!pKey->section_iter_->next (entry))
return 1;
// Return the value of the iterator and advance it
pKey->section_iter_->advance ();
name = entry->ext_id_.name_;
return 0;
}
| 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.
| 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. |
| 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 1699 of file Configuration.cpp.
{
ACE_ASSERT (this->allocator_);
ACE_Configuration_Section_Key_Heap* pKey =
dynamic_cast<ACE_Configuration_Section_Key_Heap*> (get_internal_key (key));
if (!pKey)
return -1;
name = pKey->path_;
// resolve the section
ACE_Configuration_ExtId ExtId (pKey->path_);
ACE_Configuration_Section_IntId IntId;
if (index_->find (ExtId, IntId, allocator_))
return -1;
// Handle iterator resets
if (index == 0)
{
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>* hash_map = IntId.value_hash_map_;
delete pKey->value_iter_;
ACE_NEW_RETURN (pKey->value_iter_,
VALUE_HASH::ITERATOR (hash_map->begin ()),
-1);
}
// Get the next entry
ACE_Hash_Map_Entry<ACE_Configuration_ExtId, ACE_Configuration_Value_IntId>* entry = 0;
if (!pKey->value_iter_->next (entry))
return 1;
// Return the value of the iterator and advance it
name = entry->ext_id_.name_;
type = entry->int_id_.type_;
pKey->value_iter_->advance ();
return 0;
}
| 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.
| 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. |
| 0 | for success. | |
| -1 | for error; ACE_OS::last_error() retrieves error code. |
Implements ACE_Configuration.
Definition at line 2085 of file Configuration.cpp.
{
ACE_ASSERT (this->allocator_);
const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
if (validate_value_name (t_name))
return -1;
// Get the section name from the key
ACE_TString section;
if (load_key (key, section))
return -1;
// Find this section
ACE_Configuration_ExtId ExtId (section.fast_rep ());
ACE_Configuration_Section_IntId IntId;
if (index_->find (ExtId, IntId, allocator_))
return -1; // section does not exist
// Find it
ACE_Configuration_ExtId ValueExtId (t_name);
VALUE_HASH::ENTRY* value_entry = 0;
if (((VALUE_HASH *) IntId.value_hash_map_)->find (ValueExtId, value_entry))
return -1; // value does not exist
type_out = value_entry->int_id_.type_;
return 0;
}
| 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.
| 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. |
| 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 2042 of file Configuration.cpp.
{
ACE_ASSERT (this->allocator_);
const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
if (validate_value_name (t_name))
return -1;
// Get the section name from the key
ACE_TString section;
if (load_key (key, section))
return -1;
// Find this section
ACE_Configuration_ExtId ExtId (section.fast_rep ());
ACE_Configuration_Section_IntId IntId;
if (index_->find (ExtId, IntId, allocator_))
return -1; // section does not exist
ACE_Configuration_ExtId VExtId (t_name);
ACE_Configuration_Value_IntId VIntId;
// See if it exists first
if (IntId.value_hash_map_->find (VExtId, VIntId, allocator_))
return -1; // unknown value
// Check type
if (VIntId.type_ != ACE_Configuration::BINARY)
{
errno = ENOENT;
return -1;
}
// Make a copy
ACE_NEW_RETURN (data, char[VIntId.length_], -1);
ACE_OS::memcpy (data, VIntId.data_.ptr_, VIntId.length_);
length = VIntId.length_;
return 0;
}
| 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.
| 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. |
| 0 | for success. | |
| -1 | for error; ACE_OS::last_error() retrieves error code. |
Implements ACE_Configuration.
Definition at line 1992 of file Configuration.cpp.
{
ACE_ASSERT (this->allocator_);
const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
if (validate_value_name (t_name))
return -1;
// Get the section name from the key
ACE_TString section (0, 0, false);
if (this->load_key (key, section) != 0)
{
return -1;
}
// Find this section
ACE_Configuration_ExtId ExtId (section.fast_rep ());
ACE_Configuration_Section_IntId IntId;
if (index_->find (ExtId, IntId, allocator_) != 0)
{
return -1; // section does not exist
}
// See if it exists first
ACE_Configuration_ExtId VExtId (t_name);
ACE_Configuration_Value_IntId VIntId;
if (IntId.value_hash_map_->find (VExtId, VIntId, allocator_) != 0)
{
return -1; // unknown value
}
// Check type
if (VIntId.type_ != ACE_Configuration::INTEGER)
{
errno = ENOENT;
return -1;
}
// Everythings ok, return the data
value = VIntId.data_.int_;
return 0;
}
| 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.
| 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. |
| 0 | for success. | |
| -1 | for error; ACE_OS::last_error() retrieves error code. |
Implements ACE_Configuration.
Definition at line 1953 of file Configuration.cpp.
{
ACE_ASSERT (this->allocator_);
const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
if (validate_value_name (t_name))
return -1;
// Get the section name from the key
ACE_TString section;
if (load_key (key, section))
return -1;
// Find this section
ACE_Configuration_ExtId ExtId (section.fast_rep ());
ACE_Configuration_Section_IntId IntId;
if (index_->find (ExtId, IntId, allocator_))
return -1; // section does not exist
// See if it exists first
ACE_Configuration_ExtId VExtId (t_name);
ACE_Configuration_Value_IntId VIntId;
if (IntId.value_hash_map_->find (VExtId, VIntId, allocator_))
return -1; // unknown value
// Check type
if (VIntId.type_ != ACE_Configuration::STRING)
{
errno = ENOENT;
return -1;
}
// everythings ok, return the data
value = static_cast<ACE_TCHAR*> (VIntId.data_.ptr_);
return 0;
}
| int ACE_Configuration_Heap::load_key | ( | const ACE_Configuration_Section_Key & | key, | |
| ACE_TString & | name | |||
| ) | [private] |
Definition at line 1363 of file Configuration.cpp.
{
ACE_ASSERT (this->allocator_);
ACE_Configuration_Section_Key_Heap* pKey =
dynamic_cast<ACE_Configuration_Section_Key_Heap*> (get_internal_key (key));
if (!pKey)
{
return -1;
}
ACE_TString temp (pKey->path_, 0, false);
name.assign_nocopy (temp);
return 0;
}
| int ACE_Configuration_Heap::new_section | ( | const ACE_TString & | section, | |
| ACE_Configuration_Section_Key & | result | |||
| ) | [private] |
Definition at line 1428 of file Configuration.cpp.
{
ACE_ASSERT (this->allocator_);
// Create a new section and add it to the global list
// Allocate memory for items to be stored in the table.
size_t section_len = section.length () + 1;
ACE_TCHAR *ptr = (ACE_TCHAR*) this->allocator_->malloc (section_len * sizeof (ACE_TCHAR));
int return_value = -1;
if (ptr == 0)
return -1;
else
{
// Populate memory with data.
ACE_OS::strcpy (ptr, section.fast_rep ());
void *value_hash_map = 0;
size_t map_size = sizeof (VALUE_MAP);
value_hash_map = this->allocator_->malloc (map_size);
// If allocation failed ...
if (value_hash_map == 0)
return -1;
// Initialize allocated hash map through placement new.
if (value_open_helper (default_map_size_, value_hash_map ) == -1)
{
this->allocator_->free (value_hash_map );
return -1;
}
// create the section map
void* section_hash_map = 0;
map_size = sizeof (SUBSECTION_MAP);
section_hash_map = this->allocator_->malloc (map_size);
// If allocation failed
if (section_hash_map == 0)
return -1;
// initialize allocated hash map through placement new
if (section_open_helper (default_map_size_, section_hash_map) == -1)
{
this->allocator_->free (value_hash_map );
this->allocator_->free (section_hash_map);
return -1;
}
ACE_Configuration_ExtId name (ptr);
ACE_Configuration_Section_IntId entry ((VALUE_MAP*) value_hash_map,
(SUBSECTION_MAP*) section_hash_map);
// Do a normal bind. This will fail if there's already an
// entry with the same name.
return_value = this->index_->bind (name, entry, this->allocator_);
if (return_value == 1 /* Entry already existed so bind failed. */
|| return_value == -1 /* Unable to bind for other reasons. */)
{
// Free our dynamically allocated memory.
this->allocator_->free (static_cast<void *> (ptr));
return return_value;
}
// If bind () succeed, it will automatically sync
// up the map manager entry. However, we must sync up our
// name/value memory.
this->allocator_->sync (ptr, section_len);
}
// set the result
ACE_Configuration_Section_Key_Heap *temp;
ACE_NEW_RETURN (temp,
ACE_Configuration_Section_Key_Heap (ptr),
-1);
result = ACE_Configuration_Section_Key (temp);
return return_value;
}
| int ACE_Configuration_Heap::open | ( | size_t | default_map_size = ACE_DEFAULT_CONFIG_SECTION_SIZE |
) |
Opens a configuration that allocates memory from the heap.
| default_map_size | Starting size for the internal hash tables that contain configuration information. |
| 0 | for success. | |
| -1 | for error, with errno set to indicate the cause. If open() is called multiple times, errno will be EBUSY. |
Definition at line 1260 of file Configuration.cpp.
{
if (this->allocator_ != 0)
{
errno = EBUSY;
return -1;
}
default_map_size_ = default_map_size;
// Create the allocator with the appropriate options.
// The name used for the lock is the same as one used
// for the file.
ACE_NEW_RETURN (this->allocator_,
HEAP_ALLOCATOR (),
-1);
return create_index ();
}
| int ACE_Configuration_Heap::open | ( | const ACE_TCHAR * | file_name, | |
| void * | base_address = ACE_DEFAULT_BASE_ADDR, |
|||
| size_t | default_map_size = ACE_DEFAULT_CONFIG_SECTION_SIZE | |||
| ) |
Opens a configuration that allocates its memory from a memory-mapped file. This makes it possible to persist a configuration to permanent storage. This is not the same as exporting the configuration to a file; the memory-mapped file is not likely to be very readable by humans.
| file_name | Name of the file to map into memory. | |
| base_address | Address to map the base of file_name to. | |
| default_map_size | Starting size for the internal hash tables that contain configuration information. |
| 0 | for success. | |
| -1 | for error, with errno set to indicate the cause. If open() is called multiple times, errno will be EBUSY. |
Definition at line 1280 of file Configuration.cpp.
{
if (this->allocator_ != 0)
{
errno = EBUSY;
return -1;
}
default_map_size_ = default_map_size;
// Make sure that the file name is of the legal length.
if (ACE_OS::strlen (file_name) >= MAXNAMELEN + MAXPATHLEN)
{
errno = ENAMETOOLONG;
return -1;
}
ACE_MMAP_Memory_Pool::OPTIONS options (base_address);
// Create the allocator with the appropriate options. The name used
// for the lock is the same as one used for the file.
ACE_NEW_RETURN (this->allocator_,
PERSISTENT_ALLOCATOR (file_name,
file_name,
&options),
-1);
#if !defined (ACE_LACKS_ACCESS)
// Now check if the backing store has been created successfully.
if (ACE_OS::access (file_name, F_OK) != 0)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("create_index\n")),
-1);
#endif /* ACE_LACKS_ACCESS */
return create_index ();
}
| 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.
| 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. |
| 0 | for success. | |
| -1 | for error; ACE_OS::last_error() retrieves error code. |
Implements ACE_Configuration.
Definition at line 1529 of file Configuration.cpp.
{
ACE_ASSERT (this->allocator_);
if (validate_name (sub_section, 1)) // 1 == allow_path
return -1;
result = base;
for (const ACE_TCHAR* separator;
(separator = ACE_OS::strchr (sub_section, ACE_TEXT ('\\'))) != 0;
)
{
ACE_TString simple_section (sub_section, separator - sub_section);
int ret_val =
open_simple_section (result, simple_section.c_str (), create, result);
if (ret_val)
return ret_val;
sub_section = separator + 1;
}
return open_simple_section (result, sub_section, create, result);
}
| 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 1556 of file Configuration.cpp.
{
ACE_TString section (0, 0, false);
if (load_key (base, section))
{
return -1;
}
// Only add the \\ if were not at the root
if (section.length ())
{
section += ACE_TEXT ("\\");
}
section += sub_section;
// resolve the section
ACE_Configuration_ExtId ExtId (section.fast_rep ());
ACE_Configuration_Section_IntId IntId;
if (index_->find (ExtId, IntId, allocator_))
{
if (!create)
{
errno = ENOENT;
return -1;
}
return add_section (base, sub_section, result);
}
ACE_Configuration_Section_Key_Heap *temp;
ACE_NEW_RETURN (temp,
ACE_Configuration_Section_Key_Heap (section.fast_rep ()),
-1);
result = ACE_Configuration_Section_Key (temp);
return 0;
}
| 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, | |||
| bool | recursive | |||
| ) | [virtual] |
Removes a named section.
| key | Section key to remove the named section from. | |
| sub_section | Name of the section to remove. | |
| recursive | If true, any subkeys below sub_section are removed as well. |
| 0 | for success. | |
| -1 | for error; ACE_OS::last_error() retrieves error code. |
Implements ACE_Configuration.
Definition at line 1600 of file Configuration.cpp.
{
ACE_ASSERT (this->allocator_);
if (validate_name (sub_section))
return -1;
ACE_TString section;
if (load_key (key, section))
return -1;
// Find this key
ACE_Configuration_ExtId ParentExtId (section.fast_rep ());
ACE_Configuration_Section_IntId ParentIntId;
if (index_->find (ParentExtId, ParentIntId, allocator_))
return -1;// no parent key
// Find this subkey
if (section.length ())
section += ACE_TEXT ("\\");
section += sub_section;
ACE_Configuration_ExtId SectionExtId (section.fast_rep ());
SECTION_HASH::ENTRY* section_entry = 0;
SECTION_HASH* hashmap = index_;
if (hashmap->find (SectionExtId, section_entry))
return -1;
if (recursive)
{
ACE_Configuration_Section_Key section;
if (open_section (key, sub_section, 0, section))
return -1;
int index = 0;
ACE_TString name;
while (!enumerate_sections (section, index, name))
{
if (remove_section (section, name.fast_rep (), true))
return -1;
++index;
}
}
// Now make sure we dont have any subkeys
if (section_entry->int_id_.section_hash_map_->current_size ())
{
errno = ENOTEMPTY;
return -1;
}
// Now remove subkey from parent key
ACE_Configuration_ExtId SubSExtId (sub_section);
SUBSECTION_HASH::ENTRY* subsection_entry;
if (((SUBSECTION_HASH*)ParentIntId.section_hash_map_)->
find (SubSExtId, subsection_entry))
return -1;
if (ParentIntId.section_hash_map_->unbind (SubSExtId, allocator_))
return -1;
subsection_entry->ext_id_.free (allocator_);
// Remember the pointers so we can free them after we unbind
ACE_Configuration_ExtId ExtIdToFree (section_entry->ext_id_);
ACE_Configuration_Section_IntId IntIdToFree (section_entry->int_id_);
// iterate over all values and free memory
VALUE_HASH* value_hash_map = section_entry->int_id_.value_hash_map_;
VALUE_HASH::ITERATOR value_iter = value_hash_map->begin ();
while (!value_iter.done ())
{
VALUE_HASH::ENTRY* value_entry = 0;
if (!value_iter.next (value_entry))
return 1;
value_entry->ext_id_.free (allocator_);
value_entry->int_id_.free (allocator_);
value_iter.advance ();
}
// remove it
if (index_->unbind (SectionExtId, allocator_))
return -1;
value_hash_map->close ();
section_entry->int_id_.section_hash_map_->close (allocator_);
// Free the memory
ExtIdToFree.free (allocator_);
IntIdToFree.free (allocator_);
return 0;
}
| 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 2116 of file Configuration.cpp.
{
ACE_ASSERT (this->allocator_);
const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
if (validate_value_name (t_name))
return -1;
// Get the section name from the key
ACE_TString section;
if (load_key (key, section))
return -1;
// Find this section
ACE_Configuration_ExtId ExtId (section.fast_rep ());
ACE_Configuration_Section_IntId IntId;
if (index_->find (ExtId, IntId, allocator_))
return -1; // section does not exist
// Find it
ACE_Configuration_ExtId ValueExtId (t_name);
VALUE_HASH::ENTRY* value_entry = 0;
if (((VALUE_HASH *) IntId.value_hash_map_)->find (ValueExtId, value_entry))
return -1;
// free it
value_entry->ext_id_.free (allocator_);
value_entry->int_id_.free (allocator_);
// Unbind it
if (IntId.value_hash_map_->unbind (ValueExtId, allocator_))
return -1;
return 0;
}
| int ACE_Configuration_Heap::section_open_helper | ( | size_t | hash_table_size, | |
| void * | buffer | |||
| ) | [private] |
Definition at line 1520 of file Configuration.cpp.
{
ACE_ASSERT (this->allocator_);
new (buffer) SUBSECTION_MAP (hash_table_size, this->allocator_);
return 0;
}
| 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.
| 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. |
| 0 | for success. | |
| -1 | for error; ACE_OS::last_error() retrieves error code. |
Implements ACE_Configuration.
Definition at line 1895 of file Configuration.cpp.
{
ACE_ASSERT (this->allocator_);
const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
if (validate_value_name (t_name))
return -1;
// Get the section name from the key
ACE_TString section;
if (load_key (key, section))
return -1;
// Find this section
ACE_Configuration_ExtId section_ext (section.fast_rep ());
ACE_Configuration_Section_IntId section_int;
if (index_->find (section_ext, section_int, allocator_))
return -1; // section does not exist
// Get the entry for this item (if it exists)
VALUE_HASH::ENTRY* entry = 0;
ACE_Configuration_ExtId item_name (t_name);
if (section_int.value_hash_map_->VALUE_HASH::find (item_name, entry) == 0)
{
// found item, replace it
// Free the old value
entry->int_id_.free (allocator_);
// Allocate the new value in this heap
ACE_TCHAR* pers_value = (ACE_TCHAR *) allocator_->malloc (length);
ACE_OS::memcpy (pers_value, data, length);
ACE_Configuration_Value_IntId new_value_int (pers_value, length);
entry->int_id_ = new_value_int;
}
else
{
// it doesn't exist, bind it
ACE_TCHAR* pers_name =
(ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (t_name) + 1) * sizeof (ACE_TCHAR));
ACE_OS::strcpy (pers_name, t_name);
ACE_TCHAR* pers_value = (ACE_TCHAR *) allocator_->malloc (length);
ACE_OS::memcpy (pers_value, data, length);
ACE_Configuration_ExtId item_name (pers_name);
ACE_Configuration_Value_IntId item_value (pers_value, length);
if (section_int.value_hash_map_->bind (item_name, item_value, allocator_))
{
allocator_->free (pers_value);
allocator_->free (pers_name);
return -1;
}
return 0;
}
return 0;
}
| 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.
| 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. |
| 0 | for success. | |
| -1 | for error; ACE_OS::last_error() retrieves error code. |
Implements ACE_Configuration.
Definition at line 1846 of file Configuration.cpp.
{
ACE_ASSERT (this->allocator_);
const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
if (validate_value_name (t_name))
return -1;
// Get the section name from the key
ACE_TString section;
if (load_key (key, section))
return -1;
// Find this section
ACE_Configuration_ExtId section_ext (section.fast_rep ());
ACE_Configuration_Section_IntId section_int;
if (index_->find (section_ext, section_int, allocator_))
return -1; // section does not exist
// Get the entry for this item (if it exists)
VALUE_HASH::ENTRY* entry = 0;
ACE_Configuration_ExtId item_name (t_name);
if (section_int.value_hash_map_->VALUE_HASH::find (item_name, entry) == 0)
{
// found item, replace it
ACE_Configuration_Value_IntId new_value_int (value);
entry->int_id_ = new_value_int;
}
else
{
// it doesn't exist, bind it
ACE_TCHAR* pers_name =
(ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (t_name) + 1) * sizeof (ACE_TCHAR));
ACE_OS::strcpy (pers_name, t_name);
ACE_Configuration_ExtId item_name (pers_name);
ACE_Configuration_Value_IntId item_value (value);
if (section_int.value_hash_map_->bind (item_name, item_value, allocator_))
{
allocator_->free (pers_name);
return -1;
}
return 0;
}
return 0;
}
| 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.
| 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. |
| 0 | for success. | |
| -1 | for error; ACE_OS::last_error() retrieves error code. |
Implements ACE_Configuration.
Definition at line 1789 of file Configuration.cpp.
{
ACE_ASSERT (this->allocator_);
const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
if (validate_value_name (t_name))
return -1;
ACE_TString section;
if (load_key (key, section))
return -1;
ACE_Configuration_ExtId section_ext (section.fast_rep ());
ACE_Configuration_Section_IntId section_int;
if (index_->find (section_ext, section_int, allocator_))
return -1;
// Get the entry for this item (if it exists)
VALUE_HASH::ENTRY* entry = 0;
ACE_Configuration_ExtId item_name (t_name);
if (section_int.value_hash_map_->VALUE_HASH::find (item_name, entry) == 0)
{
// found item, replace it
// Free the old value
entry->int_id_.free (allocator_);
// Allocate the new value in this heap
ACE_TCHAR* pers_value =
(ACE_TCHAR *) allocator_->malloc ((value.length () + 1) * sizeof (ACE_TCHAR));
ACE_OS::strcpy (pers_value, value.fast_rep ());
ACE_Configuration_Value_IntId new_value_int (pers_value);
entry->int_id_ = new_value_int;
}
else
{
// it doesn't exist, bind it
ACE_TCHAR* pers_name =
(ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (t_name) + 1) * sizeof (ACE_TCHAR));
ACE_OS::strcpy (pers_name, t_name);
ACE_TCHAR* pers_value =
(ACE_TCHAR *) allocator_->malloc ((value.length () + 1) * sizeof (ACE_TCHAR));
ACE_OS::strcpy (pers_value, value.fast_rep ());
ACE_Configuration_ExtId item_name (pers_name);
ACE_Configuration_Value_IntId item_value (pers_value);
if (section_int.value_hash_map_->bind (item_name, item_value, allocator_))
{
allocator_->free (pers_value);
allocator_->free (pers_name);
return -1;
}
return 0;
}
return 0;
}
| int ACE_Configuration_Heap::value_open_helper | ( | size_t | hash_table_size, | |
| void * | buffer | |||
| ) | [private] |
Definition at line 1511 of file Configuration.cpp.
{
ACE_ASSERT (this->allocator_);
new (buffer) VALUE_MAP (hash_table_size, this->allocator_);
return 0;
}
ACE_Allocator* ACE_Configuration_Heap::allocator_ [private] |
Definition at line 907 of file Configuration.h.
size_t ACE_Configuration_Heap::default_map_size_ [private] |
Definition at line 909 of file Configuration.h.
SECTION_MAP* ACE_Configuration_Heap::index_ [private] |
Definition at line 908 of file Configuration.h.
1.7.0