The Gaudi Framework  v33r1 (b1225454)
SvcCatalog.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 // ============================================================================
12 // Include files
13 // ===========================================================================
14 // STD & STL:
15 // ===========================================================================
16 #include <iostream>
17 #include <sstream>
18 // ===========================================================================
19 // Boost:
20 // ===========================================================================
21 #include "boost/algorithm/string.hpp"
22 // ===========================================================================
23 // Local
24 // ===========================================================================
25 #include "SvcCatalog.h"
26 // ===========================================================================
27 namespace {
28  constexpr struct select1st_t {
29  template <typename S, typename T>
30  const S& operator()( const std::pair<S, T>& p ) const {
31  return p.first;
32  }
33  template <typename S, typename T>
34  S& operator()( std::pair<S, T>& p ) const {
35  return p.first;
36  }
37  } select1st{};
38 } // namespace
39 // ===========================================================================
41  for ( const auto& cur : m_catalog ) {
42  for ( auto& prop : cur.second ) delete prop;
43  }
44 }
45 // ============================================================================
47  auto props = findProperties( client );
48  if ( props ) {
49  removeProperty( client, property->name() ).ignore();
50  props->push_back( property );
51  } else {
52  m_catalog.emplace( client, PropertiesT{property} );
53  }
54  return StatusCode::SUCCESS;
55 }
56 // ============================================================================
58  auto props = findProperties( client );
59  if ( props ) {
60  auto res = findProperty( *props, name );
61  if ( res.first ) {
62  delete *res.second;
63  props->erase( res.second );
64  }
65  }
66  return StatusCode::SUCCESS;
67 }
68 // ============================================================================
70  return findProperties( client );
71 }
72 // ============================================================================
75  result.reserve( m_catalog.size() );
77  return result;
78 }
79 // ============================================================================
81  auto result = m_catalog.find( client );
82  return ( result != m_catalog.end() ) ? &result->second : nullptr;
83 }
84 // ============================================================================
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  auto p = std::find_if( std::begin( props ), std::end( props ), [&]( const Gaudi::Details::PropertyBase* prop ) {
93  return boost::iequals( name, prop->name() );
94  } );
95  return {p != std::end( props ), p};
96 }
97 // ============================================================================
99  const std::string& name ) {
100  auto p = std::find_if( std::begin( props ), std::end( props ), [&]( const Gaudi::Details::PropertyBase* prop ) {
101  return boost::iequals( name, prop->name() );
102  } );
103  return {p != std::end( props ), p};
104 }
105 // ============================================================================
107  // loop over the clients:
108  for ( const auto& iclient : m_catalog ) {
109  o << "Client '" << iclient.first << "'" << std::endl;
110  for ( const auto& p : iclient.second ) {
111  if ( p ) o << "\t" << ( *p ) << std::endl;
112  }
113  }
114  //
115  return o; // RETURN
116 }
118  const std::string& name ) const {
119  auto props = findProperties( client );
120  if ( props ) {
121  const auto res = findProperty( *props, name );
122  if ( res.first ) { return *res.second; }
123  }
124  return nullptr;
125 }
126 // ============================================================================
127 // printoput operator
128 // ============================================================================
129 std::ostream& operator<<( std::ostream& o, const SvcCatalog& c ) { return c.fillStream( o ); }
130 // ============================================================================
131 // The END
132 // ============================================================================
const PropertiesT * findProperties(const std::string &client) const
Definition: SvcCatalog.cpp:80
const PropertiesT * getProperties(const std::string &client) const
Definition: SvcCatalog.cpp:69
const Gaudi::Details::PropertyBase * getProperty(const std::string &client, const std::string &name) const
Definition: SvcCatalog.cpp:117
T endl(T... args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
T end(T... args)
StatusCode addProperty(const std::string &client, const Gaudi::Details::PropertyBase *property)
Definition: SvcCatalog.cpp:46
std::pair< bool, PropertiesT::const_iterator > findProperty(const PropertiesT &props, const std::string &name) const
Definition: SvcCatalog.cpp:90
const std::string name() const
property name
Definition: Property.h:46
std::ostream & operator<<(std::ostream &o, const SvcCatalog &c)
printoput operator
Definition: SvcCatalog.cpp:129
StatusCode removeProperty(const std::string &client, const std::string &name)
Definition: SvcCatalog.cpp:57
STL class.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
std::map< std::string, PropertiesT > m_catalog
Definition: SvcCatalog.h:57
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:42
std::vector< std::string > getClients() const
Definition: SvcCatalog.cpp:73
T find_if(T... args)
STL class.
T begin(T... args)
T back_inserter(T... args)
std::ostream & fillStream(std::ostream &o) const
dump the content of catalog to std::ostream
Definition: SvcCatalog.cpp:106
T transform(T... args)
STL class.
T reserve(T... args)