Catalogue.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "boost/algorithm/string.hpp"
00010 #include "boost/format.hpp"
00011
00012
00013
00014 #include "Catalogue.h"
00015 #include "ParserUtils.h"
00016
00017 namespace ba = boost::algorithm;
00018
00019
00020
00021
00022
00023
00024
00025
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
00042
00043
00044
00045
00046
00047
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
00064
00065
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
00085
00086
00087
00088
00089
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
00102
00103
00104
00105
00106
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
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
00173
00174 std::ostream& operator<<( std::ostream& o , const Gaudi::Parsers::Catalogue& c )
00175 { return c.fillStream ( o ) ; }
00176
00177
00178
00179
00180