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