ATLAS Offline Software
Loading...
Searching...
No Matches
Control/AthenaKernel/AthenaKernel/ClassID_traits.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef ATHENAKERNEL_CLASSID_TRAITS_H
6#define ATHENAKERNEL_CLASSID_TRAITS_H
13
15#include "GaudiKernel/ClassID.h"
16
17#include <string>
18#include <typeinfo>
19#include <type_traits>
20#include <concepts>
21
22
24#define MY_STATIC_ASSERT( B ) \
25 static_assert (B, "You should use the CLASS_DEF macro to define CLID and VERSION")
27
36template <typename T>
38 // Always false, but needs to depend on T to prevent the assertions
39 // from being instantiated too early.
40 static const bool s_isDataObject = std::same_as<T, ClassID_trait_dummy>;
41 using has_classID_tag = std::false_type;
42 static const int s_version = 0;
43
44 static CLID ID() {
46 return CLID_NULL;
47 }
48
49 static const std::string& typeName() {
51 static const std::string dummy;
52 return dummy;
53 }
54
55 static const std::type_info& typeInfo() {
57 return typeid(int);
58 }
59};
60
61
67template <typename T>
68requires requires () {
69 { T::classID() } -> std::convertible_to<CLID>;
70}
71struct ClassID_traits<T> {
72 static const bool s_isDataObject = true;
73
75 static const CLID& ID() {
76 return T::classID();
77 }
78
80 static const std::string& typeName() {
81 static const std::string tname = Athena::typeinfoName(typeid(T));
82 return tname;
83 }
84
86 static const std::type_info& typeInfo() {
87 return typeid(T);
88 }
89
90 using has_version_tag = std::false_type;
91 using has_classID_tag = std::false_type;
92
93 static const int s_version = 0;
94
95 // Is this is true, these types will automatically be made
96 // const when added to StoreGate.
97 static const bool s_isConst = false;
98};
99
100#undef MY_STATIC_ASSERT
101
102#endif // not ATHENAKERNEL_CLASSID_TRAITS_H
An interface for getting the name of a class as a string.
#define MY_STATIC_ASSERT(B)
internal use: issues a compilation error when condition B is false
uint32_t CLID
The Class ID type.
std::string typeinfoName(const std::type_info &ti)
Convert a type_info to a demangled string.
static const std::string & typeName()
the demangled type name of T
static const std::type_info & typeInfo()
the type id of T
Default, invalid implementation of ClassID_traits.