| The Gaudi Framework v29r0 (ff2e7097)

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

- File List
- File Members

Catalog.cpp
Go to the documentation of this file.
1 // ============================================================================
2 #include "Catalog.h"
3 // ============================================================================
4 // Boost:
5 // ============================================================================
6 #include <boost/format.hpp>
7 // ============================================================================
8 // Namesapce aliases:
9 // ============================================================================
10 namespace gp = Gaudi::Parsers;
11 // ============================================================================
12 namespace
13 {
14 constexpr struct select1st_t {
15 template <typename S, typename T>
16 const S& operator()( const std::pair<S, T>& p ) const
17 {
18 return p.first;
19 }
20 template <typename S, typename T>
21 S& operator()( std::pair<S, T>& p ) const
22 {
23 return p.first;
24 }
25 } select1st{};
26 }
27 // ============================================================================
28 std::vector<std::string> gp::Catalog::ClientNames() const
29 {
30 std::vector<std::string> result;
31 std::transform( std::begin( catalog_ ), std::end( catalog_ ), std::back_inserter( result ), select1st );
32 return result;
33 }
34 // ============================================================================
35 bool gp::Catalog::Add( Property* property )
36 {
37 assert( property );
38 auto it = catalog_.find( property->ClientName() );
39 if ( it == catalog_.end() ) {
40 CatalogSet::mapped_type properties;
41 properties.insert( property );
42 catalog_.emplace( property->ClientName(), properties );
43 return true;
44 }
45 it->second.erase( *property );
46 it->second.insert( property );
47 // TODO: check return value
48 return true;
49 }
50 // ============================================================================
51 gp::Property* gp::Catalog::Find( const std::string& client, const std::string& name )
52 {
53 auto it = catalog_.find( client );
54 if ( it == catalog_.end() ) return nullptr;
55
56 auto pit = std::find_if( it->second.begin(), it->second.end(), Property::Equal( name ) );
57 return ( pit != it->second.end() ) ? &*pit : nullptr;
58 }
59 // ============================================================================
60 std::string gp::Catalog::ToString() const
61 {
62 std::string result;
63 for ( const auto& client : catalog_ ) {
64 for ( const auto& current : client.second ) {
65 result += current.ToString() + "\n";
66 }
67 }
68 return result;
69 }
70 // ============================================================================
71 // print the content of the catalogue to std::ostream
72 // ============================================================================
73 std::ostream& Gaudi::Parsers::Catalog::fillStream( std::ostream& o ) const
74 {
75 o << "// " << std::string( 82, '=' ) << std::endl
76 << "// Parser catalog " << std::endl
77 << "// " << std::string( 82, '=' ) << std::endl;
78
79 size_t nComponents = 0;
80 size_t nProperties = 0;
81
82 for ( const auto& client : catalog_ ) {
83 o << boost::format( "// Properties of '%1%' %|43t|# = %2%" ) % client.first % client.second.size() << std::endl;
84 ++nComponents;
85 nProperties += client.second.size();
86 for ( const auto& current : client.second ) {
87 o << boost::format( "%1% %|44t| = %2% ; " ) % current.FullName() % current.ValueAsString() << '\n';
88 }
89 }
90 o << "// " << std::string( 82, '=' ) << '\n'
91 << boost::format( "// End parser catalog #Components=%1% #Properties=%2%" ) % nComponents % nProperties << '\n'
92 << "// " << std::string( 82, '=' ) << std::endl;
93 return o;
94 }
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:120
Gaudi::Parsers::Catalog::fillStream
std::ostream & fillStream(std::ostream &out) const
print the content of the catalogue to std::ostream
Definition: Catalog.cpp:73
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
Gaudi::Parsers::Property
Definition: Property.h:19
std::endl
T endl(T...args)
property
Gaudi::Details::PropertyBase * property(const std::string &name) const
std::end
T end(T...args)
Property
Gaudi::Details::PropertyBase Property
backward compatibility hack for old Property base class
Definition: PropertyFwd.h:28
Catalog.h
std::string
STL class.
std::pair
std::find_if
T find_if(T...args)
std::string::size
T size(T...args)
std::vector< std::string >
Gaudi::Functional::operator()
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
gaudiComponentHelp.properties
properties
Definition: gaudiComponentHelp.py:41
std::begin
T begin(T...args)
std::back_inserter
T back_inserter(T...args)
Gaudi::Parsers
Definition: DODBasicMapper.cpp:8
Gaudi::Parsers::Property::ClientName
const std::string & ClientName() const
Definition: Property.cpp:23
std::transform
T transform(T...args)
std::ostream
STL class.