![]() |
|
|
Generated: 8 Jan 2009 |
00001 // $Id: Catalogue.cpp,v 1.8 2007/05/24 14:41:22 hmd Exp $ 00002 // ============================================================================ 00003 // CVS tag $Name: $, version $Revision: 1.8 $ 00004 // ============================================================================ 00005 // Include files 00006 // ============================================================================ 00007 // Boost.string_algo 00008 // ============================================================================ 00009 #include "boost/algorithm/string.hpp" // For case conversations 00010 #include "boost/format.hpp" 00011 // ============================================================================ 00012 // local 00013 // ============================================================================ 00014 #include "Catalogue.h" 00015 #include "ParserUtils.h" 00016 // ============================================================================ 00017 namespace ba = boost::algorithm; 00018 00019 // ============================================================================ 00020 // Purpose: Implementation of Catalogue::findProperties() 00021 // Comment: Find properties of object by object name 00022 // Parameters: 00023 // - objName Object name 00024 // - list Result list 00025 // Return: StatusCode::SUCCESS if catalogue contains object properties 00026 // ============================================================================ 00027 StatusCode Gaudi::Parsers::Catalogue::findProperties 00028 ( const std::string& objName, 00029 std::vector<PropertyEntry>& lst ) const 00030 { 00031 ObjectsStoreT::const_iterator obj = 00032 m_properties.find(objName); 00033 if ( obj == m_properties.end()){ return StatusCode::FAILURE; } 00034 PropertiesStoreT::const_iterator cur = obj->second.begin(); 00035 PropertiesStoreT::const_iterator end = obj->second.end(); 00036 for(;cur!=end;cur++){ lst.push_back(cur->second); } 00037 return StatusCode::SUCCESS; 00038 } 00039 00040 // ============================================================================ 00041 // Purpose: Implementation of Catalogue::findProperty() 00042 // Comment: Find property in catalogue 00043 // Parameters: 00044 // - objName Object name 00045 // - propName Property name 00046 // - property 00047 // Return: StatusCode::SUCCESS - if catalogue contains property 00048 // ============================================================================ 00049 StatusCode Gaudi::Parsers::Catalogue::findProperty 00050 ( const std::string& objName, 00051 const std::string& propName, 00052 PropertyEntry& property ) const 00053 { 00054 ObjectsStoreT::const_iterator obj = m_properties.find(objName); 00055 if ( obj == m_properties.end()){ return StatusCode::FAILURE; } 00056 PropertiesStoreT::const_iterator prop = obj->second.find(propName); 00057 if ( prop==obj->second.end()){ return StatusCode::FAILURE; } 00058 property = prop->second; 00059 return StatusCode::SUCCESS; 00060 } 00061 00062 // ============================================================================ 00063 // Purpose: Implementation of Catalogue::catalogue() 00064 // Comment: Return all objects names and their properties info 00065 // Return: objects names and their properties info 00066 // ============================================================================ 00067 Gaudi::Parsers::Catalogue::CatalogueT 00068 Gaudi::Parsers::Catalogue::catalogue() const 00069 { 00070 CatalogueT result; 00071 for(ObjectsStoreT::const_iterator curObj=m_properties.begin(); 00072 curObj!=m_properties.end();curObj++){ 00073 std::vector<PropertyEntry> properties; 00074 for(PropertiesStoreT::const_iterator curProp=curObj->second.begin(); 00075 curProp!=curObj->second.end();curProp++){ 00076 properties.push_back(curProp->second); 00077 } 00078 result[curObj->first] = properties; 00079 } 00080 return result; 00081 } 00082 00083 // ============================================================================ 00084 // Purpose: Implementation of Catalogue::addProperty() 00085 // Comment: Add property to catalogue 00086 // Parameters: 00087 // - objName Name of object 00088 // - property PropertyEntry 00089 // Return: 00090 // ============================================================================ 00091 void Gaudi::Parsers::Catalogue::addProperty 00092 ( const std::string& objName, 00093 const PropertyEntry& property ) 00094 { 00095 PropertyEntry prop = property; 00096 prop.removeEnv().ignore() ; 00097 m_properties[objName][ property.name()] = prop; 00098 } 00099 00100 // ============================================================================ 00101 // Purpose: Implementation of Catalogue::addProperty() 00102 // Comment: Add property to catalogue 00103 // Parameters: 00104 // - objName Name of object 00105 // - propName Property name 00106 // - value Value as string 00107 // ============================================================================ 00108 StatusCode Gaudi::Parsers::Catalogue::addProperty 00109 ( const std::string& objName, 00110 const std::string& propName, 00111 const std::string& value ) 00112 { 00113 StatusCode ok; 00114 std::string stringResult; 00115 std::vector<std::string> vectorResult; 00116 ok = Gaudi::Parsers::Utils::parseValue(value,stringResult,vectorResult); 00117 if(ok.isFailure()){ 00118 return StatusCode::FAILURE; 00119 } 00120 bool isVector = (vectorResult.size()>0) || (stringResult=="{}"); 00121 if(isVector){ 00122 addProperty(objName,PropertyEntry(propName,vectorResult)); 00123 }else{ 00124 addProperty(objName,PropertyEntry(propName,stringResult)); 00125 } 00126 return StatusCode::SUCCESS; 00127 } 00128 // ============================================================================ 00130 // ============================================================================ 00131 bool Gaudi::Parsers::_NoCaseCmp_::operator() 00132 ( const std::string& s1 , 00133 const std::string& s2 ) const 00134 { return boost::to_lower_copy( s1 ) < boost::to_lower_copy( s2 ) ; } 00135 // ============================================================================ 00136 // print the content of the catalogue to std::ostream 00137 // ============================================================================ 00138 std::ostream& Gaudi::Parsers::Catalogue::fillStream ( std::ostream& o ) const 00139 { 00140 o << "// " << std::string(82,'=') << std::endl 00141 << "// Parser catalogue " << std::endl 00142 << "// " << std::string(82,'=') << std::endl ; 00143 00144 size_t nComponents = 0 ; 00145 size_t nProperties = 0 ; 00146 00147 CatalogueT cat = catalogue(); 00148 for( Catalogue::CatalogueT::const_iterator obj = cat.begin(); 00149 cat.end() != obj ; ++obj ) 00150 { 00151 o << boost::format("// Properties of '%1%' %|40t|#=%2%" ) 00152 % obj->first % obj->second.size() << std::endl ; 00153 ++nComponents ; 00154 nProperties += obj->second.size() ; 00155 for( std::vector<PropertyEntry>::const_iterator prop = obj->second.begin(); 00156 obj->second.end() != prop ; ++prop ) 00157 { 00158 o << boost::format("%1%.%2% %|44t| = %3% ; ") 00159 % obj->first 00160 % prop->name() 00161 % prop->value() << std::endl ; 00162 } 00163 } 00164 o << "// " << std::string(82,'=') << std::endl 00165 << boost::format("// End parser catalogue #Components=%1% #Properties=%2%") 00166 % nComponents % nProperties << std::endl 00167 << "// " << std::string(82,'=') << std::endl ; 00168 00169 return o ; 00170 } 00171 // ============================================================================ 00172 // printout operator 00173 // ============================================================================ 00174 std::ostream& operator<<( std::ostream& o , const Gaudi::Parsers::Catalogue& c ) 00175 { return c.fillStream ( o ) ; } 00176 // ============================================================================ 00177 00178 // ============================================================================ 00179 // The END 00180 // ============================================================================