TAO::PG_Property_Set Class Reference

#include <PG_Property_Set.h>

Collaboration diagram for TAO::PG_Property_Set:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 PG_Property_Set (void)
 PG_Property_Set (const PortableGroup::Properties &property_set)
 PG_Property_Set (const PortableGroup::Properties &property_set, PG_Property_Set *defaults)
 PG_Property_Set (PG_Property_Set *defaults)
 ~PG_Property_Set ()
int find (const ACE_CString &key, const PortableGroup::Value *&pValue) const
void decode (const PortableGroup::Properties &property_set)
void clear ()
void remove (const PortableGroup::Properties &property_set)
void set_property (const char *name, const PortableGroup::Value &value)
void export_properties (PortableGroup::Properties &property_set) const

Private Types

typedef ACE_Hash_Map_Manager<
ACE_CString, const PortableGroup::Value *,
ACE_SYNCH_NULL_MUTEX
ValueMap
typedef ACE_Hash_Map_Iterator<
ACE_CString, const PortableGroup::Value *,
ACE_SYNCH_NULL_MUTEX
ValueMapIterator

Private Member Functions

void merge_properties (ValueMap &merged_values) const
 PG_Property_Set (const PG_Property_Set &rhs)
PG_Property_Setoperator= (const PG_Property_Set &rhs)

Private Attributes

TAO_SYNCH_MUTEX internals_
ValueMap values_
PG_Property_Setdefaults_

Detailed Description

The PG_Property_Set captures the set of properties from a PortableGroup::Properties structure in a more usable format (a hash map), and provides methods for operating on these properties.

It supports "chains" of property sets to implement default value semantics. If a requested property is not found in this set, the default set(s) are searched. Thus, any property found at this level overrides the defaults.

See: PG_Properties_Support for more details on use of this object.

A PG_Property_Set may also be used for it's original purpose as a stand-alone helper class for extracting values from PortableGroup::Properties.

Definition at line 51 of file PG_Property_Set.h.


Member Typedef Documentation

typedef ACE_Hash_Map_Manager< ACE_CString, const PortableGroup::Value *, ACE_SYNCH_NULL_MUTEX> TAO::PG_Property_Set::ValueMap [private]
 

Definition at line 56 of file PG_Property_Set.h.

Referenced by export_properties(), and merge_properties().

typedef ACE_Hash_Map_Iterator< ACE_CString, const PortableGroup::Value *, ACE_SYNCH_NULL_MUTEX> TAO::PG_Property_Set::ValueMapIterator [private]
 

Definition at line 60 of file PG_Property_Set.h.

Referenced by clear(), export_properties(), and merge_properties().


Constructor & Destructor Documentation

TAO_BEGIN_VERSIONED_NAMESPACE_DECL TAO::PG_Property_Set::PG_Property_Set void   ) 
 

constructor: empty set with no defaults.

Definition at line 24 of file PG_Property_Set.cpp.

00025   : defaults_ (0)
00026 {
00027 }

TAO::PG_Property_Set::PG_Property_Set const PortableGroup::Properties property_set  ) 
 

constructor

Parameters:
property_set the properties to be decoded

Definition at line 29 of file PG_Property_Set.cpp.

References decode(), and PortableGroup::Properties.

00031   : defaults_ (0)
00032 {
00033   this->decode (property_set);
00034 }

TAO::PG_Property_Set::PG_Property_Set const PortableGroup::Properties property_set,
PG_Property_Set defaults
 

constructor with defaults

Parameters:
property_set the properties to be decoded
defaults a propert set decoder that supplies default values.

Definition at line 36 of file PG_Property_Set.cpp.

References decode(), and PortableGroup::Properties.

00039   : defaults_ (defaults)
00040 {
00041   this->decode (property_set);
00042 }

TAO::PG_Property_Set::PG_Property_Set PG_Property_Set defaults  ) 
 

constructor with defaults, but no properties (yet) (note this is not a copy constructor)

Parameters:
defaults a propert set decoder that supplies default values.

Definition at line 45 of file PG_Property_Set.cpp.

00047   : defaults_ (defaults)
00048 {
00049 }

TAO::PG_Property_Set::~PG_Property_Set  ) 
 

Definition at line 51 of file PG_Property_Set.cpp.

References clear().

00052 {
00053   this->clear ();
00054 }

TAO::PG_Property_Set::PG_Property_Set const PG_Property_Set rhs  )  [private]
 


Member Function Documentation

void TAO::PG_Property_Set::clear  ) 
 

Clear properties Does not clear default properties.

Definition at line 104 of file PG_Property_Set.cpp.

References ACE_GUARD, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::begin(), ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::end(), TAO_SYNCH_MUTEX, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::unbind_all(), and ValueMapIterator.

Referenced by TAO::PG_Properties_Support::set_type_properties(), and ~PG_Property_Set().

