The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
Dictionary.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2024 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 <GaudiKernel/System.h>
12namespace GaudiDict {
13 std::string typeName( const std::type_info& typ );
14 std::string vectorName( const std::type_info& typ );
15 std::string vectorName( const std::string& typ );
16 std::string pairName( const std::type_info& typ1, const std::type_info& typ2 );
17 std::string relationName( const std::string& prefix, const std::type_info& typ1, const std::type_info& typ2 );
18 std::string templateName1( std::string templ, const std::type_info& typ );
19 std::string templateName1( std::string templ, const std::string& typ );
20 std::string templateName2( std::string templ, const std::type_info& typ1, const std::type_info& typ2 );
21 std::string templateName3( std::string templ, const std::type_info& typ1, const std::type_info& typ2,
22 const std::type_info& typ3 );
23 std::string keyedContainerName( const std::string& prefix, const std::type_info& typ1 );
24} // namespace GaudiDict
25
26static std::string clean( std::string c ) {
27 for ( size_t occ = c.find( " *" ); occ != std::string::npos; occ = c.find( " *" ) ) c.replace( occ, 2, "*" );
28 return c;
29}
30
31std::string GaudiDict::typeName( const std::type_info& typ ) {
32 std::string r = clean( System::typeinfoName( typ ) );
33 // if ( r.compare(0,4,"enum") == 0 ) {
34 // r = "int";
35 //}
36 return r;
37}
38
39std::string GaudiDict::templateName1( std::string templ, const std::type_info& typ ) {
40 return templateName1( std::move( templ ), typeName( typ ) );
41}
42
43std::string GaudiDict::templateName1( std::string s, const std::string& typ ) {
44 s += "<";
45 s += typ;
46 s += ( s.back() == '>' ) ? " >" : ">"; // with C++11, we can have <somename<T>>...
47 return clean( s );
48}
49
50std::string GaudiDict::templateName2( std::string s, const std::type_info& typ1, const std::type_info& typ2 ) {
51 s += "<";
52 s += typeName( typ1 );
53 s += ",";
54 s += typeName( typ2 );
55 s += ( s.back() == '>' ) ? " >" : ">";
56 return clean( s );
57}
58
59std::string GaudiDict::templateName3( std::string s, const std::type_info& typ1, const std::type_info& typ2,
60 const std::type_info& typ3 ) {
61 s += "<";
62 s += typeName( typ1 );
63 s += ",";
64 s += typeName( typ2 );
65 s += ",";
66 s += typeName( typ3 );
67 s += ( s.back() == '>' ) ? " >" : ">";
68 return clean( s );
69}
70
71std::string GaudiDict::vectorName( const std::type_info& typ ) { return templateName1( "std::vector", typ ); }
72
73std::string GaudiDict::vectorName( const std::string& typ ) { return templateName1( "std::vector", typ ); }
74
75std::string GaudiDict::pairName( const std::type_info& typ1, const std::type_info& typ2 ) {
76 return templateName2( "std::pair", typ1, typ2 );
77}
78
79std::string GaudiDict::keyedContainerName( const std::string& mgr_typ, const std::type_info& typ1 ) {
80 std::string s = "KeyedContainer<";
81 s += typeName( typ1 );
82 s += ",";
83 s += mgr_typ;
84 if ( mgr_typ[mgr_typ.length() - 1] == '>' ) s += " ";
85 s += ">";
86 return clean( s );
87}
88
89std::string GaudiDict::relationName( const std::string& /* prefix */, const std::type_info& /* typ1 */,
90 const std::type_info& /* typ2 */ ) {
91 return "";
92}
std::string templateName3(std::string templ, const std::type_info &typ1, const std::type_info &typ2, const std::type_info &typ3)
std::string templateName1(std::string templ, const std::type_info &typ)
std::string vectorName(const std::type_info &typ)
std::string typeName(const std::type_info &typ)
std::string pairName(const std::type_info &typ1, const std::type_info &typ2)
std::string templateName2(std::string templ, const std::type_info &typ1, const std::type_info &typ2)
std::string relationName(const std::string &prefix, const std::type_info &typ1, const std::type_info &typ2)
std::string keyedContainerName(const std::string &prefix, const std::type_info &typ1)
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition System.cpp:260