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 ACE_ENV_ARG_DECL_WITH_DEFAULTS) throw (CORBA::SystemException)
 PG_Property_Set (const PortableGroup::Properties &property_set, PG_Property_Set *defaults ACE_ENV_ARG_DECL_WITH_DEFAULTS) throw (CORBA::SystemException)
 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 ACE_ENV_ARG_DECL) throw (CORBA::SystemException)
void clear ()
void remove (const PortableGroup::Properties &property_set) throw (CORBA::SystemException)
void set_property (const char *name, const PortableGroup::Value &value ACE_ENV_ARG_DECL)
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  ACE_ENV_ARG_DECL_WITH_DEFAULTS  )  throw (CORBA::SystemException)
 

constructor

Parameters:
property_set the properties to be decoded

Definition at line 29 of file PG_Property_Set.cpp.

References ACE_ENV_ARG_PARAMETER, and PortableGroup::Properties.

00033   : defaults_ (0)
00034 {
00035   this->decode (property_set ACE_ENV_ARG_PARAMETER);
00036 }

TAO::PG_Property_Set::PG_Property_Set const PortableGroup::Properties property_set,
PG_Property_Set *defaults  ACE_ENV_ARG_DECL_WITH_DEFAULTS
throw (CORBA::SystemException)
 

constructor with defaults

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

Definition at line 38 of file PG_Property_Set.cpp.

References ACE_ENV_ARG_PARAMETER, and PortableGroup::Properties.

00043   : defaults_ (defaults)
00044 {
00045   this->decode (property_set ACE_ENV_ARG_PARAMETER);
00046 }

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 49 of file PG_Property_Set.cpp.

00051   : defaults_ (defaults)
00052 {
00053 }

TAO::PG_Property_Set::~PG_Property_Set  ) 
 

Definition at line 55 of file PG_Property_Set.cpp.

References clear().

00056 {
00057   this->clear ();
00058 }

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 113 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().

00114 {
00115   ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->internals_);
00116   for (ValueMapIterator it = this->values_.begin ();
00117        it != this->values_.end ();
00118        ++it)
00119   {
00120     delete (*it).int_id_;
00121   }
00122   this->values_.unbind_all ();
00123 }

void TAO::PG_Property_Set::decode const PortableGroup::Properties &property_set  ACE_ENV_ARG_DECL  )  throw (CORBA::SystemException)
 

Decode additional properties Duplicate values replace previous values.

Parameters:
property_set the properties to be decoded

Definition at line 61 of file PG_Property_Set.cpp.

References ACE_CHECK, ACE_CString, ACE_ENV_ARG_PARAMETER, ACE_ERROR, ACE_GUARD, ACE_NEW_THROW_EX, ACE_THROW, LM_ERROR, PortableGroup::Property::nam, PortableGroup::Properties, TAO_debug_level, TAO_SYNCH_MUTEX, PortableGroup::Property::val, and PortableGroup::Value.

Referenced by TAO::PG_Properties_Support::set_type_properties().

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

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 186 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_type_properties().

00187 {
00188   ValueMap merged_values;
00189   this->merge_properties (merged_values);
00190 
00191   property_set.length (merged_values.current_size ());
00192 
00193   size_t pos = 0;
00194   for (ValueMapIterator it = merged_values.begin ();
00195         it != merged_values.end ();
00196         ++it)
00197   {
00198     const ACE_CString & name = (*it).ext_id_;
00199     const PortableGroup::Value * value = (*it).int_id_;
00200 
00201     PortableGroup::Property & property = property_set[pos];
00202     CosNaming::Name & nsName = property.nam;
00203     //@@ note assumption: single level name, no kind
00204     nsName.length(1);
00205     CosNaming::NameComponent & nc = nsName[0];
00206     nc.id = CORBA::string_dup (name.c_str ());
00207     PortableGroup::Value & val = property.val;
00208     val = *value;  // NOTE: Any assignment does a deep copy
00209     ++pos;
00210   }
00211   ACE_ASSERT (pos == property_set.length ());
00212 }

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 233 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.

00236 {
00237   ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->internals_, 0);
00238   int found = (0 == this->values_.find (key, pValue));
00239   if (! found)
00240   {
00241     if (0 != this->defaults_)
00242     {
00243       found = this->defaults_->find (key, pValue);
00244     }
00245   }
00246   return found;
00247 }

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 214 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().

00215 {
00216   ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->internals_);
00217   if (0 != this->defaults_)
00218   {
00219     this->defaults_->merge_properties (merged_values);
00220   }
00221   // note AFICT ACE_Hash_Map does not support const iterators, hence the const cast.
00222   ValueMap & mutable_values = const_cast<ValueMap &> (this->values_);
00223   for (ValueMapIterator it = mutable_values.begin ();
00224         it != mutable_values.end ();
00225         ++it)
00226   {
00227     merged_values.rebind ( (*it).ext_id_, (*it).int_id_);
00228   }
00229 }

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  )  throw (CORBA::SystemException)
 

Definition at line 125 of file PG_Property_Set.cpp.

References ACE_CString, ACE_GUARD, PortableGroup::Property::nam, PortableGroup::Properties, TAO_SYNCH_MUTEX, and PortableGroup::Value.

Referenced by TAO::PG_Properties_Support::remove_type_properties().

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

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

set or replace a single property

Definition at line 151 of file PG_Property_Set.cpp.

References ACE_CHECK, ACE_CString, ACE_ERROR, ACE_NEW_THROW_EX, ACE_THROW, 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.

00155 {
00156   ACE_CString key (name);
00157   PortableGroup::Value * value_copy;
00158   ACE_NEW_THROW_EX (
00159     value_copy, PortableGroup::Value (value),
00160     CORBA::NO_MEMORY ());
00161   ACE_CHECK;
00162 
00163   const PortableGroup::Value * replaced_value = 0;
00164   if (0 == this->values_.rebind (name, value_copy, replaced_value))
00165   {
00166     if (0 != replaced_value)
00167     {
00168       delete replaced_value;
00169     }
00170   }
00171   else
00172   {
00173     if (TAO_debug_level > 3)
00174     {
00175       ACE_ERROR ( (LM_ERROR,
00176         "%n\n%T: Property_set: rebind failed.\n"
00177         ));
00178     }
00179     // @@ should throw something here
00180     ACE_THROW (CORBA::NO_MEMORY ());
00181   }
00182 }


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 176 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 168 of file PG_Property_Set.h.

ValueMap TAO::PG_Property_Set::values_ [private]
 

Definition at line 170 of file PG_Property_Set.h.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 14:05:33 2006 for TAO_PortableGroup by doxygen 1.3.6