PG_Property_Set.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    PG_Property_Set.h
00006  *
00007  *  $Id: PG_Property_Set.h 77001 2007-02-12 07:54:49Z johnnyw $
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 
00075     /**
00076      * constructor with defaults
00077      * @param property_set the properties to be decoded
00078      * @param defaults a propert set decoder that supplies default values.
00079      */
00080     PG_Property_Set (const PortableGroup::Properties & property_set,
00081                      PG_Property_Set * defaults);
00082 
00083     /**
00084      * constructor with defaults, but no properties (yet)
00085      * (note this is not a copy constructor)
00086      * @param defaults a propert set decoder that supplies default values.
00087      */
00088     PG_Property_Set (PG_Property_Set * defaults);
00089 
00090 
00091     ~PG_Property_Set ();
00092 
00093     /**
00094      * general purpose find. returns a pointer to an Any
00095      *  if templated methods were available:
00096      *    template <typename TYPE >
00097      *    int find (const ACE_CString & key, TYPE & value) const;
00098      *    instead, see global function below
00099      * @param key the (simple) name of the property
00100      * @param pValue an out parameter to receive a pointer to the Any containing the value
00101      * @returns boolean true if found
00102      */
00103     int find (const ACE_CString & key, const PortableGroup::Value *& pValue)const;
00104 
00105 
00106     /**
00107      * Decode additional properties
00108      * Duplicate values replace previous values.
00109      * @param property_set the properties to be decoded
00110      */
00111     void decode (const PortableGroup::Properties & property_set);
00112 
00113     /**
00114      * Clear properties
00115      * Does not clear default properties.
00116      */
00117     void clear ();
00118 
00119     void remove (const PortableGroup::Properties & property_set);
00120 
00121     /**
00122      * set or replace a single property
00123      */
00124     void set_property (
00125       const char * name,
00126       const PortableGroup::Value & value);
00127 
00128 
00129     /**
00130      * Export the properties to a PortableGroup::Properties
00131      *
00132      * This method is intended to be used to implement the PropertyManager::get_*_properties
00133      * methods.  If you want to access the properties for any purpose other than exporting
00134      * them across a CORBA interface, it is much more efficient to use the find interface.
00135      *
00136      */
00137     void export_properties(PortableGroup::Properties & property_set) const;
00138 
00139     /////////////////////////
00140     // Implementation Methods
00141  private:
00142     /**
00143      * populate a ValueMap with the properties known to this decoder
00144      * including but overriding default values
00145      */
00146     void merge_properties (ValueMap & merged_values) const;
00147 
00148     ////////////////////
00149     // Forbidden methods
00150   private:
00151     PG_Property_Set(const PG_Property_Set & rhs);
00152     PG_Property_Set & operator = (const PG_Property_Set & rhs);
00153 
00154     ///////////////
00155     // Data Members
00156   private:
00157 
00158     /**
00159      * Protect internal state.
00160      */
00161     mutable TAO_SYNCH_MUTEX internals_;
00162 
00163     ValueMap values_;
00164     /**
00165      * a parent to another property decoder that provides default values
00166      * these can be chained indefinitely.
00167      * @todo reference counted pointers would be a good idea here.
00168      */
00169     PG_Property_Set * defaults_;
00170   };
00171 
00172 
00173 #ifdef PG_PS_UNIT_TEST
00174 
00175   /**
00176    * unit test: encode and decode properties.
00177    * Initialize CORBA before calling this function.
00178    * Success is silent, failure prints on cerr.
00179    * @returns 1 if test passed; 0 if test failed.
00180    */
00181   int test_encode_decode();
00182 #endif // PG_PS_UNIT_TEST
00183 } //namespace TAO
00184 
00185 TAO_END_VERSIONED_NAMESPACE_DECL
00186 
00187 ////////////////////////////////////
00188 // include templated helper function
00189 #include "orbsvcs/PortableGroup/PG_Property_Set_Find.h"
00190 
00191 #include /**/ "ace/post.h"
00192 
00193 #endif // TAO_PG_PROPERTY_SET

Generated on Sun Jan 27 16:22:30 2008 for TAO_PortableGroup by doxygen 1.3.6