| The Gaudi Framework v32r1 (f65d50dc)

TypeNameString.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_TYPENAMESTRING_H
2 #define GAUDIKERNEL_TYPENAMESTRING_H
3 #include <ostream>
4 #include <string>
5 #include <utility>
6
7 namespace Gaudi {
8 namespace Utils {
10 class TypeNameString {
11 std::string m_type, m_name;
12 bool m_haveType;
13
14 public:
15 TypeNameString( const char tn[] ) : TypeNameString( std::string{tn} ) {}
16 TypeNameString( const std::string& tn ) : m_type{tn} {
17 const auto slash_pos = m_type.find_first_of( "/" );
18 m_haveType = slash_pos != std::string::npos;
19 if ( m_haveType ) {
20 m_name = m_type.substr( slash_pos + 1 );
21 m_type = m_type.substr( 0, slash_pos );
22 } else
23 m_name = m_type;
24 }
25
26 TypeNameString( const std::string& tn, const std::string& deftyp ) : TypeNameString( tn ) {
27 if ( !m_haveType ) m_type = deftyp;
28 }
29
30 // support passing a Gaudi::Property<std::string> without having to include Property.h
31 // require that prop.value() can be used to construct a TypeNameString...
32 template <class T, typename = std::enable_if_t<std::is_constructible<
33 TypeNameString, decltype( std::declval<const T&>().value() )>::value>>
34 TypeNameString( const T& prop ) : TypeNameString( prop.value() ) {}
35
36 const std::string& type() const { return m_type; }
37 const std::string& name() const { return m_name; }
38 bool haveType() const { return m_haveType; }
39 };
40
42 inline std::ostream& operator<<( std::ostream& s, const TypeNameString& tn ) {
43 return s << tn.type() << '/' << tn.name();
44 }
45 } // namespace Utils
46 } // namespace Gaudi
47
48 #endif // GAUDIKERNEL_TYPENAMESTRING_H
Gaudi::Utils::TypeNameString::haveType
bool haveType() const
Definition: TypeNameString.h:38
Gaudi::Utils::operator<<
std::ostream & operator<<(std::ostream &s, const TypeNameString &tn)
Output stream operator for TypeNameString instances.
Definition: TypeNameString.h:42
std
STL namespace.
Gaudi::Utils::TypeNameString::m_haveType
bool m_haveType
Definition: TypeNameString.h:12
Gaudi::Utils::TypeNameString::type
const std::string & type() const
Definition: TypeNameString.h:36
std::is_constructible
std::string
STL class.
Gaudi::Utils::TypeNameString
Helper class to parse a string of format "type/name".
Definition: TypeNameString.h:10
Gaudi::Utils::TypeNameString::name
const std::string & name() const
Definition: TypeNameString.h:37
Gaudi::Utils::TypeNameString::TypeNameString
TypeNameString(const char tn[])
Definition: TypeNameString.h:15
std::string::find_first_of
T find_first_of(T... args)
Gaudi::Utils::TypeNameString::TypeNameString
TypeNameString(const T &prop)
Definition: TypeNameString.h:34
Gaudi::Utils::TypeNameString::TypeNameString
TypeNameString(const std::string &tn, const std::string &deftyp)
Definition: TypeNameString.h:26
gaudirun.s
string s
Definition: gaudirun.py:316
std::string::substr
T substr(T... args)
Gaudi::Utils::TypeNameString::m_name
std::string m_name
Definition: TypeNameString.h:11
Gaudi::Utils::TypeNameString::TypeNameString
TypeNameString(const std::string &tn)
Definition: TypeNameString.h:16
std::ostream
STL class.
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
Gaudi::Utils::TypeNameString::m_type
std::string m_type
Definition: TypeNameString.h:11