Configuration.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Configuration.h
00006  *
00007  *  Configuration.h,v 4.58 2006/03/27 09:31:06 smcqueen Exp
00008  *
00009  *  @author Chris Hafey <chafey@stentor.com>
00010  *
00011  *  The ACE configuration API provides a portable abstraction for
00012  *  program configuration similar to the Microsoft Windows registry.
00013  *  The API supports a tree based hierarchy of configuration sections.  Each
00014  *  section contains other sections or values.  Values may contain string,
00015  *  unsigned integer and binary data.
00016  *
00017  *  @note These classes are not thread safe, if multiple threads use these
00018  *  classes, you are responsible for serializing access.
00019  *
00020  *  For examples of using this class, see:
00021  *   -# The test code in ACE_wrappers/test
00022  *   -# wxConfigViewer, a Windows like Registry Editor for ACE_Configuration
00023  *   -# TAO's IFR, it makes extensive use of ACE_Configuration
00024  *
00025  *  @todo Templatize this class with an ACE_LOCK to provide thread safety
00026  *
00027  */
00028 //=============================================================================
00029 
00030 #ifndef ACE_CONFIGURATION_H
00031 #define ACE_CONFIGURATION_H
00032 #include /**/ "ace/pre.h"
00033 
00034 #include "ace/SStringfwd.h"
00035 #include "ace/Hash_Map_With_Allocator_T.h"
00036 #include "ace/Malloc_T.h"
00037 #include "ace/MMAP_Memory_Pool.h"
00038 #include "ace/Local_Memory_Pool.h"
00039 #include "ace/Synch_Traits.h"
00040 
00041 
00042 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00043 # pragma once
00044 #endif /* ACE_LACKS_PRAGMA_ONCE */
00045 
00046 // configurable parameters
00047 
00048 #if !defined (ACE_CONFIG_SECTION_INDEX)
00049 #  define ACE_CONFIG_SECTION_INDEX "Config_Section_Index"
00050 #endif /* ! ACE_CONFIG_SECTION_INDEX */
00051 
00052 #if !defined (ACE_DEFAULT_CONFIG_SECTION_SIZE)
00053 #define ACE_DEFAULT_CONFIG_SECTION_SIZE 16
00054 #endif /* ACE_DEFAULT_CONFIG_SECTION_SIZE */
00055 
00056 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00057 
00058 /**
00059  * @class ACE_Section_Key_Internal
00060  *
00061  * @internal
00062  *
00063  * @brief A base class for internal handles to section keys for
00064  * configuration implementations
00065  *
00066  * Implementations subclass this base class to represent a
00067  * section key.
00068  *
00069  */
00070 class ACE_Export ACE_Section_Key_Internal
00071 {
00072 public:
00073   /// Virtual destructor, make sure descendants are virtual!
00074   virtual ~ACE_Section_Key_Internal (void);
00075 
00076   /// Increment reference count
00077   virtual int add_ref (void);
00078 
00079   /// Decrement reference count.  Will delete this if count gets to 0
00080   virtual int dec_ref (void);
00081 protected:
00082   ACE_Section_Key_Internal (void);
00083   ACE_Section_Key_Internal (const ACE_Section_Key_Internal& rhs);
00084   ACE_Section_Key_Internal& operator= (ACE_Section_Key_Internal& rhs);
00085 
00086   u_int ref_count_;
00087 };
00088 
00089 /**
00090  * @class ACE_Configuration_Section_Key
00091  *
00092  * @brief Reference counted wrapper for ACE_Section_Key_Internal.
00093  *
00094  * Reference counted wrapper class for the abstract internal
00095  * section key.  A user gets one of these to represent a section
00096  * in the configuration database.
00097  */
00098 class ACE_Export ACE_Configuration_Section_Key
00099 {
00100   friend class ACE_Configuration;
00101 public:
00102   /// Default constructor.
00103   ACE_Configuration_Section_Key (void);
00104 
00105   /// Constructor that initializes to a pointer to a concrete internal key.
00106   /**
00107    * @param key The section key to reference. Calls add_ref() with @a key.
00108    */
00109   explicit ACE_Configuration_Section_Key (ACE_Section_Key_Internal *key);
00110 
00111   /// Copy constructor, increments the reference count on the key.
00112   ACE_Configuration_Section_Key (const ACE_Configuration_Section_Key &rhs);
00113 
00114   /// Destructor, decrements reference count on the referenced key.
00115   ~ACE_Configuration_Section_Key (void);
00116 
00117   /// Assignment operator, increments reference count for this object
00118   /// and decrements it on @a rhs.
00119   ACE_Configuration_Section_Key &
00120     operator= (const ACE_Configuration_Section_Key &rhs);
00121 private:
00122   ACE_Section_Key_Internal *key_;
00123 };
00124 
00125 /**
00126  * @class ACE_Configuration
00127  *
00128  * @internal
00129  *
00130  * @brief Base class for configuration databases
00131  *
00132  * This class provides an interface for configuration databases. A concrete
00133  * class is required that implements the interface.
00134  *
00135  * @sa ACE_Configuration_Heap
00136  * @sa ACE_Configuration_Win32Registry
00137  */
00138 class ACE_Export ACE_Configuration
00139 {
00140 public:
00141   /// Enumeration for the various types of values we can store.
00142   enum VALUETYPE
00143   {
00144     STRING,
00145     INTEGER,
00146     BINARY,
00147     INVALID
00148   };
00149 
00150   /// Destructor
00151   virtual ~ACE_Configuration (void);
00152 
00153   /// Obtain a reference to the root section of this configuration.
00154   /*
00155    * @return Reference to the configuration's root section. Note that
00156    *         it is a const reference.
00157    */
00158   virtual const ACE_Configuration_Section_Key& root_section (void) const;
00159 
00160   /**
00161    * Opens a named section in an existing section.
00162    *
00163    * @param base        Existing section in which to open the named section.
00164    * @param sub_section Name of the section to open.
00165    * @param create      If zero, the named section must exist. If non-zero,
00166    *                    the named section will be created if it does not exist.
00167    * @param result      Reference; receives the section key for the new
00168    *                    section.
00169    *
00170    * @retval   0 for success.
00171    * @retval  -1 for error; ACE_OS::last_error() retrieves error code.
00172    */
00173   virtual int open_section (const ACE_Configuration_Section_Key &base,
00174                             const ACE_TCHAR *sub_section,
00175                             int create,
00176                             ACE_Configuration_Section_Key& result) = 0;
00177 
00178   /// Removes a named section.
00179   /**
00180    * @param key          Section key to remove the named section from.
00181    * @param sub_section  Name of the section to remove.
00182    * @param recursive    If non zero, any subkeys below @a sub_section are
00183    *                     removed as well.
00184    *
00185    * @retval   0 for success.
00186    * @retval  -1 for error; ACE_OS::last_error() retrieves error code.
00187    */
00188   virtual int remove_section (const ACE_Configuration_Section_Key &key,
00189                               const ACE_TCHAR *sub_section,
00190                               int recursive) = 0;
00191 
00192   /**
00193    * Enumerates through the values in a section.
00194    *
00195    * @param key    Section key to iterate through.
00196    * @param index  Iteration position. Must be zero on the first call to
00197    *               iterate through @a key. Increment @a index by one on each
00198    *               successive call to this method.
00199    * @param name   Receives the value's name.
00200    * @param type   Receives the value's data type.
00201    *
00202    * @note  You may not delete or add values while enumerating.  If the
00203    *        section is modified during enumeration, results are undefined;
00204    *        you must restart the enumeration from index 0.
00205    *
00206    * @retval   0 for success, @a name and @a type are valid.
00207    * @retval   1 there are no more values in the section.
00208    * @retval  -1 for error; ACE_OS::last_error() retrieves error code.
00209    */
00210   virtual int enumerate_values (const ACE_Configuration_Section_Key& key,
00211                                 int index,
00212                                 ACE_TString& name,
00213                                 VALUETYPE& type) = 0;
00214 
00215   /**
00216    * Enumerates through the subsections in a section.
00217    *
00218    * @param key    Section key to iterate through.
00219    * @param index  Iteration position. Must be zero on the first call to
00220    *               iterate through @a key. Increment @a index by one on each
00221    *               successive call to this method.
00222    * @param name   Receives the subsection's name.
00223    *
00224    * @note  You may not modify the @a key section while enumerating.  If the
00225    *        section is modified during enumeration, results are undefined;
00226    *        you must restart the enumeration from index 0.
00227    *
00228    * @retval   0 for success, @a name has a valid name.
00229    * @retval   1 there are no more subsections in the section.
00230    * @retval  -1 for error; ACE_OS::last_error() retrieves error code.
00231    */
00232   virtual int enumerate_sections (const ACE_Configuration_Section_Key& key,
00233                                   int index, ACE_TString& name) = 0;
00234 
00235   /// Sets a string-typed value.
00236   /**
00237    * @param key     Configuration section to set the value in.
00238    * @param name    Name of the configuration value to set. If a value with
00239    *                the specified name exists, it is replaced.
00240    * @param value   The string to set the configuration value to.
00241    *
00242    * @retval   0 for success.
00243    * @retval  -1 for error; ACE_OS::last_error() retrieves error code.
00244    */
00245   virtual int set_string_value (const ACE_Configuration_Section_Key& key,
00246                                 const ACE_TCHAR* name,
00247                                 const ACE_TString& value) = 0;
00248 
00249   /// Sets a integer-typed value.
00250   /**
00251    * @param key     Configuration section to set the value in.
00252    * @param name    Name of the configuration value to set. If a value with
00253    *                the specified name exists, it is replaced.
00254    * @param value   The integer to set the configuration value to.
00255    *
00256    * @retval   0 for success.
00257    * @retval  -1 for error; ACE_OS::last_error() retrieves error code.
00258    */
00259   virtual int set_integer_value (const ACE_Configuration_Section_Key& key,
00260                                  const ACE_TCHAR* name,
00261                                  u_int value) = 0;
00262 
00263   /// Sets a binary-typed value.
00264   /**
00265    * @param key     Configuration section to set the value in.
00266    * @param name    Name of the configuration value to set. If a value with
00267    *                the specified name exists, it is replaced.
00268    * @param data    Pointer to the binary data for the value.
00269    * @param length  Number of bytes for the new value.
00270    *
00271    * @retval   0 for success.
00272    * @retval  -1 for error; ACE_OS::last_error() retrieves error code.
00273    */
00274   virtual int set_binary_value (const ACE_Configuration_Section_Key& key,
00275                                 const ACE_TCHAR* name,
00276                                 const void* data,
00277                                 size_t length) = 0;
00278 
00279   /// Gets a string-typed value.
00280   /**
00281    * @param key     Configuration section to get the value from.
00282    * @param name    Name of the configuration value to get.
00283    * @param value   Receives the configuration value if it exists and
00284    *                has type STRING.
00285    *
00286    * @retval   0 for success.
00287    * @retval  -1 for error; ACE_OS::last_error() retrieves error code.
00288    */
00289   virtual int get_string_value (const ACE_Configuration_Section_Key& key,
00290                                 const ACE_TCHAR* name,
00291                                 ACE_TString& value) = 0;
00292 
00293   /// Gets an integer-typed value.
00294   /**
00295    * @param key     Configuration section to get the value from.
00296    * @param name    Name of the configuration value to get.
00297    * @param value   Receives the configuration value if it exists and
00298    *                has type INTEGER.
00299    *
00300    * @retval   0 for success.
00301    * @retval  -1 for error; ACE_OS::last_error() retrieves error code.
00302    */
00303   virtual int get_integer_value (const ACE_Configuration_Section_Key& key,
00304                                  const ACE_TCHAR* name,
00305                                  u_int& value) = 0;
00306 
00307   /// Gets a binary-typed value.
00308   /**
00309    * @param key     Configuration section to get the value from.
00310    * @param name    Name of the configuration value to get.
00311    * @param data    Receives a pointer to memory holding the binary data
00312    *                for the value. This method allocates the memory pointed
00313    *                to using operator new[]. The caller is responsible for
00314    *                freeing the memory using operator delete[].
00315    * @param length  Receives the number of bytes in the value.
00316    *
00317    * @retval   0 for success; caller is responsible for freeing the
00318    *             returned memory.
00319    * @retval  -1 for error; ACE_OS::last_error() retrieves error code.
00320    */
00321   virtual int get_binary_value (const ACE_Configuration_Section_Key& key,
00322                                 const ACE_TCHAR* name,
00323                                 void*& data,
00324                                 size_t& length) = 0;
00325 
00326   /**
00327    * Retrieves the type of a named configuration value.
00328    *
00329    * @param key     Configuration section to look up the name in.
00330    * @param name    Name of the configuration value to get the type of.
00331    * @param type    Receives the data type of the named value, if it exists.
00332    *
00333    * @retval   0 for success.
00334    * @retval  -1 for error; ACE_OS::last_error() retrieves error code.
00335    */
00336   virtual int find_value(const ACE_Configuration_Section_Key& key,
00337                          const ACE_TCHAR* name,
00338                          VALUETYPE& type) = 0;
00339 
00340   /// Removes a named value.
00341   /**
00342    * @param key     Configuration section to remove the named value from.
00343    * @param name    Name of the configuration value to remove.
00344    *
00345    * @retval   0 for success.
00346    * @retval  -1 for error; ACE_OS::last_error() retrieves error code.
00347    */
00348   virtual int remove_value (const ACE_Configuration_Section_Key& key,
00349                             const ACE_TCHAR* name) = 0;
00350 
00351   /**
00352    * Expands <path_in> to <key_out> from <key>.  If create is true,
00353    * the subsections are created.  Returns 0 on success, non zero on
00354    * error The path consists of sections separated by the backslash
00355    * '\' or forward slash '/'.
00356    * Returns 0 on success, -1 if <create) is 0 and the path refers
00357    * a nonexistant section
00358    */
00359   int expand_path (const ACE_Configuration_Section_Key& key,
00360                    const ACE_TString& path_in,
00361                    ACE_Configuration_Section_Key& key_out,
00362                    int create = 1);
00363 
00364   /**
00365    * @deprecated Exports the configuration database to filename.
00366    * If @a filename is already present, it is overwritten. This function is
00367    * deprecated and will be removed in a future version of ACE. Please use
00368    * either ACE_Registry_ImpExp or ACE_Ini_ImpExp instead.
00369    */
00370   int export_config (const ACE_TCHAR* filename);
00371 
00372   /**
00373    * @deprecated Imports the configuration database from filename.  Any
00374    * existing data is not removed. This function is deprecated and will be
00375    * removed in a future version of ACE. Please use ACE_Registry_ImpExp
00376    * or ACE_Ini_ImpExp instead.
00377    */
00378   int import_config (const ACE_TCHAR* filename);
00379 
00380   /**
00381    * Determine if the contents of this object is the same as the
00382    * contents of the object on the right hand side.
00383    * Returns 1 (True) if they are equal and 0 (False) if they are not equal
00384    */
00385   bool operator==(const ACE_Configuration& rhs) const;
00386 
00387   /**
00388    * Determine if the contents of this object are different from the
00389    * contents of the object on the right hand side.
00390    * Returns 0 (False) if they are equal and 1 (True) if they are not equal
00391    */
00392   bool operator!=(const ACE_Configuration& rhs) const;
00393 
00394   /**
00395    *    *  Represents the "NULL" string to simplify the internal logic.
00396    *       */
00397   static ACE_TCHAR NULL_String_;
00398 
00399 protected:
00400   /// Default ctor
00401   ACE_Configuration (void);
00402 
00403   /// Resolves the internal key from a section key
00404   ACE_Section_Key_Internal* get_internal_key
00405     (const ACE_Configuration_Section_Key& key);
00406 
00407   /**
00408    * Tests to see if <name> is valid.  <name> must be < 255 characters
00409    * and not contain the path separator '\', brackets [] or = (maybe
00410    * just restrict to alphanumeric?) returns non zero if name is not
00411    * valid.  The path separator is allowed, except for the first character,
00412    * if <allow_path> is true.
00413    */
00414   int validate_name (const ACE_TCHAR* name, int allow_path = 0);
00415 
00416   /**
00417    * Test to see if <name> is valid.  The default value for a key can be
00418    * unnamed, which means either <name> is == 0 or <name> == '\0` is
00419    * valid.  Otherwise, it calls validate_name() to test <name> for the
00420    * same rules that apply to keys.
00421    */
00422   int validate_value_name (const ACE_TCHAR* name);
00423 
00424   // Not used
00425   ACE_Configuration (const ACE_Configuration& rhs);
00426   ACE_Configuration& operator= (const ACE_Configuration& rhs);
00427 
00428 
00429   ACE_Configuration_Section_Key root_;
00430 };
00431 
00432 #if defined (ACE_WIN32)
00433 
00434 /**
00435  * @class ACE_Section_Key_Win32
00436  *
00437  * @brief The Win32 registry implementation of an internal section key.
00438  *
00439  * Holds the HKEY for a section (registry key).
00440  */
00441 class ACE_Export ACE_Section_Key_Win32 : public ACE_Section_Key_Internal
00442 {
00443 public:
00444   /// Constructor based on an HKEY
00445   ACE_Section_Key_Win32 (HKEY hKey);
00446 
00447   HKEY hKey_;
00448 
00449 protected:
00450   /// Destructor - invokes <RegCloseKey>
00451   virtual ~ACE_Section_Key_Win32 (void);
00452 
00453   // Not used
00454   ACE_Section_Key_Win32 (const ACE_Section_Key_Win32& rhs);
00455   ACE_Section_Key_Win32& operator= (const ACE_Section_Key_Win32& rhs);
00456 };
00457 
00458 /**
00459  * @class ACE_Configuration_Win32Registry
00460  *
00461  * @brief The win32 registry implementation of a configuration database
00462  *
00463  * The win32 implementation basically makes calls through to the
00464  * registry functions. The API is very similar so very little
00465  * work must be done
00466  */
00467 class ACE_Export ACE_Configuration_Win32Registry : public ACE_Configuration
00468 {
00469 public:
00470 
00471   /**
00472    * Constructor for registry configuration database.  hKey is the
00473    * base registry key to attach to.  This class takes ownership of
00474    * hKey, it will invoke <RegCloseKey> on it upon destruction.
00475    */
00476   explicit ACE_Configuration_Win32Registry (HKEY hKey);
00477 
00478   /// Destructor
00479   virtual ~ACE_Configuration_Win32Registry (void);
00480 
00481   virtual int open_section (const ACE_Configuration_Section_Key& base,
00482                             const ACE_TCHAR* sub_section,
00483                             int create,
00484                             ACE_Configuration_Section_Key& result);
00485 
00486   virtual int remove_section (const ACE_Configuration_Section_Key& key,
00487                               const ACE_TCHAR* sub_section,
00488                               int recursive);
00489 
00490   virtual int enumerate_values (const ACE_Configuration_Section_Key& key,
00491                                 int index,
00492                                 ACE_TString& name,
00493                                 VALUETYPE& type);
00494 
00495   virtual int enumerate_sections (const ACE_Configuration_Section_Key& key,
00496                                   int index,
00497                                   ACE_TString& name);
00498 
00499   virtual int set_string_value (const ACE_Configuration_Section_Key& key,
00500                                 const ACE_TCHAR* name,
00501                                 const ACE_TString& value);
00502 
00503   virtual int set_integer_value (const ACE_Configuration_Section_Key& key,
00504                                  const ACE_TCHAR* name,
00505                                  u_int value);
00506 
00507   virtual int set_binary_value (const ACE_Configuration_Section_Key& key,
00508                                 const ACE_TCHAR* name,
00509                                 const void* data,
00510                                 size_t length);
00511 
00512   virtual int get_string_value (const ACE_Configuration_Section_Key& key,
00513                                 const ACE_TCHAR* name,
00514                                 ACE_TString& value);
00515 
00516   virtual int get_integer_value (const ACE_Configuration_Section_Key& key,
00517                                  const ACE_TCHAR* name,
00518                                  u_int& value);
00519 
00520   virtual int get_binary_value (const ACE_Configuration_Section_Key& key,
00521                                 const ACE_TCHAR* name,
00522                                 void*& data,
00523                                 size_t& length);
00524 
00525   virtual int find_value(const ACE_Configuration_Section_Key& key,
00526                          const ACE_TCHAR* name,
00527                          VALUETYPE& type);
00528 
00529   /// Removes the the value @a name from @a key.  returns non zero on error
00530   virtual int remove_value (const ACE_Configuration_Section_Key& key,
00531                             const ACE_TCHAR* name);
00532 
00533   /**
00534    * This method traverses <path> through <hKey>.  It is useful when
00535    * you want the HKEY for a specific registry key, especially when
00536    * initializing this implementation.  Caller is responsible for
00537    * closeing this key when it is no longer used.  If create is 1
00538    * (default) the keys are create if they don't already exist.
00539    * Returns 0 on error
00540    */
00541   static HKEY resolve_key (HKEY hKey,
00542                            const ACE_TCHAR* path,
00543                            int create = 1);
00544   virtual bool operator== (const ACE_Configuration_Win32Registry &rhs) const;
00545   virtual bool operator!= (const ACE_Configuration_Win32Registry &rhs) const;
00546 
00547 protected:
00548 
00549   /// Gets the HKEY for a configuration section
00550   int load_key (const ACE_Configuration_Section_Key& key, HKEY& hKey);
00551 
00552   // Not used
00553   ACE_Configuration_Win32Registry (void);
00554   ACE_Configuration_Win32Registry (const ACE_Configuration_Win32Registry& rhs);
00555   ACE_Configuration_Win32Registry& operator= (const ACE_Configuration_Win32Registry& rhs);
00556 };
00557 #endif /* ACE_WIN32 */
00558 
00559 // ACE_Allocator version
00560 
00561 typedef ACE_Allocator_Adapter <ACE_Malloc <ACE_MMAP_MEMORY_POOL,
00562                                            ACE_SYNCH_MUTEX> >
00563         PERSISTENT_ALLOCATOR;
00564 typedef ACE_Allocator_Adapter <ACE_Malloc <ACE_LOCAL_MEMORY_POOL,
00565                                            ACE_SYNCH_MUTEX> >
00566         HEAP_ALLOCATOR;
00567 
00568 /**
00569  * @class ACE_Configuration_ExtId
00570  *
00571  * @brief External ID for the section and value hash
00572  *
00573  * Contains a pointer to the section or value name.
00574  */
00575 class ACE_Export ACE_Configuration_ExtId
00576 {
00577 public:
00578   /// Defeault ctor
00579   ACE_Configuration_ExtId (void);
00580 
00581   /// Named constructor
00582   explicit ACE_Configuration_ExtId (const ACE_TCHAR* name);
00583 
00584   /// Copy ctor
00585   ACE_Configuration_ExtId (const ACE_Configuration_ExtId& rhs);
00586 
00587   /// destructor
00588   ~ACE_Configuration_ExtId (void);
00589 
00590   /// Assignment operator
00591   ACE_Configuration_ExtId& operator= (const ACE_Configuration_ExtId& rhs);
00592 
00593   /// Equality comparison operator (must match name_).
00594   bool operator==  (const ACE_Configuration_ExtId &rhs) const;
00595 
00596   /// Inequality comparison operator.
00597   bool operator!= (const ACE_Configuration_ExtId &rhs) const;
00598 
00599   /// Frees the name of the value.  needed since we don't know the
00600   /// allocator name_ was created in
00601   void free (ACE_Allocator *alloc);
00602 
00603   /// <hash> function is required in order for this class to be usable by
00604   /// ACE_Hash_Map_Manager.
00605   u_long hash  (void) const;
00606 
00607   // = Data members.
00608 
00609   const ACE_TCHAR * name_;
00610 
00611   // Accessors
00612   const ACE_TCHAR *name (void);
00613 };
00614 
00615 typedef ACE_Hash_Map_With_Allocator<ACE_Configuration_ExtId, int>
00616         SUBSECTION_MAP;
00617 typedef ACE_Hash_Map_Manager_Ex<ACE_Configuration_ExtId,
00618                                 int,
00619                                 ACE_Hash<ACE_Configuration_ExtId>,
00620                                 ACE_Equal_To<ACE_Configuration_ExtId>,
00621                                 ACE_Null_Mutex>
00622         SUBSECTION_HASH;
00623 
00624 /// @deprecated Deprecated typedef.  Use the SUBSECTION_HASH::ENTRY trait instead.
00625 typedef SUBSECTION_HASH::ENTRY SUBSECTION_ENTRY;
00626 
00627 /**
00628  * @class ACE_Configuration_Value_IntId
00629  *
00630  * @brief The section hash table internal value class
00631  *
00632  * This class is present as the internal portion of a section's
00633  * value hash table It may store string, integer or binary data.
00634  */
00635 class ACE_Export ACE_Configuration_Value_IntId
00636 {
00637 public:
00638   /// Default constructor
00639   ACE_Configuration_Value_IntId (void);
00640 
00641   /// String constructor, takes ownership of string
00642   explicit ACE_Configuration_Value_IntId (ACE_TCHAR* string);
00643 
00644   /// Integer constructor
00645   explicit ACE_Configuration_Value_IntId (u_int integer);
00646 
00647   /// Binary constructor, takes ownership of data
00648   ACE_Configuration_Value_IntId (void* data, size_t length);
00649 
00650   /// Copy ctor
00651   ACE_Configuration_Value_IntId (const ACE_Configuration_Value_IntId& rhs);
00652 
00653   /// Destructor
00654   ~ACE_Configuration_Value_IntId (void);
00655 
00656   /// Assignment operator
00657   ACE_Configuration_Value_IntId& operator= (
00658     const ACE_Configuration_Value_IntId& rhs);
00659 
00660   void free (ACE_Allocator *alloc);
00661 
00662   // = Data members.
00663 
00664   /**
00665    * Points to the string value or binary data or IS the integer
00666    * Length is only used when type_ == BINARY
00667    */
00668   ACE_Configuration::VALUETYPE  type_;
00669   union {
00670     void *     ptr_;
00671     u_int      int_;
00672   }                             data_;
00673   size_t                        length_;
00674 };
00675 
00676 typedef ACE_Hash_Map_With_Allocator<ACE_Configuration_ExtId,
00677                                     ACE_Configuration_Value_IntId>
00678         VALUE_MAP;
00679 typedef ACE_Hash_Map_Manager_Ex<ACE_Configuration_ExtId,
00680                                 ACE_Configuration_Value_IntId,
00681                                 ACE_Hash<ACE_Configuration_ExtId>,
00682                                 ACE_Equal_To<ACE_Configuration_ExtId>,
00683                                 ACE_Null_Mutex>
00684         VALUE_HASH;
00685 
00686 // Deprecated typedef.  Use the VALUE_HASH::ENTRY trait instead.
00687 typedef VALUE_HASH::ENTRY VALUE_ENTRY;
00688 
00689 /**
00690  * @class ACE_Configuration_Section_IntId
00691  *
00692  * @brief The internal ID for a section hash table
00693  *
00694  * Contains a hash table containing value name/values
00695  */
00696 class ACE_Export ACE_Configuration_Section_IntId
00697 {
00698 public:
00699   /// Default ctor
00700   ACE_Configuration_Section_IntId (void);
00701 
00702   /// Named ctor
00703   ACE_Configuration_Section_IntId (VALUE_MAP* value_hash_map,
00704                                    SUBSECTION_MAP* section_hash_map);
00705 
00706   /// Copy ctor
00707   ACE_Configuration_Section_IntId (const ACE_Configuration_Section_IntId& rhs);
00708 
00709   /// Destructor
00710   ~ACE_Configuration_Section_IntId (void);
00711 
00712   /// Assignment operator
00713   ACE_Configuration_Section_IntId& operator= (
00714     const ACE_Configuration_Section_IntId& rhs);
00715 
00716   /// Frees the hash table and all its values
00717   void free (ACE_Allocator *alloc);
00718 
00719   // = Data Members.
00720   VALUE_MAP* value_hash_map_;
00721 
00722   SUBSECTION_MAP* section_hash_map_;
00723 };
00724 
00725 typedef ACE_Hash_Map_With_Allocator<ACE_Configuration_ExtId,
00726                                     ACE_Configuration_Section_IntId>
00727         SECTION_MAP;
00728 typedef ACE_Hash_Map_Manager_Ex<ACE_Configuration_ExtId,
00729                                 ACE_Configuration_Section_IntId,
00730                                 ACE_Hash<ACE_Configuration_ExtId>,
00731                                 ACE_Equal_To<ACE_Configuration_ExtId>,
00732                                 ACE_Null_Mutex>
00733         SECTION_HASH;
00734 
00735 // Deprecated typedef.  Use the SECTION_HASH::ENTRY trait instead.
00736 typedef SECTION_HASH::ENTRY SECTION_ENTRY;
00737 
00738 /**
00739  * @class ACE_Configuration_Section_Key_Heap
00740  *
00741  * @brief Internal section key class for heap based configuration
00742  *    database.
00743  *
00744  *     Contains a value iterator and full path name of section.
00745  */
00746 class ACE_Export ACE_Configuration_Section_Key_Heap
00747   : public ACE_Section_Key_Internal
00748 {
00749 public:
00750   /// Constructor based on the full path of the section
00751   ACE_Configuration_Section_Key_Heap (const ACE_TCHAR* path);
00752 
00753   /// The path itself
00754   ACE_TCHAR* path_;
00755 
00756   /// The value iterator
00757   VALUE_HASH::ITERATOR* value_iter_;
00758 
00759   /// The sub section iterator
00760   SUBSECTION_HASH::ITERATOR* section_iter_;
00761 protected:
00762   /// Destructor - will delete the iterators
00763   virtual ~ACE_Configuration_Section_Key_Heap (void);
00764 
00765   // Not used
00766   ACE_Configuration_Section_Key_Heap (const ACE_Configuration_Section_Key_Heap& rhs);
00767   ACE_Configuration_Section_Key_Heap& operator= (const ACE_Configuration_Section_Key_Heap& rhs);
00768 };
00769 
00770 /**
00771  * @class ACE_Configuration_Heap
00772  *
00773  * @brief The concrete implementation of a allocator based
00774  * configuration database
00775  *
00776  * This class uses ACE's Allocators to manage a memory
00777  * representation of a configuraiton database. A persistent heap
00778  * may be used to store configurations persistently
00779  *
00780  * @note Before using this class you must call one of the open methods.
00781  *
00782  * @todo
00783  *  - Need to investigate what happens if memory mapped file gets mapped to
00784  *    a location different than it was created with.
00785  */
00786 class ACE_Export ACE_Configuration_Heap : public ACE_Configuration
00787 {
00788 public:
00789 
00790   /// Default ctor
00791   ACE_Configuration_Heap (void);
00792 
00793   /// Destructor
00794   virtual ~ACE_Configuration_Heap (void);
00795 
00796   /// Opens a configuration based on a file name
00797   int open (const ACE_TCHAR* file_name,
00798             void* base_address = ACE_DEFAULT_BASE_ADDR,
00799             size_t default_map_size = ACE_DEFAULT_CONFIG_SECTION_SIZE);
00800 
00801   /// Opens a heap based configuration
00802   int open (size_t default_map_size = ACE_DEFAULT_CONFIG_SECTION_SIZE);
00803 
00804   virtual int open_section (const ACE_Configuration_Section_Key& base,
00805                             const ACE_TCHAR* sub_section,
00806                             int create, ACE_Configuration_Section_Key& result);
00807 
00808   virtual int remove_section (const ACE_Configuration_Section_Key& key,
00809                               const ACE_TCHAR* sub_section,
00810                               int recursive);
00811 
00812   virtual int enumerate_values (const ACE_Configuration_Section_Key& key,
00813                                 int index,
00814                                 ACE_TString& name,
00815                                 VALUETYPE& type);
00816 
00817   virtual int enumerate_sections (const ACE_Configuration_Section_Key& key,
00818                                   int index,
00819                                   ACE_TString& name);
00820 
00821   virtual int set_string_value (const ACE_Configuration_Section_Key& key,
00822                                 const ACE_TCHAR* name,
00823                                 const ACE_TString& value);
00824 
00825   virtual int set_integer_value (const ACE_Configuration_Section_Key& key,
00826                                  const ACE_TCHAR* name,
00827                                  u_int value);
00828 
00829   virtual int set_binary_value (const ACE_Configuration_Section_Key& key,
00830                                 const ACE_TCHAR* name,
00831                                 const void* data,
00832                                 size_t length);
00833 
00834   virtual int get_string_value (const ACE_Configuration_Section_Key& key,
00835                                 const ACE_TCHAR* name,
00836                                 ACE_TString& value);
00837 
00838   virtual int get_integer_value (const ACE_Configuration_Section_Key& key,
00839                                  const ACE_TCHAR* name,
00840                                  u_int& value);
00841 
00842   virtual int get_binary_value (const ACE_Configuration_Section_Key& key,
00843                                 const ACE_TCHAR* name,
00844                                 void* &data,
00845                                 size_t &length);
00846 
00847   virtual int find_value(const ACE_Configuration_Section_Key& key,
00848                          const ACE_TCHAR* name,
00849                          VALUETYPE& type);
00850 
00851   /// Removes the the value <name> from <key>.  returns non zero on error
00852   virtual int remove_value (const ACE_Configuration_Section_Key& key,
00853                             const ACE_TCHAR* name);
00854 
00855 private:
00856   /// <sub_section> may not contain path separators
00857   int open_simple_section (const ACE_Configuration_Section_Key &base,
00858                             const ACE_TCHAR *sub_section,
00859                             int create, ACE_Configuration_Section_Key &result);
00860   /// Adds a new section
00861   int add_section (const ACE_Configuration_Section_Key &base,
00862                    const ACE_TCHAR *sub_section,
00863                    ACE_Configuration_Section_Key &result);
00864 
00865   /// Helper for the <open> method.
00866   int create_index (void);
00867 
00868   /// Helper for create_index() method: places hash table into an
00869   /// allocated space.
00870   int create_index_helper (void *buffer);
00871 
00872   int value_open_helper (size_t hash_table_size, void *buffer);
00873 
00874   int section_open_helper (size_t hash_table_size, void *buffer);
00875 
00876   int load_key (const ACE_Configuration_Section_Key& key, ACE_TString& name);
00877 
00878   int new_section (const ACE_TString& section,
00879                    ACE_Configuration_Section_Key& result);
00880 
00881   ACE_Configuration_Heap (const ACE_Configuration_Heap& rhs);
00882   ACE_Configuration_Heap& operator= (const ACE_Configuration_Heap& rhs);
00883 
00884   ACE_Allocator *allocator_;
00885   SECTION_MAP *index_;
00886   size_t default_map_size_;
00887 };
00888 
00889 ACE_END_VERSIONED_NAMESPACE_DECL
00890 
00891 #include /**/ "ace/post.h"
00892 #endif /* ACE_CONFIGURATION_H */

Generated on Thu Nov 9 09:41:48 2006 for ACE by doxygen 1.3.6