PG_Property_Set.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    PG_Property_Set.h
00006  *
00007  *  PG_Property_Set.h,v 1.12 2006/03/14 06:14:34 jtc Exp
00008  *
00009  *  This file declares classes to help manage the Properties
00010  *  defined in the Portable Object Group.
00011  *
00012  *  Note: this started as a simple helper class to make decoding sets of properties
00013  *  easier, but expanded to provide more general support for managing sets of properties.
00014  *
00015  *  A more appropriate name would be PG_Properties_Set.  Maybe this can be changed someday.
00016  *
00017  *  @author Dale Wilson <wilson_d@ociweb.com>
00018  */
00019 //=============================================================================
00020 #ifndef TAO_PG_PROPERTY_SET
00021 #define TAO_PG_PROPERTY_SET
00022 #include /**/ "ace/pre.h"
00023 
00024 #include "orbsvcs/PortableGroup/portablegroup_export.h"
00025 #include "orbsvcs/PortableGroupS.h"
00026 #include "orbsvcs/CosNamingC.h"
00027 #include "ace/Hash_Map_Manager.h"
00028 #include "ace/SString.h"
00029 #include "ace/Null_Mutex.h"
00030 
00031 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00032 
00033 namespace TAO
00034 {
00035 
00036   /**
00037    * The PG_Property_Set captures the set of properties from a
00038    * PortableGroup::Properties structure in a more usable format (a
00039    * hash map), and provides methods for operating on these properties.
00040    *
00041    * It supports "chains" of property sets to implement default value semantics.
00042    * If a requested property is not found in this set, the default set(s) are searched.
00043    * Thus, any property found at this level overrides the defaults.
00044    *
00045    * See: PG_Properties_Support for more details on use of this object.
00046    *
00047    * A PG_Property_Set may also be used for it's original purpose as a stand-alone
00048    * helper class for extracting values from PortableGroup::Properties.
00049    */
00050 
00051   class TAO_PortableGroup_Export PG_Property_Set
00052   {
00053     typedef ACE_Hash_Map_Manager<
00054       ACE_CString,
00055       const PortableGroup::Value *,
00056       ACE_SYNCH_NULL_MUTEX> ValueMap;
00057     typedef ACE_Hash_Map_Iterator<
00058       ACE_CString,
00059       const PortableGroup::Value *,
00060       ACE_SYNCH_NULL_MUTEX> ValueMapIterator;
00061 
00062   public:
00063 
00064     /**
00065      * constructor: empty set with no defaults.
00066      */
00067     PG_Property_Set (void);
00068 
00069     /**
00070      * constructor
00071      * @param property_set the properties to be decoded
00072      */
00073     PG_Property_Set (const PortableGroup::Properties & property_set
00074                      ACE_ENV_ARG_DECL_WITH_DEFAULTS)
00075       ACE_THROW_SPEC ((CORBA::SystemException));
00076 
00077     /**
00078      * constructor with defaults
00079      * @param property_set the properties to be decoded
00080      * @param defaults a propert set decoder that supplies default values.
00081      */
00082     PG_Property_Set (const PortableGroup::Properties & property_set,
00083                      PG_Property_Set * defaults
00084                      ACE_ENV_ARG_DECL_WITH_DEFAULTS)
00085       ACE_THROW_SPEC ((CORBA::SystemException));
00086 
00087     /**
00088      * constructor with defaults, but no properties (yet)
00089      * (note this is not a copy constructor)
00090      * @param defaults a propert set decoder that supplies default values.
00091      */
00092     PG_Property_Set (PG_Property_Set * defaults);
00093 
00094 
00095     ~PG_Property_Set ();
00096 
00097     /**
00098      * general purpose find. returns a pointer to an Any
00099      *  if templated methods were available:
00100      *    template <typename TYPE >
00101      *    int find (const ACE_CString & key, TYPE & value) const;
00102      *    instead, see global function below
00103      * @param key the (simple) name of the property
00104      * @param pValue an out parameter to receive a pointer to the Any containing the value
00105      * @returns boolean true if found
00106      */
00107     int find (const ACE_CString & key, const PortableGroup::Value *& pValue)const;
00108 
00109 
00110     /**
00111      * Decode additional properties
00112      * Duplicate values replace previous values.
00113      * @param property_set the properties to be decoded
00114      */
00115     void decode (const PortableGroup::Properties & property_set ACE_ENV_ARG_DECL)
00116       ACE_THROW_SPEC ((CORBA::SystemException));
00117 
00118     /**
00119      * Clear properties
00120      * Does not clear default properties.
00121      */
00122     void clear ();
00123 
00124     void remove (const PortableGroup::Properties & property_set)
00125       ACE_THROW_SPEC ((CORBA::SystemException));
00126 
00127     /**
00128      * set or replace a single property
00129      */
00130     void set_property (
00131       const char * name,
00132       const PortableGroup::Value & value
00133       ACE_ENV_ARG_DECL);
00134 
00135 
00136     /**
00137      * Export the properties to a PortableGroup::Properties
00138      *
00139      * This method is intended to be used to implement the PropertyManager::get_*_properties
00140      * methods.  If you want to access the properties for any purpose other than exporting
00141      * them across a CORBA interface, it is much more efficient to use the find interface.
00142      *
00143      */
00144     void export_properties(PortableGroup::Properties & property_set) const;
00145 
00146     /////////////////////////
00147     // Implementation Methods
00148  private:
00149     /**
00150      * populate a ValueMap with the properties known to this decoder
00151      * including but overriding default values
00152      */
00153     void merge_properties (ValueMap & merged_values) const;
00154 
00155     ////////////////////
00156     // Forbidden methods
00157   private:
00158     PG_Property_Set(const PG_Property_Set & rhs);
00159     PG_Property_Set & operator = (const PG_Property_Set & rhs);
00160 
00161     ///////////////
00162     // Data Members
00163   private:
00164 
00165     /**
00166      * Protect internal state.
00167      */
00168     mutable TAO_SYNCH_MUTEX internals_;
00169 
00170     ValueMap values_;
00171     /**
00172      * a parent to another property decoder that provides default values
00173      * these can be chained indefinitely.
00174      * @todo reference counted pointers would be a good idea here.
00175      */
00176     PG_Property_Set * defaults_;
00177   };
00178 
00179 
00180 #ifdef PG_PS_UNIT_TEST
00181 
00182   /**
00183    * unit test: encode and decode properties.
00184    * Initialize CORBA before calling this function.
00185    * Success is silent, failure prints on cerr.
00186    * @returns 1 if test passed; 0 if test failed.
00187    */
00188   int test_encode_decode();
00189 #endif // PG_PS_UNIT_TEST
00190 } //namespace TAO
00191 
00192 TAO_END_VERSIONED_NAMESPACE_DECL
00193 
00194 ////////////////////////////////////
00195 // include templated helper function
00196 #include "orbsvcs/PortableGroup/PG_Property_Set_Find.h"
00197 
00198 #include /**/ "ace/post.h"
00199 
00200 #endif // TAO_PG_PROPERTY_SET

Generated on Thu Nov 9 14:03:34 2006 for TAO_PortableGroup by doxygen 1.3.6