The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
Catalog.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 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
14namespace gp = Gaudi::Parsers;
15namespace {
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
28std::vector<std::string> gp::Catalog::ClientNames() const {
29 std::vector<std::string> result;
30 std::transform( std::begin( catalog_ ), std::end( catalog_ ), std::back_inserter( result ), select1st );
31 return result;
32}
33bool gp::Catalog::Add( Property* property ) {
34 assert( property );
35 auto it = catalog_.find( property->ClientName() );
36 if ( it == catalog_.end() ) {
37 CatalogSet::mapped_type properties;
38 properties.insert( property );
39 catalog_.emplace( property->ClientName(), properties );
40 return true;
41 }
42 it->second.erase( *property );
43 it->second.insert( property );
44 // TODO: check return value
45 return true;
46}
47gp::Property* gp::Catalog::Find( std::string_view client, std::string_view name ) {
48 auto it = catalog_.find( client );
49 if ( it == catalog_.end() ) return nullptr;
50
51 auto pit = std::find_if( it->second.begin(), it->second.end(),
52 [&]( const Property& property ) { return name == property.NameInClient(); } );
53
54 return ( pit != it->second.end() ) ? &*pit : nullptr;
55}
56std::string gp::Catalog::ToString() const {
57 std::string result;
58 for ( const auto& client : catalog_ ) {
59 for ( const auto& current : client.second ) { result += current.ToString() + "\n"; }
60 }
61 return result;
62}
63std::ostream& Gaudi::Parsers::Catalog::fillStream( std::ostream& o ) const {
64 o << R"(// ==================================================================================
65// Parser catalog
66// ==================================================================================
67)";
68
69 size_t nComponents = 0;
70 size_t nProperties = 0;
71
72 for ( const auto& client : catalog_ ) {
73 o << fmt::format( "// Properties of {:<25} # = {}", fmt::format( "'{}'", client.first ), client.second.size() );
74 ++nComponents;
75 nProperties += client.second.size();
76 for ( const auto& current : client.second ) {
77 o << fmt::format( "{:<44} = {} ;", current.FullName(), current.ValueAsString() );
78 }
79 }
80 o << fmt::format( R"(// ==================================================================================
81// End parser catalog #Components={} #Properties={}
82// ==================================================================================
83)",
84 nComponents, nProperties );
85 return o;
86}
Property * Find(std::string_view client, std::string_view name)
Definition Catalog.cpp:47
bool Add(Property *property)
Definition Catalog.cpp:33
CatalogSet catalog_
Definition Catalog.h:46
std::vector< std::string > ClientNames() const
Definition Catalog.cpp:28
std::string ToString() const
Definition Catalog.cpp:56
std::ostream & fillStream(std::ostream &out) const
print the content of the catalogue to std::ostream
Definition Catalog.cpp:63
const std::string & ClientName() const
Definition Property.cpp:21