Project
Loading...
Searching...
No Matches
TypeIdHelpers.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef O2_FRAMEWORK_TYPEIDHELPERS_H_
13#define O2_FRAMEWORK_TYPEIDHELPERS_H_
14
15#include <string_view>
16#if __cplusplus >= 202002L
17#include <source_location>
18#endif
20
21namespace o2::framework
22{
23#if defined(__CLING__) || __cplusplus < 202002L
24template <typename T>
26 static constexpr auto get() noexcept
27 {
28 constexpr std::string_view full_name{__PRETTY_FUNCTION__};
29 return full_name;
30 }
31
32 static constexpr std::string_view value{get()};
33};
34
35template <typename T>
37#endif
38
39#if !defined(__CLING__) && __cplusplus >= 202002L
41template <typename T>
42consteval static std::string_view type_name_impl(T*)
43{
44 return std::source_location::current().function_name();
45}
46#endif
47
50template <typename T>
51constexpr static std::string_view type_name()
52{
53#if defined(__CLING__) || __cplusplus < 202002L
54 constexpr std::string_view wrapped_name{unique_type_id_v<T>};
55#else
56 constexpr std::string_view wrapped_name = type_name_impl<T>(nullptr);
57#endif
58 const std::string_view left_marker{"T = "};
59#if !defined(__clang__) && __cplusplus >= 202002L
60 const std::string_view right_marker{";"};
61#else
62 const std::string_view right_marker{"]"};
63#endif
64
65 const auto left_marker_index = wrapped_name.find(left_marker);
66 const auto start_index = left_marker_index + left_marker.size();
67 const auto end_index = wrapped_name.find(right_marker, left_marker_index);
68 const auto length = end_index - start_index;
69 return wrapped_name.substr(start_index, length);
70}
71
73 template <typename T>
74 constexpr static uint32_t uniqueId()
75 {
76#ifdef __CLING__
77 return crc32(unique_type_id_v<T>.data(), unique_type_id_v<T>.size());
78#else
79 return crc32(type_name<T>().data(), type_name<T>().size());
80#endif
81 }
82};
83
84} // namespace o2::framework
85
86#endif // O2_FRAMEWORK_TYPEIDHELPERS_H_
consteval uint32_t crc32(char const *str, int length)
GLsizeiptr size
Definition glcorearb.h:659
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLboolean * data
Definition glcorearb.h:298
GLuint GLsizei GLsizei * length
Definition glcorearb.h:790
Defining PrimaryVertex explicitly as messageable.
constexpr auto unique_type_id_v
static constexpr uint32_t uniqueId()
static constexpr auto get() noexcept