#include <PG_Property_Set.h>
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.
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.
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.
TAO::PG_Property_Set::PG_Property_Set | ( | void | ) |
constructor: empty set with no defaults.
Definition at line 24 of file PG_Property_Set.cpp.
: defaults_ (0) { }
TAO::PG_Property_Set::PG_Property_Set | ( | const PortableGroup::Properties & | property_set | ) |
constructor
property_set | the properties to be decoded |
Definition at line 29 of file PG_Property_Set.cpp.
TAO::PG_Property_Set::PG_Property_Set | ( | const PortableGroup::Properties & | property_set, | |
PG_Property_Set * | defaults | |||
) |
constructor with defaults
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.
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)
defaults | a propert set decoder that supplies default values. |
Definition at line 45 of file PG_Property_Set.cpp.
: defaults_ (defaults) { }
TAO::PG_Property_Set::~PG_Property_Set | ( | ) |
Definition at line 51 of file PG_Property_Set.cpp.
{ this->clear (); }
TAO::PG_Property_Set::PG_Property_Set | ( | const PG_Property_Set & | rhs | ) | [private] |
void TAO::PG_Property_Set::clear | ( | void | ) |
Clear properties Does not clear default properties.
Definition at line 104 of file PG_Property_Set.cpp.
void TAO::PG_Property_Set::decode | ( | const PortableGroup::Properties & | property_set | ) |
Decode additional properties Duplicate values replace previous values.
property_set | the properties to be decoded |
Definition at line 57 of file PG_Property_Set.cpp.
{ ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->internals_); size_t count = property_set.length (); for (size_t nItem = 0; nItem < count; ++nItem) { const PortableGroup::Property & property = property_set[nItem]; const CosNaming::Name & nsName = property.nam; // note assumption one level name with no kind // @@ TODO: fix this const CosNaming::NameComponent & nc = nsName[0]; this->set_property (static_cast<const char *> (nc.id), property.val); #if 0 ACE_CString name = static_cast<const char *> (nc.id); const PortableGroup::Value * value_copy; ACE_NEW_THROW_EX (value_copy, PortableGroup::Value (property.val), CORBA::NO_MEMORY ()); const PortableGroup::Value * replaced_value = 0; if (0 == this->values_.rebind (name, value_copy, replaced_value)) { if (0 != replaced_value) { delete replaced_value; } } else { if (TAO_debug_level > 3) { ACE_ERROR ( (LM_ERROR, "%n\n%T: Property_set: rebind failed.\n" )); } // @@ should throw something here throw CORBA::NO_MEMORY (); } #endif } }
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.
{ ValueMap merged_values; this->merge_properties (merged_values); property_set.length (merged_values.current_size ()); size_t pos = 0; for (ValueMapIterator it = merged_values.begin (); it != merged_values.end (); ++it) { const ACE_CString & name = (*it).ext_id_; const PortableGroup::Value * value = (*it).int_id_; PortableGroup::Property & property = property_set[pos]; CosNaming::Name & nsName = property.nam; //@@ note assumption: single level name, no kind nsName.length(1); CosNaming::NameComponent & nc = nsName[0]; nc.id = CORBA::string_dup (name.c_str ()); PortableGroup::Value & val = property.val; val = *value; // NOTE: Any assignment does a deep copy ++pos; } ACE_ASSERT (pos == property_set.length ()); }
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 <typename type=""> int find (const ACE_CString & key, TYPE & value) const; instead, see global function below
key | the (simple) name of the property | |
pValue | an out parameter to receive a pointer to the Any containing the value |
Definition at line 221 of file PG_Property_Set.cpp.
{ ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->internals_, 0); int found = (0 == this->values_.find (key, pValue)); if (! found) { if (0 != this->defaults_) { found = this->defaults_->find (key, pValue); } } return found; }
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.
{ ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->internals_); if (0 != this->defaults_) { this->defaults_->merge_properties (merged_values); } // note AFICT ACE_Hash_Map does not support const iterators, hence the const cast. ValueMap & mutable_values = const_cast<ValueMap &> (this->values_); for (ValueMapIterator it = mutable_values.begin (); it != mutable_values.end (); ++it) { merged_values.rebind ( (*it).ext_id_, (*it).int_id_); } }
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.
{ ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->internals_); size_t count = property_set.length (); for (size_t nItem = 0; nItem < count; ++nItem) { const PortableGroup::Property & property = property_set[nItem]; const CosNaming::Name & nsName = property.nam; // note assumption one level name with no kind // @@ TODO: fix this const CosNaming::NameComponent & nc = nsName[0]; ACE_CString name = static_cast<const char *> (nc.id); const PortableGroup::Value * deleted_value; if ( 0 == this->values_.unbind (name, deleted_value)) { delete deleted_value; } else { // don't worry about it. } } }
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.
{ ACE_CString key (name); PortableGroup::Value * value_copy; ACE_NEW_THROW_EX ( value_copy, PortableGroup::Value (value), CORBA::NO_MEMORY ()); const PortableGroup::Value * replaced_value = 0; if (0 == this->values_.rebind (name, value_copy, replaced_value)) { if (0 != replaced_value) { delete replaced_value; } } else { if (TAO_debug_level > 3) { ACE_ERROR ( (LM_ERROR, "%n\n%T: Property_set: rebind failed.\n" )); } // @@ should throw something here throw CORBA::NO_MEMORY (); } }
PG_Property_Set* TAO::PG_Property_Set::defaults_ [private] |
a parent to another property decoder that provides default values these can be chained indefinitely.
Definition at line 169 of file PG_Property_Set.h.
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.