| The Gaudi Framework v32r1 (f65d50dc)

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