Also use Objects as part of an operation but as a result don't generate Any operation...
[ACE_TAO.git] / ACE / ace / Configuration.h
blob7e89c4de42e4d7d98e3042ba8e28757beb36917e
1 /* -*- C++ -*- */
3 //=============================================================================
4 /**
5 * @file Configuration.h
7 * @author Chris Hafey <chafey@stentor.com>
9 * The ACE configuration API provides a portable abstraction for
10 * program configuration similar to the Microsoft Windows registry.
11 * The API supports a tree based hierarchy of configuration sections. Each
12 * section contains other sections or values. Values may contain string,
13 * unsigned integer and binary data.
15 * @note These classes are not thread safe, if multiple threads use these
16 * classes, you are responsible for serializing access.
18 * For examples of using this class, see:
19 * -# The test code in ACE_wrappers/test
20 * -# wxConfigViewer, a Windows like Registry Editor for ACE_Configuration
21 * -# TAO's IFR, it makes extensive use of ACE_Configuration
23 * @todo Templatize this class with an ACE_LOCK to provide thread safety
25 //=============================================================================
27 #ifndef ACE_CONFIGURATION_H
28 #define ACE_CONFIGURATION_H
29 #include /**/ "ace/pre.h"
31 #include "ace/SStringfwd.h"
32 #include "ace/Hash_Map_With_Allocator_T.h"
33 #include "ace/Malloc_T.h"
34 #include "ace/MMAP_Memory_Pool.h"
35 #include "ace/Local_Memory_Pool.h"
36 #include "ace/Synch_Traits.h"
39 #if !defined (ACE_LACKS_PRAGMA_ONCE)
40 # pragma once
41 #endif /* ACE_LACKS_PRAGMA_ONCE */
43 // configurable parameters
45 #if !defined (ACE_CONFIG_SECTION_INDEX)
46 # define ACE_CONFIG_SECTION_INDEX "Config_Section_Index"
47 #endif /* ! ACE_CONFIG_SECTION_INDEX */
49 #if !defined (ACE_DEFAULT_CONFIG_SECTION_SIZE)
50 #define ACE_DEFAULT_CONFIG_SECTION_SIZE 16
51 #endif /* ACE_DEFAULT_CONFIG_SECTION_SIZE */
53 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
55 /**
56 * @class ACE_Section_Key_Internal
58 * @internal
60 * @brief A base class for internal handles to section keys for
61 * configuration implementations
63 * Implementations subclass this base class to represent a
64 * section key.
66 class ACE_Export ACE_Section_Key_Internal
68 public:
69 /// Virtual destructor, make sure descendants are virtual!
70 virtual ~ACE_Section_Key_Internal (void);
72 /// Increment reference count
73 virtual int add_ref (void);
75 /// Decrement reference count. Will delete this if count gets to 0
76 virtual int dec_ref (void);
77 protected:
78 ACE_Section_Key_Internal (void);
79 ACE_Section_Key_Internal (const ACE_Section_Key_Internal& rhs);
80 ACE_Section_Key_Internal& operator= (ACE_Section_Key_Internal& rhs);
82 u_int ref_count_;
85 /**
86 * @class ACE_Configuration_Section_Key
88 * @brief Reference counted wrapper for ACE_Section_Key_Internal.
90 * Reference counted wrapper class for the abstract internal
91 * section key. A user gets one of these to represent a section
92 * in the configuration database.
94 class ACE_Export ACE_Configuration_Section_Key
96 friend class ACE_Configuration;
97 public:
98 /// Default constructor.
99 ACE_Configuration_Section_Key (void);
101 /// Constructor that initializes to a pointer to a concrete internal key.
103 * @param key The section key to reference. Calls add_ref() with @a key.
105 explicit ACE_Configuration_Section_Key (ACE_Section_Key_Internal *key);
107 /// Copy constructor, increments the reference count on the key.
108 ACE_Configuration_Section_Key (const ACE_Configuration_Section_Key &rhs);
110 /// Destructor, decrements reference count on the referenced key.
111 ~ACE_Configuration_Section_Key (void);
113 /// Assignment operator, increments reference count for this object
114 /// and decrements it on @a rhs.
115 ACE_Configuration_Section_Key &
116 operator= (const ACE_Configuration_Section_Key &rhs);
117 private:
118 ACE_Section_Key_Internal *key_;
122 * @class ACE_Configuration
124 * @internal
126 * @brief Base class for configuration databases
128 * This class provides an interface for configuration databases. A concrete
129 * class is required that implements the interface.
131 * @sa ACE_Configuration_Heap
132 * @sa ACE_Configuration_Win32Registry
134 class ACE_Export ACE_Configuration
136 public:
137 /// Enumeration for the various types of values we can store.
138 enum VALUETYPE
140 STRING,
141 INTEGER,
142 BINARY,
143 INVALID
146 /// Destructor
147 virtual ~ACE_Configuration (void);
149 /// Obtain a reference to the root section of this configuration.
151 * @return Reference to the configuration's root section. Note that
152 * it is a const reference.
154 virtual const ACE_Configuration_Section_Key& root_section (void) const;
157 * Opens a named section in an existing section.
159 * @param base Existing section in which to open the named section.
160 * @param sub_section Name of the section to open.
161 * @param create If false, the named section must exist, otherwise
162 * the named section will be created if it does not exist.
163 * @param result Reference; receives the section key for the new
164 * section.
166 * @retval 0 for success.
167 * @retval -1 for error; ACE_OS::last_error() retrieves error code.
169 virtual int open_section (const ACE_Configuration_Section_Key &base,
170 const ACE_TCHAR *sub_section,
171 bool create,
172 ACE_Configuration_Section_Key& result) = 0;
174 /// Removes a named section.
176 * @param key Section key to remove the named section from.
177 * @param sub_section Name of the section to remove.
178 * @param recursive If true, any subkeys below @a sub_section are
179 * removed as well.
181 * @retval 0 for success.
182 * @retval -1 for error; ACE_OS::last_error() retrieves error code.
184 virtual int remove_section (const ACE_Configuration_Section_Key &key,
185 const ACE_TCHAR *sub_section,
186 bool recursive) = 0;
189 * Enumerates through the values in a section.
191 * @param key Section key to iterate through.
192 * @param index Iteration position. Must be zero on the first call to
193 * iterate through @a key. Increment @a index by one on each
194 * successive call to this method.
195 * @param name Receives the value's name.
196 * @param type Receives the value's data type.
198 * @note You may not delete or add values while enumerating. If the
199 * section is modified during enumeration, results are undefined;
200 * you must restart the enumeration from index 0.
202 * @retval 0 for success, @a name and @a type are valid.
203 * @retval 1 there are no more values in the section.
204 * @retval -1 for error; ACE_OS::last_error() retrieves error code.
206 virtual int enumerate_values (const ACE_Configuration_Section_Key& key,
207 int index,
208 ACE_TString& name,
209 VALUETYPE& type) = 0;
212 * Enumerates through the subsections in a section.
214 * @param key Section key to iterate through.
215 * @param index Iteration position. Must be zero on the first call to
216 * iterate through @a key. Increment @a index by one on each
217 * successive call to this method.
218 * @param name Receives the subsection's name.
220 * @note You may not modify the @a key section while enumerating. If the
221 * section is modified during enumeration, results are undefined;
222 * you must restart the enumeration from index 0.
224 * @retval 0 for success, @a name has a valid name.
225 * @retval 1 there are no more subsections in the section.
226 * @retval -1 for error; ACE_OS::last_error() retrieves error code.
228 virtual int enumerate_sections (const ACE_Configuration_Section_Key& key,
229 int index, ACE_TString& name) = 0;
231 /// Sets a string-typed value.
233 * @param key Configuration section to set the value in.
234 * @param name Name of the configuration value to set. If a value with
235 * the specified name exists, it is replaced.
236 * @param value The string to set the configuration value to.
238 * @retval 0 for success.
239 * @retval -1 for error; ACE_OS::last_error() retrieves error code.
241 virtual int set_string_value (const ACE_Configuration_Section_Key& key,
242 const ACE_TCHAR* name,
243 const ACE_TString& value) = 0;
245 /// Sets a integer-typed value.
247 * @param key Configuration section to set the value in.
248 * @param name Name of the configuration value to set. If a value with
249 * the specified name exists, it is replaced.
250 * @param value The integer to set the configuration value to.
252 * @retval 0 for success.
253 * @retval -1 for error; ACE_OS::last_error() retrieves error code.
255 virtual int set_integer_value (const ACE_Configuration_Section_Key& key,
256 const ACE_TCHAR* name,
257 u_int value) = 0;
259 /// Sets a binary-typed value.
261 * @param key Configuration section to set the value in.
262 * @param name Name of the configuration value to set. If a value with
263 * the specified name exists, it is replaced.
264 * @param data Pointer to the binary data for the value.
265 * @param length Number of bytes for the new value.
267 * @retval 0 for success.
268 * @retval -1 for error; ACE_OS::last_error() retrieves error code.
270 virtual int set_binary_value (const ACE_Configuration_Section_Key& key,
271 const ACE_TCHAR* name,
272 const void* data,
273 size_t length) = 0;
275 /// Gets a string-typed value.
277 * @param key Configuration section to get the value from.
278 * @param name Name of the configuration value to get.
279 * @param value Receives the configuration value if it exists and
280 * has type STRING.
282 * @retval 0 for success.
283 * @retval -1 for error; ACE_OS::last_error() retrieves error code.
285 virtual int get_string_value (const ACE_Configuration_Section_Key& key,
286 const ACE_TCHAR* name,
287 ACE_TString& value) = 0;
289 /// Gets an integer-typed value.
291 * @param key Configuration section to get the value from.
292 * @param name Name of the configuration value to get.
293 * @param value Receives the configuration value if it exists and
294 * has type INTEGER.
296 * @retval 0 for success.
297 * @retval -1 for error; ACE_OS::last_error() retrieves error code.
299 virtual int get_integer_value (const ACE_Configuration_Section_Key& key,
300 const ACE_TCHAR* name,
301 u_int& value) = 0;
303 /// Gets a binary-typed value.
305 * @param key Configuration section to get the value from.
306 * @param name Name of the configuration value to get.
307 * @param data Receives a pointer to memory holding the binary data
308 * for the value. This method allocates the memory pointed
309 * to using operator new[]. The caller is responsible for
310 * freeing the memory using operator delete[].
311 * @param length Receives the number of bytes in the value.
313 * @retval 0 for success; caller is responsible for freeing the
314 * returned memory.
315 * @retval -1 for error; ACE_OS::last_error() retrieves error code.
317 virtual int get_binary_value (const ACE_Configuration_Section_Key& key,
318 const ACE_TCHAR* name,
319 void*& data,
320 size_t& length) = 0;
323 * Retrieves the type of a named configuration value.
325 * @param key Configuration section to look up the name in.
326 * @param name Name of the configuration value to get the type of.
327 * @param type Receives the data type of the named value, if it exists.
329 * @retval 0 for success.
330 * @retval -1 for error; ACE_OS::last_error() retrieves error code.
332 virtual int find_value(const ACE_Configuration_Section_Key& key,
333 const ACE_TCHAR* name,
334 VALUETYPE& type) = 0;
336 /// Removes a named value.
338 * @param key Configuration section to remove the named value from.
339 * @param name Name of the configuration value to remove.
341 * @retval 0 for success.
342 * @retval -1 for error; ACE_OS::last_error() retrieves error code.
344 virtual int remove_value (const ACE_Configuration_Section_Key& key,
345 const ACE_TCHAR* name) = 0;
348 * Expands @a path_in to @a key_out from @a key. If create is true,
349 * the subsections are created. Returns 0 on success, non zero on
350 * error The path consists of sections separated by the backslash
351 * '\' or forward slash '/'.
352 * Returns 0 on success, -1 if <create) is 0 and the path refers
353 * a nonexistant section
355 int expand_path (const ACE_Configuration_Section_Key& key,
356 const ACE_TString& path_in,
357 ACE_Configuration_Section_Key& key_out,
358 bool create = true);
361 * Determine if the contents of this object is the same as the
362 * contents of the object on the right hand side.
363 * Returns true if they are equal and false if they are not equal
365 bool operator==(const ACE_Configuration& rhs) const;
368 * Determine if the contents of this object are different from the
369 * contents of the object on the right hand side.
370 * Returns false if they are equal and true if they are not equal
372 bool operator!=(const ACE_Configuration& rhs) const;
375 * * Represents the "NULL" string to simplify the internal logic.
376 * */
377 static ACE_TCHAR NULL_String_;
379 protected:
380 /// Default ctor
381 ACE_Configuration (void);
383 /// Resolves the internal key from a section key
384 ACE_Section_Key_Internal* get_internal_key
385 (const ACE_Configuration_Section_Key& key);
388 * Tests to see if @a name is valid. @a name must be < 255 characters
389 * and not contain the path separator '\', brackets [] or = (maybe
390 * just restrict to alphanumeric?) returns non zero if name is not
391 * valid. The path separator is allowed, except for the first character,
392 * if @a allow_path is true.
394 int validate_name (const ACE_TCHAR* name, int allow_path = 0);
397 * Test to see if @a name is valid. The default value for a key can be
398 * unnamed, which means either @a name is == 0 or @a name == '\0` is
399 * valid. Otherwise, it calls validate_name() to test @a name for the
400 * same rules that apply to keys.
402 int validate_value_name (const ACE_TCHAR* name);
404 // Not used
405 ACE_Configuration (const ACE_Configuration& rhs);
406 ACE_Configuration& operator= (const ACE_Configuration& rhs);
409 ACE_Configuration_Section_Key root_;
412 #if defined (ACE_WIN32) && !defined (ACE_LACKS_WIN32_REGISTRY)
415 * @class ACE_Section_Key_Win32
417 * @brief The Win32 registry implementation of an internal section key.
419 * Holds the HKEY for a section (registry key).
421 class ACE_Export ACE_Section_Key_Win32 : public ACE_Section_Key_Internal
423 public:
424 /// Constructor based on an HKEY
425 ACE_Section_Key_Win32 (HKEY hKey);
427 HKEY hKey_;
429 protected:
430 /// Destructor - invokes <RegCloseKey>
431 virtual ~ACE_Section_Key_Win32 (void);
433 // Not used
434 ACE_Section_Key_Win32 (const ACE_Section_Key_Win32& rhs);
435 ACE_Section_Key_Win32& operator= (const ACE_Section_Key_Win32& rhs);
439 * @class ACE_Configuration_Win32Registry
441 * @brief The win32 registry implementation of a configuration database
443 * The win32 implementation basically makes calls through to the
444 * registry functions. The API is very similar so very little
445 * work must be done
447 class ACE_Export ACE_Configuration_Win32Registry : public ACE_Configuration
449 public:
451 * Constructor for registry configuration database. hKey is the
452 * base registry key to attach to. This class takes ownership of
453 * hKey, it will invoke <RegCloseKey> on it upon destruction.
455 explicit ACE_Configuration_Win32Registry (HKEY hKey,
456 u_long security_access = KEY_ALL_ACCESS);
458 /// Destructor
459 virtual ~ACE_Configuration_Win32Registry (void);
461 virtual int open_section (const ACE_Configuration_Section_Key& base,
462 const ACE_TCHAR* sub_section,
463 bool create,
464 ACE_Configuration_Section_Key& result);
466 virtual int remove_section (const ACE_Configuration_Section_Key& key,
467 const ACE_TCHAR* sub_section,
468 bool recursive);
470 virtual int enumerate_values (const ACE_Configuration_Section_Key& key,
471 int index,
472 ACE_TString& name,
473 VALUETYPE& type);
475 virtual int enumerate_sections (const ACE_Configuration_Section_Key& key,
476 int index,
477 ACE_TString& name);
479 virtual int set_string_value (const ACE_Configuration_Section_Key& key,
480 const ACE_TCHAR* name,
481 const ACE_TString& value);
483 virtual int set_integer_value (const ACE_Configuration_Section_Key& key,
484 const ACE_TCHAR* name,
485 u_int value);
487 virtual int set_binary_value (const ACE_Configuration_Section_Key& key,
488 const ACE_TCHAR* name,
489 const void* data,
490 size_t length);
492 virtual int get_string_value (const ACE_Configuration_Section_Key& key,
493 const ACE_TCHAR* name,
494 ACE_TString& value);
496 virtual int get_integer_value (const ACE_Configuration_Section_Key& key,
497 const ACE_TCHAR* name,
498 u_int& value);
500 virtual int get_binary_value (const ACE_Configuration_Section_Key& key,
501 const ACE_TCHAR* name,
502 void*& data,
503 size_t& length);
505 virtual int find_value(const ACE_Configuration_Section_Key& key,
506 const ACE_TCHAR* name,
507 VALUETYPE& type);
509 /// Removes the the value @a name from @a key. returns non zero on error
510 virtual int remove_value (const ACE_Configuration_Section_Key& key,
511 const ACE_TCHAR* name);
514 * This method traverses <path> through <hKey>. It is useful when
515 * you want the HKEY for a specific registry key, especially when
516 * initializing this implementation. Caller is responsible for
517 * closeing this key when it is no longer used. If create is 1
518 * (default) the keys are create if they don't already exist.
519 * Returns 0 on error
521 static HKEY resolve_key (HKEY hKey,
522 const ACE_TCHAR* path,
523 bool create = true,
524 u_long security_access = KEY_ALL_ACCESS);
525 virtual bool operator== (const ACE_Configuration_Win32Registry &rhs) const;
526 virtual bool operator!= (const ACE_Configuration_Win32Registry &rhs) const;
528 protected:
530 /// Gets the HKEY for a configuration section
531 int load_key (const ACE_Configuration_Section_Key& key, HKEY& hKey);
533 // Not used
534 ACE_Configuration_Win32Registry (void);
535 ACE_Configuration_Win32Registry (const ACE_Configuration_Win32Registry& rhs);
536 ACE_Configuration_Win32Registry& operator= (const ACE_Configuration_Win32Registry& rhs);
538 const u_long security_access_;
540 #endif /* ACE_WIN32 && !ACE_LACKS_WIN32_REGISTRY */
542 // ACE_Allocator version
544 typedef ACE_Allocator_Adapter <ACE_Malloc <ACE_MMAP_MEMORY_POOL,
545 ACE_SYNCH_MUTEX> >
546 PERSISTENT_ALLOCATOR;
547 typedef ACE_Allocator_Adapter <ACE_Malloc <ACE_LOCAL_MEMORY_POOL,
548 ACE_SYNCH_MUTEX> >
549 HEAP_ALLOCATOR;
552 * @class ACE_Configuration_ExtId
554 * @brief External ID for the section and value hash
556 * Contains a pointer to the section or value name.
558 class ACE_Export ACE_Configuration_ExtId
560 public:
561 /// Defeault ctor
562 ACE_Configuration_ExtId (void);
564 /// Named constructor
565 explicit ACE_Configuration_ExtId (const ACE_TCHAR* name);
567 /// Copy ctor
568 ACE_Configuration_ExtId (const ACE_Configuration_ExtId& rhs);
570 /// destructor
571 ~ACE_Configuration_ExtId (void);
573 /// Assignment operator
574 ACE_Configuration_ExtId& operator= (const ACE_Configuration_ExtId& rhs);
576 /// Equality comparison operator (must match name_).
577 bool operator== (const ACE_Configuration_ExtId &rhs) const;
579 /// Inequality comparison operator.
580 bool operator!= (const ACE_Configuration_ExtId &rhs) const;
582 /// Frees the name of the value. needed since we don't know the
583 /// allocator name_ was created in
584 void free (ACE_Allocator *alloc);
586 /// hash function is required in order for this class to be usable by
587 /// ACE_Hash_Map_Manager.
588 u_long hash (void) const;
590 // = Data members.
592 const ACE_TCHAR * name_;
594 // Accessors
595 const ACE_TCHAR *name (void);
598 typedef ACE_Hash_Map_With_Allocator<ACE_Configuration_ExtId, int>
599 SUBSECTION_MAP;
600 typedef ACE_Hash_Map_Manager_Ex<ACE_Configuration_ExtId,
601 int,
602 ACE_Hash<ACE_Configuration_ExtId>,
603 ACE_Equal_To<ACE_Configuration_ExtId>,
604 ACE_Null_Mutex>
605 SUBSECTION_HASH;
608 * @class ACE_Configuration_Value_IntId
610 * @brief The section hash table internal value class
612 * This class is present as the internal portion of a section's
613 * value hash table It may store string, integer or binary data.
615 class ACE_Export ACE_Configuration_Value_IntId
617 public:
618 /// Default constructor
619 ACE_Configuration_Value_IntId (void);
621 /// String constructor, takes ownership of string
622 explicit ACE_Configuration_Value_IntId (ACE_TCHAR* string);
624 /// Integer constructor
625 explicit ACE_Configuration_Value_IntId (u_int integer);
627 /// Binary constructor, takes ownership of data
628 ACE_Configuration_Value_IntId (void* data, size_t length);
630 /// Copy ctor
631 ACE_Configuration_Value_IntId (const ACE_Configuration_Value_IntId& rhs);
633 /// Destructor
634 ~ACE_Configuration_Value_IntId (void);
636 /// Assignment operator
637 ACE_Configuration_Value_IntId& operator= (
638 const ACE_Configuration_Value_IntId& rhs);
640 void free (ACE_Allocator *alloc);
642 // = Data members.
645 * Points to the string value or binary data or IS the integer
646 * Length is only used when type_ == BINARY
648 ACE_Configuration::VALUETYPE type_;
649 union {
650 void * ptr_;
651 u_int int_;
652 } data_;
653 size_t length_;
656 typedef ACE_Hash_Map_With_Allocator<ACE_Configuration_ExtId,
657 ACE_Configuration_Value_IntId>
658 VALUE_MAP;
659 typedef ACE_Hash_Map_Manager_Ex<ACE_Configuration_ExtId,
660 ACE_Configuration_Value_IntId,
661 ACE_Hash<ACE_Configuration_ExtId>,
662 ACE_Equal_To<ACE_Configuration_ExtId>,
663 ACE_Null_Mutex>
664 VALUE_HASH;
666 // Deprecated typedef. Use the VALUE_HASH::ENTRY trait instead.
667 typedef VALUE_HASH::ENTRY VALUE_ENTRY;
670 * @class ACE_Configuration_Section_IntId
672 * @brief The internal ID for a section hash table
674 * Contains a hash table containing value name/values
676 class ACE_Export ACE_Configuration_Section_IntId
678 public:
679 /// Default ctor
680 ACE_Configuration_Section_IntId (void);
682 /// Named ctor
683 ACE_Configuration_Section_IntId (VALUE_MAP* value_hash_map,
684 SUBSECTION_MAP* section_hash_map);
686 /// Copy ctor
687 ACE_Configuration_Section_IntId (const ACE_Configuration_Section_IntId& rhs);
689 /// Destructor
690 ~ACE_Configuration_Section_IntId (void);
692 /// Assignment operator
693 ACE_Configuration_Section_IntId& operator= (
694 const ACE_Configuration_Section_IntId& rhs);
696 /// Frees the hash table and all its values
697 void free (ACE_Allocator *alloc);
699 // = Data Members.
700 VALUE_MAP* value_hash_map_;
702 SUBSECTION_MAP* section_hash_map_;
705 typedef ACE_Hash_Map_With_Allocator<ACE_Configuration_ExtId,
706 ACE_Configuration_Section_IntId>
707 SECTION_MAP;
708 typedef ACE_Hash_Map_Manager_Ex<ACE_Configuration_ExtId,
709 ACE_Configuration_Section_IntId,
710 ACE_Hash<ACE_Configuration_ExtId>,
711 ACE_Equal_To<ACE_Configuration_ExtId>,
712 ACE_Null_Mutex>
713 SECTION_HASH;
715 // Deprecated typedef. Use the SECTION_HASH::ENTRY trait instead.
716 typedef SECTION_HASH::ENTRY SECTION_ENTRY;
719 * @class ACE_Configuration_Section_Key_Heap
721 * @brief Internal section key class for heap based configuration
722 * database.
724 * Contains a value iterator and full path name of section.
726 class ACE_Export ACE_Configuration_Section_Key_Heap
727 : public ACE_Section_Key_Internal
729 public:
730 /// Constructor based on the full path of the section
731 ACE_Configuration_Section_Key_Heap (const ACE_TCHAR* path);
733 /// The path itself
734 ACE_TCHAR* path_;
736 /// The value iterator
737 VALUE_HASH::ITERATOR* value_iter_;
739 /// The sub section iterator
740 SUBSECTION_HASH::ITERATOR* section_iter_;
742 ACE_ALLOC_HOOK_DECLARE;
744 protected:
745 /// Destructor - will delete the iterators
746 virtual ~ACE_Configuration_Section_Key_Heap (void);
748 // Not used
749 ACE_Configuration_Section_Key_Heap (const ACE_Configuration_Section_Key_Heap& rhs);
750 ACE_Configuration_Section_Key_Heap& operator= (const ACE_Configuration_Section_Key_Heap& rhs);
754 * @class ACE_Configuration_Heap
756 * @brief The concrete implementation of a allocator based
757 * configuration database
759 * This class uses ACE's Allocators to manage a memory
760 * representation of a configuration database. A persistent heap
761 * may be used to store configurations persistently
763 * @note Before using this class you must call one of the open methods.
765 * @todo
766 * - Need to investigate what happens if memory mapped file gets mapped to
767 * a location different than it was created with.
769 class ACE_Export ACE_Configuration_Heap : public ACE_Configuration
771 public:
772 /// Default ctor
773 ACE_Configuration_Heap (void);
775 /// Destructor
776 virtual ~ACE_Configuration_Heap (void);
779 * Opens a configuration that allocates its memory from a memory-mapped file.
780 * This makes it possible to persist a configuration to permanent storage.
781 * This is not the same as exporting the configuration to a file; the
782 * memory-mapped file is not likely to be very readable by humans.
784 * @param file_name Name of the file to map into memory.
786 * @param base_address Address to map the base of @a file_name to.
788 * @param default_map_size Starting size for the internal hash tables that
789 * contain configuration information.
791 * @retval 0 for success.
792 * @retval -1 for error, with errno set to indicate the cause. If open()
793 * is called multiple times, errno will be @c EBUSY.
795 int open (const ACE_TCHAR* file_name,
796 void* base_address = ACE_DEFAULT_BASE_ADDR,
797 size_t default_map_size = ACE_DEFAULT_CONFIG_SECTION_SIZE);
800 * Opens a configuration that allocates memory from the heap.
802 * @param default_map_size Starting size for the internal hash tables that
803 * contain configuration information.
805 * @retval 0 for success.
806 * @retval -1 for error, with errno set to indicate the cause. If open()
807 * is called multiple times, errno will be @c EBUSY.
809 int open (size_t default_map_size = ACE_DEFAULT_CONFIG_SECTION_SIZE);
811 virtual int open_section (const ACE_Configuration_Section_Key& base,
812 const ACE_TCHAR* sub_section,
813 bool create, ACE_Configuration_Section_Key& result);
815 virtual int remove_section (const ACE_Configuration_Section_Key& key,
816 const ACE_TCHAR* sub_section,
817 bool recursive);
819 virtual int enumerate_values (const ACE_Configuration_Section_Key& key,
820 int index,
821 ACE_TString& name,
822 VALUETYPE& type);
824 virtual int enumerate_sections (const ACE_Configuration_Section_Key& key,
825 int index,
826 ACE_TString& name);
828 virtual int set_string_value (const ACE_Configuration_Section_Key& key,
829 const ACE_TCHAR* name,
830 const ACE_TString& value);
832 virtual int set_integer_value (const ACE_Configuration_Section_Key& key,
833 const ACE_TCHAR* name,
834 u_int value);
836 virtual int set_binary_value (const ACE_Configuration_Section_Key& key,
837 const ACE_TCHAR* name,
838 const void* data,
839 size_t length);
841 virtual int get_string_value (const ACE_Configuration_Section_Key& key,
842 const ACE_TCHAR* name,
843 ACE_TString& value);
845 virtual int get_integer_value (const ACE_Configuration_Section_Key& key,
846 const ACE_TCHAR* name,
847 u_int& value);
849 virtual int get_binary_value (const ACE_Configuration_Section_Key& key,
850 const ACE_TCHAR* name,
851 void* &data,
852 size_t &length);
854 virtual int find_value(const ACE_Configuration_Section_Key& key,
855 const ACE_TCHAR* name,
856 VALUETYPE& type);
858 /// Removes the the value @a name from @a key. returns non zero on error
859 virtual int remove_value (const ACE_Configuration_Section_Key& key,
860 const ACE_TCHAR* name);
862 private:
863 /// @a sub_section may not contain path separators
864 int open_simple_section (const ACE_Configuration_Section_Key &base,
865 const ACE_TCHAR *sub_section,
866 bool create, ACE_Configuration_Section_Key &result);
867 /// Adds a new section
868 int add_section (const ACE_Configuration_Section_Key &base,
869 const ACE_TCHAR *sub_section,
870 ACE_Configuration_Section_Key &result);
872 /// Helper for the <open> method.
873 int create_index (void);
875 /// Helper for create_index() method: places hash table into an
876 /// allocated space.
877 int create_index_helper (void *buffer);
879 int value_open_helper (size_t hash_table_size, void *buffer);
881 int section_open_helper (size_t hash_table_size, void *buffer);
883 int load_key (const ACE_Configuration_Section_Key& key, ACE_TString& name);
885 int new_section (const ACE_TString& section,
886 ACE_Configuration_Section_Key& result);
888 ACE_Configuration_Heap (const ACE_Configuration_Heap& rhs);
889 ACE_Configuration_Heap& operator= (const ACE_Configuration_Heap& rhs);
891 ACE_Allocator *allocator_;
892 SECTION_MAP *index_;
893 size_t default_map_size_;
896 ACE_END_VERSIONED_NAMESPACE_DECL
898 #if defined (__ACE_INLINE__)
899 #include "ace/Configuration.inl"
900 #endif /* __ACE_INLINE__ */
902 #include /**/ "ace/post.h"
903 #endif /* ACE_CONFIGURATION_H */