| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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