SvcCatalog.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ===========================================================================
4 // STD & STL:
5 // ===========================================================================
6 #include <iostream>
7 #include <sstream>
8 // ===========================================================================
9 // Boost:
10 // ===========================================================================
11 #include "boost/algorithm/string.hpp"
12 // ===========================================================================
13 // Local
14 // ===========================================================================
15 #include "SvcCatalog.h"
16 // ===========================================================================
17 namespace {
18  constexpr struct select1st_t {
19  template <typename S, typename T> const S& operator()(const std::pair<S,T>& p) const
20  { return p.first; }
21  template <typename S, typename T> S& operator()(std::pair<S,T>& p) const
22  { return p.first; }
23  } select1st {};
24 }
25 // ===========================================================================
27 {
28  for (const auto& cur : m_catalog)
29  {
30  for (auto & prop : cur.second) delete prop;
31  }
32 }
33 // ============================================================================
35 (const std::string& client,
36  const Property* property )
37 {
38  auto props = findProperties(client);
39  if ( props ){
40  removeProperty(client,property->name()).ignore();
41  props->push_back(property);
42  }else{
43  m_catalog.emplace( client, PropertiesT{ property } );
44  }
45  return StatusCode::SUCCESS;
46 }
47 // ============================================================================
49 SvcCatalog::removeProperty ( const std::string& client,
50  const std::string& name)
51 {
52  auto props = findProperties(client);
53  if (props) {
54  auto res = findProperty(*props,name);
55  if(res.first) {
56  delete *res.second;
57  props->erase(res.second);
58  }
59  }
60  return StatusCode::SUCCESS;
61 }
62 // ============================================================================
65 ( const std::string& client) const { return findProperties(client); }
66 // ============================================================================
67 std::vector<std::string> SvcCatalog::getClients() const
68 {
69  std::vector<std::string> result; result.reserve(m_catalog.size());
70  std::transform( std::begin(m_catalog), std::end(m_catalog),
71  std::back_inserter(result), select1st );
72  return result;
73 }
74 // ============================================================================
76 SvcCatalog::findProperties( const std::string& client) const
77 {
78  auto result = m_catalog.find(client);
79  return ( result != m_catalog.end() ) ? &result->second
80  : nullptr;
81 }
82 // ============================================================================
84 SvcCatalog::findProperties( const std::string& client)
85 {
86  auto result = m_catalog.find(client);
87  return ( result != m_catalog.end() ) ? &result->second
88  : nullptr;
89 }
90 // ============================================================================
91 std::pair<bool,SvcCatalog::PropertiesT::iterator>
94  const std::string& name )
95 {
96  auto p = std::find_if( std::begin(props), std::end(props),
97  [&](const Property* prop) {
98  return boost::iequals( name, prop->name());
99  });
100  return { p != std::end(props), p };
101 }
102 // ============================================================================
103 std::ostream& SvcCatalog::fillStream( std::ostream& o ) const
104 {
105  // loop over the clients:
106  for ( const auto& iclient : m_catalog )
107  {
108  o << "Client '" << iclient.first << "'" << std::endl ;
109  for ( const auto& p : iclient.second )
110  {
111  if ( p ) o << "\t" << (*p) << std::endl ;
112  }
113  }
114  //
115  return o ; // RETURN
116 }
117 // ============================================================================
118 // printoput operator
119 // ============================================================================
120 std::ostream& operator<<( std::ostream& o , const SvcCatalog& c )
121 { return c.fillStream ( o ) ; }
122 // ============================================================================
123 // The END
124 // ============================================================================
tuple c
Definition: gaudirun.py:391
const PropertiesT * getProperties(const std::string &client) const
Definition: SvcCatalog.cpp:65
const std::string & name() const
property name
Definition: Property.h:45
std::ostream & fillStream(std::ostream &o) const
dump the content of catalog to std::ostream
Definition: SvcCatalog.cpp:103
constexpr struct select1st_t select1st
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
StatusCode addProperty(const std::string &client, const Property *property)
Definition: SvcCatalog.cpp:35
std::ostream & operator<<(std::ostream &o, const SvcCatalog &c)
printoput operator
Definition: SvcCatalog.cpp:120
StatusCode removeProperty(const std::string &client, const std::string &name)
Definition: SvcCatalog.cpp:49
std::vector< std::string > getClients() const
Definition: SvcCatalog.cpp:67
const PropertiesT * findProperties(const std::string &client) const
Definition: SvcCatalog.cpp:76
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
std::map< std::string, PropertiesT > m_catalog
Definition: SvcCatalog.h:46
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
const S & operator()(const std::pair< S, T > &p) const
std::vector< const Property * > PropertiesT
Definition: SvcCatalog.h:28
std::pair< bool, PropertiesT::iterator > findProperty(PropertiesT &props, const std::string &name)
Definition: SvcCatalog.cpp:93