00001 #include "orbsvcs/PortableGroup/PG_Property_Utils.h" 00002 #include "orbsvcs/PortableGroup/PG_Operators.h" 00003 00004 ACE_RCSID (PortableGroup, 00005 PG_Property_Utils, 00006 "$Id: PG_Property_Utils.cpp 71526 2006-03-14 06:14:35Z jtc $") 00007 00008 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00009 00010 CORBA::Boolean 00011 TAO_PG::get_property_value (const PortableGroup::Name & property_name, 00012 const PortableGroup::Properties & properties, 00013 PortableGroup::Value & property_value) 00014 { 00015 const CORBA::ULong len = properties.length (); 00016 for (CORBA::ULong i = 0; i < len; ++i) 00017 { 00018 const PortableGroup::Property & property = properties[i]; 00019 if (property.nam == property_name) 00020 { 00021 property_value = property.val; 00022 return 1; 00023 } 00024 } 00025 00026 return 0; 00027 } 00028 00029 void 00030 TAO_PG::override_properties ( 00031 const PortableGroup::Properties & overrides, 00032 PortableGroup::Properties &properties) 00033 { 00034 const CORBA::ULong num_overrides = overrides.length (); 00035 if (num_overrides == 0) 00036 return; 00037 00038 const CORBA::ULong old_length = properties.length (); 00039 00040 const CORBA::ULong new_length = 00041 (num_overrides > old_length ? num_overrides : old_length); 00042 00043 // Increase the length wholesale as much as possible. The idea is 00044 // to keep the cost of the incremental growth that may occur below 00045 // to a minimum. 00046 properties.length (new_length); 00047 00048 // @@ Slow O(n^2) operation. Note that it may be slower than O(n^2) 00049 // if the length of the property sequence must be increased 00050 // on-the-fly due to the allocations and copies incurred by such 00051 // an operation. 00052 for (CORBA::ULong i = 0; i < num_overrides; ++i) 00053 { 00054 const PortableGroup::Property &override = overrides[i]; 00055 00056 CORBA::ULong j = 0; 00057 for ( ; j < old_length; ++j) 00058 if (properties[j].nam == override.nam) 00059 { 00060 properties[j].val = override.val; 00061 break; 00062 } 00063 00064 // No property to override. Append the override. 00065 if (j == old_length) 00066 { 00067 // @@ Slow incremental growth! In order to set the length 00068 // only once, i.e. a priori, instead of multiple times a 00069 // searches in the override list and the property list 00070 // must be performed to determine how many additional 00071 // properties from the override list must be appended to 00072 // the properties list. Depending on the size of each 00073 // list, such an operation may be just as slow as this 00074 // operation. 00075 const CORBA::ULong current_length = properties.length (); 00076 properties.length (current_length + 1); 00077 properties[current_length] = override; 00078 } 00079 } 00080 } 00081 00082 TAO_END_VERSIONED_NAMESPACE_DECL