00105 {
00106   ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->internals_);
00107   for (ValueMapIterator it = this->values_.begin ();
00108        it != this->values_.end ();
00109        ++it)
00110   {
00111     delete (*it).int_id_;
00112   }
00113   this->values_.unbind_all ();
00114 }

void TAO::PG_Property_Set::decode const PortableGroup::Properties property_set  ) 
 

Decode additional properties Duplicate values replace previous values.

Parameters:
property_set the properties to be decoded

Definition at line 57 of file PG_Property_Set.cpp.

References ACE_CString, ACE_ERROR, ACE_GUARD, ACE_NEW_THROW_EX, LM_ERROR, PortableGroup::Property::nam, PortableGroup::Properties, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::rebind(), set_property(), TAO_debug_level, TAO_SYNCH_MUTEX, PortableGroup::Property::val, and PortableGroup::Value.

Referenced by PG_Property_Set(), TAO::PG_Properties_Support::set_default_properties(), TAO::PG_Object_Group::set_properties_dynamically(), and TAO::PG_Properties_Support::set_type_properties().

00058 {
00059   ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->internals_);
00060 
00061   size_t count = property_set.length ();
00062   for (size_t nItem = 0; nItem < count; ++nItem)
00063   {
00064     const PortableGroup::Property & property = property_set[nItem];
00065     const CosNaming::Name & nsName = property.nam;
00066     // note assumption one level name with no kind
00067     // @@ TODO: fix this
00068     const CosNaming::NameComponent & nc = nsName[0];
00069 
00070     this->set_property (static_cast<const char *> (nc.id),
00071                         property.val);
00072 
00073 #if 0
00074     ACE_CString name = static_cast<const char *> (nc.id);
00075 
00076     const PortableGroup::Value * value_copy;
00077     ACE_NEW_THROW_EX (value_copy,
00078                       PortableGroup::Value (property.val),
00079                       CORBA::NO_MEMORY ());
00080 
00081     const PortableGroup::Value * replaced_value = 0;
00082     if (0 == this->values_.rebind (name, value_copy, replaced_value))
00083     {
00084       if (0 != replaced_value)
00085       {
00086         delete replaced_value;
00087       }
00088     }
00089     else
00090     {
00091       if (TAO_debug_level > 3)
00092       {
00093         ACE_ERROR ( (LM_ERROR,
00094           "%n\n%T: Property_set: rebind failed.\n"
00095           ));
00096       }
00097       // @@ should throw something here
00098       throw CORBA::NO_MEMORY ();
00099     }
00100 #endif
00101   }
00102 }

void TAO::PG_Property_Set::export_properties PortableGroup::Properties property_set  )  const
 

Export the properties to a PortableGroup::Properties

This method is intended to be used to implement the PropertyManager::get_*_properties methods. If you want to access the properties for any purpose other than exporting them across a CORBA interface, it is much more efficient to use the find interface.

Definition at line 174 of file PG_Property_Set.cpp.

References ACE_ASSERT, ACE_CString, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::begin(), ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::current_size(), ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::end(), merge_properties(), PortableGroup::Property::nam, PortableGroup::Properties, CORBA::string_dup(), PortableGroup::Property::val, PortableGroup::Value, ValueMap, and ValueMapIterator.

Referenced by TAO::PG_Properties_Support::get_default_properties(), TAO::PG_Object_Group::get_properties(), and TAO::PG_Properties_Support::get_type_properties().

00175 {
00176   ValueMap merged_values;
00177   this->merge_properties (merged_values);
00178 
00179   property_set.length (merged_values.current_size ());
00180 
00181   size_t pos = 0;
00182   for (ValueMapIterator it = merged_values.begin ();
00183         it != merged_values.end ();
00184         ++it)
00185   {
00186     const ACE_CString & name = (*it).ext_id_;
00187     const PortableGroup::Value * value = (*it).int_id_;
00188 
00189     PortableGroup::Property & property = property_set[pos];
00190     CosNaming::Name & nsName = property.nam;
00191     //@@ note assumption: single level name, no kind
00192     nsName.length(1);
00193     CosNaming::NameComponent & nc = nsName[0];
00194     nc.id = CORBA::string_dup (name.c_str ());
00195     PortableGroup::Value & val = property.val;
00196     val = *value;  // NOTE: Any assignment does a deep copy
00197     ++pos;
00198   }
00199   ACE_ASSERT (pos == property_set.length ());
00200 }

int TAO::PG_Property_Set::find const ACE_CString key,
const PortableGroup::Value *&  pValue
const
 

general purpose find. returns a pointer to an Any if templated methods were available: template int find (const ACE_CString & key, TYPE & value) const; instead, see global function below

Parameters:
key the (simple) name of the property
pValue an out parameter to receive a pointer to the Any containing the value
Returns:
boolean true if found

Definition at line 221 of file PG_Property_Set.cpp.

