![]() |
|
|
Generated: 18 Jul 2008 |
00001 // $Id: JobOptionsCatalogue.cpp,v 1.13 2007/05/25 11:27:59 marcocle Exp $ 00002 // ============================================================================ 00003 // CVS tag $Name: v17r1 $ 00004 // ============================================================================ 00005 // Include files 00006 // =========================================================================== 00007 // STL&STL 00008 // =========================================================================== 00009 #include <iostream> 00010 // =========================================================================== 00011 // Boost.string_algo 00012 // =========================================================================== 00013 #include "boost/algorithm/string.hpp" 00014 // =========================================================================== 00015 // Local 00016 // =========================================================================== 00017 #include "JobOptionsCatalogue.h" 00018 #include <sstream> 00019 #include "GaudiKernel/Parsers.h" 00020 // =========================================================================== 00021 JobOptionsCatalogue::JobOptionsCatalogue() 00022 { m_catalogue = new ObjectsT(); } 00023 // =========================================================================== 00024 JobOptionsCatalogue::~JobOptionsCatalogue() 00025 { 00026 for (ObjectsT::const_iterator cur=m_catalogue->begin(); 00027 cur!=m_catalogue->end();cur++) 00028 { 00029 for(PropertiesT::const_iterator prop=cur->second.begin(); 00030 prop!=cur->second.end(); prop++) 00031 { if(NULL != *prop){ delete *prop; } } 00032 } 00033 delete m_catalogue; 00034 } 00035 // ============================================================================ 00036 StatusCode JobOptionsCatalogue::addProperty 00037 (const std::string& client, 00038 const Property* property ) 00039 { 00040 PropertiesT* props = findProperties(client); 00041 if ( props != 0 ){ 00042 removeProperty(client,property->name()).ignore(); 00043 props->push_back(property); 00044 }else{ 00045 PropertiesT toInsert; 00046 toInsert.push_back(property); 00047 m_catalogue->insert(std::pair<std::string,PropertiesT>(client,toInsert)); 00048 } 00049 return StatusCode::SUCCESS; 00050 } 00051 // ============================================================================ 00052 StatusCode 00053 JobOptionsCatalogue::removeProperty 00054 ( const std::string& client, 00055 const std::string& name) 00056 { 00057 PropertiesT* props = findProperties(client); 00058 if (props) 00059 { 00060 PropertiesT::iterator toRemove; 00061 if(findProperty(props,name,toRemove)) 00062 { 00063 delete *toRemove; 00064 props->erase(toRemove); 00065 } 00066 } 00067 return StatusCode::SUCCESS; 00068 } 00069 // ============================================================================ 00070 const JobOptionsCatalogue::PropertiesT* 00071 JobOptionsCatalogue::getProperties 00072 ( const std::string& client) const { return findProperties(client); } 00073 // ============================================================================ 00074 std::vector<std::string> JobOptionsCatalogue::getClients() const 00075 { 00076 std::vector<std::string> result; 00077 for (ObjectsT::const_iterator cur = m_catalogue->begin(); 00078 cur != m_catalogue->end(); cur++) { result.push_back(cur->first); } 00079 return result; 00080 } 00081 // ============================================================================ 00082 JobOptionsCatalogue::PropertiesT* 00083 JobOptionsCatalogue::findProperties( const std::string& client) const 00084 { 00085 ObjectsT::iterator result; 00086 if((result = m_catalogue->find(client))==m_catalogue->end()){ return 0; } 00087 return &result->second; 00088 } 00089 // ============================================================================ 00090 bool JobOptionsCatalogue::findProperty 00091 ( JobOptionsCatalogue::PropertiesT* props , 00092 const std::string& name , 00093 JobOptionsCatalogue::PropertiesT::iterator& result) 00094 { 00095 for(result = props->begin();result!=props->end();result++){ 00096 if(boost::to_lower_copy((*result)->name()) == boost::to_lower_copy(name)) 00097 { return true; } 00098 } 00099 return false; 00100 } 00101 // ============================================================================ 00102 std::ostream& JobOptionsCatalogue::fillStream( std::ostream& o ) const 00103 { 00104 // loop over the clients: 00105 for ( ObjectsT::const_iterator iclient = m_catalogue->begin(); 00106 m_catalogue->end() != iclient ; ++iclient ) 00107 { 00108 const PropertiesT& props = iclient->second ; 00109 o << "Client '" << iclient->first << "'" << std::endl ; 00110 for ( PropertiesT::const_iterator ip = props.begin() ; 00111 props.end() != ip ; ++ip ) 00112 { 00113 const Property* p = *ip ; 00114 if ( 0 == p ) { continue ; } // CONTINUE 00115 o << "\t" << (*p) << std::endl ; 00116 } 00117 } 00118 // 00119 return o ; // RETURN 00120 } 00121 // ============================================================================ 00122 // printoput operator 00123 // ============================================================================ 00124 std::ostream& operator<<( std::ostream& o , const JobOptionsCatalogue& c ) 00125 { return c.fillStream ( o ) ; } 00126 // ============================================================================ 00127 // The END 00128 // ============================================================================