All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SvcCatalog.cpp
Go to the documentation of this file.
1 // $Id:$
2 // ============================================================================
3 // CVS tag $Name: $
4 // ============================================================================
5 // Include files
6 // ===========================================================================
7 // STD & STL:
8 // ===========================================================================
9 #include <iostream>
10 #include <sstream>
11 // ===========================================================================
12 // Boost:
13 // ===========================================================================
14 #include "boost/algorithm/string.hpp"
15 // ===========================================================================
16 // Local
17 // ===========================================================================
18 #include "SvcCatalog.h"
19 // ===========================================================================
21 { m_catalog = new ObjectsT(); }
22 // ===========================================================================
24 {
25  for (ObjectsT::const_iterator cur=m_catalog->begin();
26  cur!=m_catalog->end();cur++)
27  {
28  for(PropertiesT::const_iterator prop=cur->second.begin();
29  prop!=cur->second.end(); prop++)
30  { if(NULL != *prop){ delete *prop; } }
31  }
32  delete m_catalog;
33 }
34 // ============================================================================
36 (const std::string& client,
37  const Property* property )
38 {
39  PropertiesT* props = findProperties(client);
40  if ( props != 0 ){
41  removeProperty(client,property->name()).ignore();
42  props->push_back(property);
43  }else{
44  PropertiesT toInsert;
45  toInsert.push_back(property);
46  m_catalog->insert(std::pair<std::string,PropertiesT>(client,toInsert));
47  }
48  return StatusCode::SUCCESS;
49 }
50 // ============================================================================
53 ( const std::string& client,
54  const std::string& name)
55 {
56  PropertiesT* props = findProperties(client);
57  if (props)
58  {
59  PropertiesT::iterator toRemove;
60  if(findProperty(props,name,toRemove))
61  {
62  delete *toRemove;
63  props->erase(toRemove);
64  }
65  }
66  return StatusCode::SUCCESS;
67 }
68 // ============================================================================
71 ( const std::string& client) const { return findProperties(client); }
72 // ============================================================================
73 std::vector<std::string> SvcCatalog::getClients() const
74 {
75  std::vector<std::string> result;
76  for (ObjectsT::const_iterator cur = m_catalog->begin();
77  cur != m_catalog->end(); cur++) { result.push_back(cur->first); }
78  return result;
79 }
80 // ============================================================================
82 SvcCatalog::findProperties( const std::string& client) const
83 {
84  ObjectsT::iterator result;
85  if((result = m_catalog->find(client)) == m_catalog->end()){ return 0; }
86  return &result->second;
87 }
88 // ============================================================================
91  const std::string& name ,
92  SvcCatalog::PropertiesT::iterator& result)
93 {
94  for(result = props->begin();result!=props->end();result++){
95  if(boost::to_lower_copy((*result)->name()) == boost::to_lower_copy(name))
96  { return true; }
97  }
98  return false;
99 }
100 // ============================================================================
101 std::ostream& SvcCatalog::fillStream( std::ostream& o ) const
102 {
103  // loop over the clients:
104  for ( ObjectsT::const_iterator iclient = m_catalog->begin();
105  m_catalog->end() != iclient ; ++iclient )
106  {
107  const PropertiesT& props = iclient->second ;
108  o << "Client '" << iclient->first << "'" << std::endl ;
109  for ( PropertiesT::const_iterator ip = props.begin() ;
110  props.end() != ip ; ++ip )
111  {
112  const Property* p = *ip ;
113  if ( 0 == p ) { continue ; } // CONTINUE
114  o << "\t" << (*p) << std::endl ;
115  }
116  }
117  //
118  return o ; // RETURN
119 }
120 // ============================================================================
121 // printoput operator
122 // ============================================================================
123 std::ostream& operator<<( std::ostream& o , const SvcCatalog& c )
124 { return c.fillStream ( o ) ; }
125 // ============================================================================
126 // The END
127 // ============================================================================
ObjectsT * m_catalog
Definition: SvcCatalog.h:50
PropertiesT * findProperties(const std::string &client) const
Definition: SvcCatalog.cpp:82
const PropertiesT * getProperties(const std::string &client) const
Definition: SvcCatalog.cpp:71
const std::string & name() const
property name
Definition: Property.h:47
std::ostream & fillStream(std::ostream &o) const
dump the content of catalog to std::ostream
Definition: SvcCatalog.cpp:101
tuple c
Definition: gaudirun.py:341
virtual ~SvcCatalog()
Definition: SvcCatalog.cpp:23
StatusCode addProperty(const std::string &client, const Property *property)
Definition: SvcCatalog.cpp:36
std::ostream & operator<<(std::ostream &o, const SvcCatalog &c)
printoput operator
Definition: SvcCatalog.cpp:123
StatusCode removeProperty(const std::string &client, const std::string &name)
Definition: SvcCatalog.cpp:53
std::vector< std::string > getClients() const
Definition: SvcCatalog.cpp:73
bool findProperty(PropertiesT *props, const std::string &name, PropertiesT::iterator &result)
Definition: SvcCatalog.cpp:90
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:43
std::map< std::string, PropertiesT > ObjectsT
Definition: SvcCatalog.h:32
std::vector< const Property * > PropertiesT
Definition: SvcCatalog.h:31