The Gaudi Framework  v33r1 (b1225454)
Catalog.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 // ============================================================================
12 #include "Catalog.h"
13 // ============================================================================
14 // Boost:
15 // ============================================================================
16 #include <boost/format.hpp>
17 // ============================================================================
18 // Namesapce aliases:
19 // ============================================================================
20 namespace gp = Gaudi::Parsers;
21 // ============================================================================
22 namespace {
23  constexpr struct select1st_t {
24  template <typename S, typename T>
25  const S& operator()( const std::pair<S, T>& p ) const {
26  return p.first;
27  }
28  template <typename S, typename T>
29  S& operator()( std::pair<S, T>& p ) const {
30  return p.first;
31  }
32  } select1st{};
33 } // namespace
34 // ============================================================================
35 std::vector<std::string> gp::Catalog::ClientNames() const {
37  std::transform( std::begin( catalog_ ), std::end( catalog_ ), std::back_inserter( result ), select1st );
38  return result;
39 }
40 // ============================================================================
41 bool gp::Catalog::Add( Property* property ) {
42  assert( property );
43  auto it = catalog_.find( property->ClientName() );
44  if ( it == catalog_.end() ) {
45  CatalogSet::mapped_type properties;
46  properties.insert( property );
47  catalog_.emplace( property->ClientName(), properties );
48  return true;
49  }
50  it->second.erase( *property );
51  it->second.insert( property );
52  // TODO: check return value
53  return true;
54 }
55 // ============================================================================
56 gp::Property* gp::Catalog::Find( const std::string& client, const std::string& name ) {
57  auto it = catalog_.find( client );
58  if ( it == catalog_.end() ) return nullptr;
59 
60  auto pit = std::find_if( it->second.begin(), it->second.end(), Property::Equal( name ) );
61  return ( pit != it->second.end() ) ? &*pit : nullptr;
62 }
63 // ============================================================================
64 std::string gp::Catalog::ToString() const {
65  std::string result;
66  for ( const auto& client : catalog_ ) {
67  for ( const auto& current : client.second ) { result += current.ToString() + "\n"; }
68  }
69  return result;
70 }
71 // ============================================================================
72 // print the content of the catalogue to std::ostream
73 // ============================================================================
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 }
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
T endl(T... args)
T end(T... args)
Gaudi::Details::PropertyBase Property
\fixme backward compatibility hack for old Property base class
Definition: PropertyFwd.h:35
STL class.
const std::string & ClientName() const
Definition: Property.cpp:23
std::ostream & fillStream(std::ostream &out) const
print the content of the catalogue to std::ostream
Definition: Catalog.cpp:74
T find_if(T... args)
T size(T... args)
T begin(T... args)
T back_inserter(T... args)
T transform(T... args)
CatalogSet catalog_
Definition: Catalog.h:63
STL class.