The Gaudi Framework  v36r6 (b1ee9983)
TypeNameString.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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 #ifndef GAUDIKERNEL_TYPENAMESTRING_H
12 #define GAUDIKERNEL_TYPENAMESTRING_H
13 #include <ostream>
14 #include <string>
15 #include <utility>
16 
17 namespace Gaudi {
18  namespace Utils {
22  bool m_haveType;
23 
24  public:
25  template <size_t N>
26  TypeNameString( const char ( &tn )[N] ) : TypeNameString{ std::string_view{ tn } } {}
27  TypeNameString( std::string_view sv ) : TypeNameString{ std::string{ sv } } {}
29  const auto slash_pos = m_type.find_first_of( "/" );
30  m_haveType = slash_pos != std::string::npos;
31  if ( m_haveType ) {
32  m_name = m_type.substr( slash_pos + 1 );
33  m_type = m_type.substr( 0, slash_pos );
34  } else
35  m_name = m_type;
36  }
37 
38  TypeNameString( std::string tn, std::string_view deftyp ) : TypeNameString( std::move( tn ) ) {
39  if ( !m_haveType ) m_type = deftyp;
40  }
41 
42  // support passing a Gaudi::Property<std::string> without having to include Property.h
43  // require that prop.value() can be used to construct a TypeNameString...
44  template <class T, typename = std::enable_if_t<std::is_constructible<
45  TypeNameString, decltype( std::declval<const T&>().value() )>::value>>
46  TypeNameString( const T& prop ) : TypeNameString( prop.value() ) {}
47 
48  const std::string& type() const { return m_type; }
49  const std::string& name() const { return m_name; }
50  bool haveType() const { return m_haveType; }
51  };
52 
55  return s << tn.type() << '/' << tn.name();
56  }
57  } // namespace Utils
58 } // namespace Gaudi
59 
60 #endif // GAUDIKERNEL_TYPENAMESTRING_H
Gaudi::Utils::TypeNameString::TypeNameString
TypeNameString(const T &prop)
Definition: TypeNameString.h:46
Gaudi::Utils::TypeNameString::m_name
std::string m_name
Definition: TypeNameString.h:21
std::string
STL class.
Gaudi::Utils::TypeNameString::name
const std::string & name() const
Definition: TypeNameString.h:49
std::move
T move(T... args)
Gaudi::Utils::TypeNameString::m_type
std::string m_type
Definition: TypeNameString.h:21
Gaudi::Utils::operator<<
std::ostream & operator<<(std::ostream &s, const TypeNameString &tn)
Output stream operator for TypeNameString instances.
Definition: TypeNameString.h:54
gaudirun.s
string s
Definition: gaudirun.py:346
IOTest.N
int N
Definition: IOTest.py:115
Gaudi::Utils::TypeNameString::TypeNameString
TypeNameString(std::string tn)
Definition: TypeNameString.h:28
Gaudi::Utils::TypeNameString
Helper class to parse a string of format "type/name".
Definition: TypeNameString.h:20
std::ostream
STL class.
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
Gaudi::Utils::TypeNameString::type
const std::string & type() const
Definition: TypeNameString.h:48
std::string::substr
T substr(T... args)
Gaudi::Utils::TypeNameString::TypeNameString
TypeNameString(const char(&tn)[N])
Definition: TypeNameString.h:26
std
STL namespace.
Gaudi::Utils::TypeNameString::TypeNameString
TypeNameString(std::string_view sv)
Definition: TypeNameString.h:27
Gaudi::Utils::TypeNameString::TypeNameString
TypeNameString(std::string tn, std::string_view deftyp)
Definition: TypeNameString.h:38
Gaudi::Utils::TypeNameString::haveType
bool haveType() const
Definition: TypeNameString.h:50
std::string::find_first_of
T find_first_of(T... args)
std::is_constructible
Gaudi::Utils::TypeNameString::m_haveType
bool m_haveType
Definition: TypeNameString.h:22