DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
convenience.hpp
Go to the documentation of this file.
1/************************************************************
2 * convenience.hpp *
3 * *
4 * Created on: 1 Mar 2014 *
5 * Author: Leonidas Georgopoulos *
6 *
7 * Copyright (C) 2014 Leonidas Georgopoulos
8 * Distributed under the Boost Software License, Version 1.0.
9 * (See accompanying file LICENSE_1_0.txt or
10 * copy at http://www.boost.org/LICENSE_1_0.txt)
11 *
12 ************************************************************/
13
14#ifndef LUTILS_CONVENIENCE_HPP_
15#define LUTILS_CONVENIENCE_HPP_
16
17/*
18 * STL inclusions
19 */
20#include <memory>
21#include <string>
22#include <typeinfo>
23
24/*
25 * G++ demangle
26 */
27#ifdef __GNUG__
28#include <cstdlib>
29#include <cxxabi.h>
30#endif
31
32namespace tools
33{
34//------------------------------------------------------------------------------
38template<typename T> class gentraits
39{
40public:
41 typedef std::string t_is;
42
43 static t_is constexpr isnot();
44
45 static t_is constexpr isa();
46
47#ifdef __GNUG__
48 static t_is constexpr filt();
49#endif
50};
51//------------------------------------------------------------------------------
52
53//------------------------------------------------------------------------------
59template<typename T> typename gentraits<T>::t_is constexpr filt(T *)
60{
61 return gentraits<T>::filt();
62}
63//------------------------------------------------------------------------------
64
65//------------------------------------------------------------------------------
70template<typename T> typename gentraits<T>::t_is constexpr gentraits<T>::isnot()
71{
72 return t_is("ISNOT");
73}
74//------------------------------------------------------------------------------
75
76//------------------------------------------------------------------------------
81template<typename T> typename gentraits<T>::t_is constexpr gentraits<T>::isa()
82{
83 return typeid(T).name();
84}
85//------------------------------------------------------------------------------
86
87//------------------------------------------------------------------------------
88#ifdef __GNUG__
89template<typename T> typename gentraits<T>::t_is constexpr gentraits<T>::filt()
90{
91 int status = -42;
92 char *res = abi::__cxa_demangle(typeid(T).name(), NULL, NULL, &status);
93
94 if(status != 0) {
95 ::free(res);
96 return isnot();
97 } else {
98 typename gentraits<T>::t_is result = res;
99 ::free(res);
100 return result;
101 }
102}
103#endif
104//------------------------------------------------------------------------------
105
106//------------------------------------------------------------------------------
112template<typename A, typename B> typename gentraits<A>::t_is const isa(
113 B const &)
114{
115 return typeid(A).name() == typeid(B).name() ? typeid(A).name() :
117}
118//------------------------------------------------------------------------------
119
120}/* namespace tools */
121
122#endif
static t_is constexpr isnot()
static t_is constexpr isa()
std::string t_is
gentraits< T >::t_is constexpr filt(T *)
gentraits< A >::t_is const isa(B const &)