| The Gaudi Framework v28r2-patches (bc4ad17a)

- 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 {
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 // ===========================================================================
33 SvcCatalog::~SvcCatalog()
34 {
35 for ( const auto& cur : m_catalog ) {
36 for ( auto& prop : cur.second ) delete prop;
37 }
38 }
39 // ============================================================================
40 StatusCode SvcCatalog::addProperty( const std::string& client, const Gaudi::Details::PropertyBase* property )
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 // ============================================================================
52 StatusCode SvcCatalog::removeProperty( const std::string& client, const std::string& name )
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 // ============================================================================
65 const SvcCatalog::PropertiesT* SvcCatalog::getProperties( const std::string& client ) const
66 {
67 return findProperties( client );
68 }
69 // ============================================================================
70 std::vector<std::string> SvcCatalog::getClients() const
71 {
72 std::vector<std::string> result;
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 // ============================================================================
78 const SvcCatalog::PropertiesT* SvcCatalog::findProperties( const std::string& client ) const
79 {
80 auto result = m_catalog.find( client );
81 return ( result != m_catalog.end() ) ? &result->second : nullptr;
82 }
83 // ============================================================================
84 SvcCatalog::PropertiesT* SvcCatalog::findProperties( const std::string& client )
85 {
86 auto result = m_catalog.find( client );
87 return ( result != m_catalog.end() ) ? &result->second : nullptr;
88 }
89 // ============================================================================
90 std::pair<bool, SvcCatalog::PropertiesT::const_iterator> SvcCatalog::findProperty( const SvcCatalog::PropertiesT& props,
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 // ============================================================================
99 std::pair<bool, SvcCatalog::PropertiesT::iterator> SvcCatalog::findProperty( SvcCatalog::PropertiesT& props,
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 // ============================================================================
108 std::ostream& SvcCatalog::fillStream( std::ostream& o ) const
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 }
120 const Gaudi::Details::PropertyBase* SvcCatalog::getProperty( const std::string& client, const std::string& name ) const
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 // ============================================================================
StatusCode::SUCCESS
Definition: StatusCode.h:30
gaudirun.c
c
Definition: gaudirun.py:391
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
SvcCatalog::getProperties
const PropertiesT * getProperties(const std::string &client) const
Definition: SvcCatalog.cpp:65
SvcCatalog::fillStream
std::ostream & fillStream(std::ostream &o) const
dump the content of catalog to std::ostream
Definition: SvcCatalog.cpp:108
Gaudi::Details::PropertyBase::name
const std::string name() const
property name
Definition: Property.h:40
SvcCatalog::~SvcCatalog
~SvcCatalog()
Definition: SvcCatalog.cpp:33
std::endl
T endl(T...args)
property
Gaudi::Details::PropertyBase * property(const std::string &name) const
std::end
T end(T...args)
SvcCatalog::addProperty
StatusCode addProperty(const std::string &client, const Gaudi::Details::PropertyBase *property)
Definition: SvcCatalog.cpp:40
operator<<
std::ostream & operator<<(std::ostream &o, const SvcCatalog &c)
printoput operator
Definition: SvcCatalog.cpp:134
SvcCatalog::removeProperty
StatusCode removeProperty(const std::string &client, const std::string &name)
Definition: SvcCatalog.cpp:52
SvcCatalog::getClients
std::vector< std::string > getClients() const
Definition: SvcCatalog.cpp:70
std::string
STL class.
SvcCatalog::findProperties
const PropertiesT * findProperties(const std::string &client) const
Definition: SvcCatalog.cpp:78
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
SvcCatalog::findProperty
std::pair< bool, PropertiesT::const_iterator > findProperty(const PropertiesT &props, const std::string &name) const
Definition: SvcCatalog.cpp:90
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
SvcCatalog::getProperty
const Gaudi::Details::PropertyBase * getProperty(const std::string &client, const std::string &name) const
Definition: SvcCatalog.cpp:120
std::pair
std::find_if
T find_if(T...args)
std::vector
STL class.
Gaudi::Functional::operator()
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
std::begin
T begin(T...args)
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.
std::vector::reserve
T reserve(T...args)