| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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 // ===========================================================================
26 SvcCatalog::~SvcCatalog()
27 {
28 for (const auto& cur : m_catalog)
29 {
30 for (auto & prop : cur.second) delete prop;
31 }
32 }
33 // ============================================================================
34 StatusCode SvcCatalog::addProperty
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 // ============================================================================
48 StatusCode
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 // ============================================================================
63 const SvcCatalog::PropertiesT*
64 SvcCatalog::getProperties
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 // ============================================================================
75 const SvcCatalog::PropertiesT*
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 // ============================================================================
83 SvcCatalog::PropertiesT*
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>
92 SvcCatalog::findProperty
93 ( SvcCatalog::PropertiesT& props ,
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 // ============================================================================
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
SvcCatalog::getProperties
const PropertiesT * getProperties(const std::string &client) const
Definition: SvcCatalog.cpp:65
Property::name
const std::string & name() const
property name
Definition: Property.h:45
SvcCatalog::fillStream
std::ostream & fillStream(std::ostream &o) const
dump the content of catalog to std::ostream
Definition: SvcCatalog.cpp:103
select1st
constexpr struct select1st_t select1st
gaudirun.c
tuple c
Definition: gaudirun.py:391
SvcCatalog::~SvcCatalog
~SvcCatalog()
Definition: SvcCatalog.cpp:26
std::endl
T endl(T...args)
SvcCatalog::addProperty
StatusCode addProperty(const std::string &client, const Property *property)
Definition: SvcCatalog.cpp:35
std::end
T end(T...args)
operator<<
std::ostream & operator<<(std::ostream &o, const SvcCatalog &c)
printoput operator
Definition: SvcCatalog.cpp:120
SvcCatalog::removeProperty
StatusCode removeProperty(const std::string &client, const std::string &name)
Definition: SvcCatalog.cpp:49
SvcCatalog::getClients
std::vector< std::string > getClients() const
Definition: SvcCatalog.cpp:67
std::string
STL class.
SvcCatalog::findProperties
const PropertiesT * findProperties(const std::string &client) const
Definition: SvcCatalog.cpp:76
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
SvcCatalog::m_catalog
std::map< std::string, PropertiesT > m_catalog
Definition: SvcCatalog.h:46
std::pair
std::find_if
T find_if(T...args)
Property
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
std::vector
STL class.
std::begin
T begin(T...args)
select1st_t::operator()
const S & operator()(const std::pair< S, T > &p) const
Definition: capi_pluginservice.cpp:25
SvcCatalog.h
std::back_inserter
T back_inserter(T...args)
std::transform
T transform(T...args)
SvcCatalog
Definition: SvcCatalog.h:25
std::ostream
STL class.
SvcCatalog::findProperty
std::pair< bool, PropertiesT::iterator > findProperty(PropertiesT &props, const std::string &name)
Definition: SvcCatalog.cpp:93
std::vector::reserve
T reserve(T...args)