The Gaudi Framework  v29r0 (ff2e7097)
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 {
19  constexpr struct select1st_t {
20  template <typename S, typename T>
21  const S& operator()( const std::pair<S, T>& p ) const
22  {
23  return p.first;
24  }
25  template <typename S, typename T>
26  S& operator()( std::pair<S, T>& p ) const
27  {
28  return p.first;
29  }
30  } select1st{};
31 }
32 // ===========================================================================
34 {
35  for ( const auto& cur : m_catalog ) {
36  for ( auto& prop : cur.second ) delete prop;
37  }
38 }
39 // ============================================================================
41 {
42  auto props = findProperties( client );
43  if ( props ) {
44  removeProperty( client, property->name() ).ignore();
45  props->push_back( property );
46  } else {
47  m_catalog.emplace( client, PropertiesT{property} );
48  }
49  return StatusCode::SUCCESS;
50 }
51 // ============================================================================
53 {
54  auto props = findProperties( client );
55  if ( props ) {
56  auto res = findProperty( *props, name );
57  if ( res.first ) {
58  delete *res.second;
59  props->erase( res.second );
60  }
61  }
62  return StatusCode::SUCCESS;
63 }
64 // ============================================================================
66 {
67  return findProperties( client );
68 }
69 // ============================================================================
71 {
73  result.reserve( m_catalog.size() );
74  std::transform( std::begin( m_catalog ), std::end( m_catalog ), std::back_inserter( result ), select1st );
75  return result;
76 }
77 // ============================================================================
79 {
80  auto result = m_catalog.find( client );
81  return ( result != m_catalog.end() ) ? &result->second : nullptr;
82 }
83 // ============================================================================
85 {
86  auto result = m_catalog.find( client );
87  return ( result != m_catalog.end() ) ? &result->second : nullptr;
88 }
89 // ============================================================================
91  const std::string& name ) const
92 {
93  auto p = std::find_if( std::begin( props ), std::end( props ), [&]( const Gaudi::Details::PropertyBase* prop ) {
94  return boost::iequals( name, prop->name() );
95  } );
96  return {p != std::end( props ), p};
97 }
98 // ============================================================================
100  const std::string& name )
101 {
102  auto p = std::find_if( std::begin( props ), std::end( props ), [&]( const Gaudi::Details::PropertyBase* prop ) {
103  return boost::iequals( name, prop->name() );
104  } );
105  return {p != std::end( props ), p};
106 }
107 // ============================================================================
109 {
110  // loop over the clients:
111  for ( const auto& iclient : m_catalog ) {
112  o << "Client '" << iclient.first << "'" << std::endl;
113  for ( const auto& p : iclient.second ) {
114  if ( p ) o << "\t" << ( *p ) << std::endl;
115  }
116  }
117  //
118  return o; // RETURN
119 }
121 {
122  auto props = findProperties( client );
123  if ( props ) {
124  const auto res = findProperty( *props, name );
125  if ( res.first ) {
126  return *res.second;
127  }
128  }
129  return nullptr;
130 }
131 // ============================================================================
132 // printoput operator
133 // ============================================================================
134 std::ostream& operator<<( std::ostream& o, const SvcCatalog& c ) { return c.fillStream( o ); }
135 // ============================================================================
136 // The END
137 // ============================================================================
const PropertiesT * getProperties(const std::string &client) const
Definition: SvcCatalog.cpp:65
std::ostream & fillStream(std::ostream &o) const
dump the content of catalog to std::ostream
Definition: SvcCatalog.cpp:108
const std::string name() const
property name
Definition: Property.h:40
T endl(T...args)
Gaudi::Details::PropertyBase * property(const std::string &name) const
T end(T...args)
StatusCode addProperty(const std::string &client, const Gaudi::Details::PropertyBase *property)
Definition: SvcCatalog.cpp:40
std::ostream & operator<<(std::ostream &o, const SvcCatalog &c)
printoput operator
Definition: SvcCatalog.cpp:134
StatusCode removeProperty(const std::string &client, const std::string &name)
Definition: SvcCatalog.cpp:52
std::vector< std::string > getClients() const
Definition: SvcCatalog.cpp:70
STL class.
const PropertiesT * findProperties(const std::string &client) const
Definition: SvcCatalog.cpp:78
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
std::pair< bool, PropertiesT::const_iterator > findProperty(const PropertiesT &props, const std::string &name) const
Definition: SvcCatalog.cpp:90
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
const Gaudi::Details::PropertyBase * getProperty(const std::string &client, const std::string &name) const
Definition: SvcCatalog.cpp:120
T find_if(T...args)
STL class.
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
T begin(T...args)
T back_inserter(T...args)
T transform(T...args)
STL class.
T reserve(T...args)