DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
convenience.hpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
3// Fork baseline commit: dbe-02-12-17 (2022-05-12).
4// Renamed since fork: yes (from dbe/convenience.hpp to include/dbe/convenience.hpp).
5
6/************************************************************
7 * convenience.hpp *
8 * *
9 * Created on: 1 Mar 2014 *
10 * Author: Leonidas Georgopoulos *
11 *
12 * Copyright (C) 2014 Leonidas Georgopoulos
13 * Distributed under the Boost Software License, Version 1.0.
14 * (See accompanying file LICENSE_1_0.txt or
15 * copy at http://www.boost.org/LICENSE_1_0.txt)
16 *
17 ************************************************************/
18
19#ifndef LUTILS_CONVENIENCE_HPP_
20#define LUTILS_CONVENIENCE_HPP_
21
22/*
23 * STL inclusions
24 */
25#include <memory>
26#include <string>
27#include <typeinfo>
28
29/*
30 * G++ demangle
31 */
32#ifdef __GNUG__
33#include <cstdlib>
34#include <cxxabi.h>
35#endif
36
37namespace tools {
38//------------------------------------------------------------------------------
42template<typename T>
44{
45public:
46 typedef std::string t_is;
47
48 static t_is constexpr isnot();
49
50 static t_is constexpr isa();
51
52#ifdef __GNUG__
53 static t_is constexpr filt();
54#endif
55};
56//------------------------------------------------------------------------------
57
58//------------------------------------------------------------------------------
64template<typename T>
65typename gentraits<T>::t_is constexpr filt(T*)
66{
67 return gentraits<T>::filt();
68}
69//------------------------------------------------------------------------------
70
71//------------------------------------------------------------------------------
76template<typename T>
78{
79 return t_is("ISNOT");
80}
81//------------------------------------------------------------------------------
82
83//------------------------------------------------------------------------------
88template<typename T>
90{
91 return typeid(T).name();
92}
93//------------------------------------------------------------------------------
94
95//------------------------------------------------------------------------------
96#ifdef __GNUG__
97template<typename T>
98typename gentraits<T>::t_is constexpr gentraits<T>::filt()
99{
100 int status = -42;
101 char* res = abi::__cxa_demangle(typeid(T).name(), NULL, NULL, &status);
102
103 if (status != 0) {
104 ::free(res);
105 return isnot();
106 } else {
107 typename gentraits<T>::t_is result = res;
108 ::free(res);
109 return result;
110 }
111}
112#endif
113//------------------------------------------------------------------------------
114
115//------------------------------------------------------------------------------
121template<typename A, typename B>
122typename gentraits<A>::t_is const
123isa(B const&)
124{
125 return typeid(A).name() == typeid(B).name() ? typeid(A).name() : gentraits<A>::isnot();
126}
127//------------------------------------------------------------------------------
128
129} /* namespace tools */
130
131#endif
std::string t_is
static t_is constexpr isnot()
static t_is constexpr isa()
gentraits< T >::t_is constexpr filt(T *)
gentraits< A >::t_is const isa(B const &)