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