References ACE_GUARD_RETURN, defaults_, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::find(), TAO_SYNCH_MUTEX, and PortableGroup::Value.

00224 {
00225   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->internals_, 0);
00226   int found = (0 == this->values_.find (key, pValue));
00227   if (! found)
00228   {
00229     if (0 != this->defaults_)
00230     {
00231       found = this->defaults_->find (key, pValue);
00232     }
00233   }
00234   return found;
00235 }

void TAO::PG_Property_Set::merge_properties ValueMap merged_values  )  const [private]
 

populate a ValueMap with the properties known to this decoder including but overriding default values

Definition at line 202 of file PG_Property_Set.cpp.

References ACE_GUARD, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::begin(), defaults_, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::end(), ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::rebind(), TAO_SYNCH_MUTEX, ValueMap, and ValueMapIterator.

Referenced by export_properties().

00203 {
00204   ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->internals_);
00205   if (0 != this->defaults_)
00206   {
00207     this->defaults_->merge_properties (merged_values);
00208   }
00209   // note AFICT ACE_Hash_Map does not support const iterators, hence the const cast.
00210   ValueMap & mutable_values = const_cast<ValueMap &> (this->values_);
00211   for (ValueMapIterator it = mutable_values.begin ();
00212         it != mutable_values.end ();
00213         ++it)
00214   {
00215     merged_values.rebind ( (*it).ext_id_, (*it).int_id_);
00216   }
00217 }

PG_Property_Set& TAO::PG_Property_Set::operator= const PG_Property_Set rhs  )  [private]
 

void TAO::PG_Property_Set::remove const PortableGroup::Properties property_set  ) 
 

Definition at line 116 of file PG_Property_Set.cpp.

References ACE_CString, ACE_GUARD, PortableGroup::Property::nam, PortableGroup::Properties, TAO_SYNCH_MUTEX, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::unbind(), and PortableGroup::Value.

Referenced by TAO::PG_Properties_Support::remove_default_properties(), and TAO::PG_Properties_Support::remove_type_properties().

00117 {
00118   ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->internals_);
00119   size_t count = property_set.length ();
00120   for (size_t nItem = 0; nItem < count; ++nItem)
00121   {
00122     const PortableGroup::Property & property = property_set[nItem];
00123     const CosNaming::Name & nsName = property.nam;
00124     // note assumption one level name with no kind
00125     // @@ TODO: fix this
00126     const CosNaming::NameComponent & nc = nsName[0];
00127     ACE_CString name = static_cast<const char *> (nc.id);
00128 
00129     const PortableGroup::Value * deleted_value;
00130     if ( 0 == this->values_.unbind (name, deleted_value))
00131     {
00132       delete deleted_value;
00133     }
00134     else
00135     {
00136       // don't worry about it.
00137     }
00138   }
00139 }

void TAO::PG_Property_Set::set_property const char *  name,
const PortableGroup::Value value
 

set or replace a single property

Definition at line 141 of file PG_Property_Set.cpp.

References ACE_CString, ACE_ERROR, ACE_NEW_THROW_EX, LM_ERROR, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_LOCK >::rebind(), TAO_debug_level, and PortableGroup::Value.

Referenced by decode(), and TAO::PG_Properties_Support::set_default_property().

00144 {
00145   ACE_CString key (name);
00146   PortableGroup::Value * value_copy;
00147   ACE_NEW_THROW_EX (
00148     value_copy, PortableGroup::Value (value),
00149     CORBA::NO_MEMORY ());
00150 
00151   const PortableGroup::Value * replaced_value = 0;
00152   if (0 == this->values_.rebind (name, value_copy, replaced_value))
00153   {
00154     if (0 != replaced_value)
00155     {
00156       delete replaced_value;
00157     }
00158   }
00159   else
00160   {
00161     if (TAO_debug_level > 3)
00162     {
00163       ACE_ERROR ( (LM_ERROR,
00164         "%n\n%T: Property_set: rebind failed.\n"
00165         ));
00166     }
00167     // @@ should throw something here
00168     throw CORBA::NO_MEMORY ();
00169   }
00170 }


Member Data Documentation

PG_Property_Set* TAO::PG_Property_Set::defaults_ [private]
 

a parent to another property decoder that provides default values these can be chained indefinitely.

Todo:
reference counted pointers would be a good idea here.

Definition at line 169 of file PG_Property_Set.h.

Referenced by find(), and merge_properties().

TAO_SYNCH_MUTEX TAO::PG_Property_Set::internals_ [mutable, private]
 

Protect internal state.

Definition at line 161 of file PG_Property_Set.h.

ValueMap TAO::PG_Property_Set::values_ [private]
 

Definition at line 163 of file PG_Property_Set.h.


The documentation for this class was generated from the following files:
Generated on Sun Jan 27 16:24:50 2008 for TAO_PortableGroup by doxygen 1.3.6