Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 {
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 // ============================================================================
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 }
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:109
std::ostream & fillStream(std::ostream &out) const
print the content of the catalogue to std::ostream
Definition: Catalog.cpp:64
T endl(T...args)
Gaudi::Details::PropertyBase * property(const std::string &name) const
T end(T...args)
Gaudi::Details::PropertyBase Property
backward compatibility hack for old Property base class
Definition: PropertyFwd.h:25
STL class.
T find_if(T...args)
T size(T...args)
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
T begin(T...args)
T back_inserter(T...args)
const std::string & ClientName() const
Definition: Property.cpp:23
T transform(T...args)
STL class.