The Gaudi Framework  v41r0 (bdbe7744)
Loading...
Searching...
No Matches
TypeNameString.h
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#pragma once
12#include <ostream>
13#include <string>
14#include <utility>
15
16namespace Gaudi {
17 namespace Utils {
20 std::string m_type, m_name;
22
23 public:
24 template <size_t N>
25 TypeNameString( const char ( &tn )[N] ) : TypeNameString{ std::string_view{ tn } } {}
26 TypeNameString( std::string_view sv ) : TypeNameString{ std::string{ sv } } {}
27 TypeNameString( std::string tn ) : m_type{ std::move( tn ) } {
28 const auto slash_pos = m_type.find_first_of( "/" );
29 m_haveType = slash_pos != std::string::npos;
30 if ( m_haveType ) {
31 m_name = m_type.substr( slash_pos + 1 );
32 m_type.resize( slash_pos );
33 } else
34 m_name = m_type;
35 }
36
37 TypeNameString( std::string tn, std::string_view deftyp ) : TypeNameString( std::move( tn ) ) {
38 if ( !m_haveType ) m_type = deftyp;
39 }
40
41 // support passing a Gaudi::Property<std::string> without having to include Property.h
42 // require that prop.value() can be used to construct a TypeNameString...
43 template <class T>
44 requires( std::is_constructible_v<TypeNameString, decltype( std::declval<const T&>().value() )> )
45 TypeNameString( const T& prop ) : TypeNameString( prop.value() ) {}
46
47 const std::string& type() const { return m_type; }
48 const std::string& name() const { return m_name; }
49 bool haveType() const { return m_haveType; }
50 };
51
53 inline std::ostream& operator<<( std::ostream& s, const TypeNameString& tn ) {
54 return s << tn.type() << '/' << tn.name();
55 }
56 } // namespace Utils
57} // namespace Gaudi
Helper class to parse a string of format "type/name".
TypeNameString(std::string_view sv)
TypeNameString(const char(&tn)[N])
TypeNameString(std::string tn, std::string_view deftyp)
const std::string & type() const
const std::string & name() const
STL class.
std::ostream & operator<<(std::ostream &s, const TypeNameString &tn)
Output stream operator for TypeNameString instances.
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1
STL namespace.