Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JTypeInfo.hh
Go to the documentation of this file.
1#ifndef __JLANG__JTYPEINFO__
2#define __JLANG__JTYPEINFO__
3
4#include <typeinfo>
5
7#include "JLang/JException.hh"
8
9
10/**
11 * \author mdejong
12 */
13
14namespace JLANG {}
15namespace JPP { using namespace JLANG; }
16
17namespace JLANG {
18
19
20 /**
21 * This class is a wrapper around the STL type_info class.
22 * It is possible to create a list of objects of this class.
23 *
24 * Source code is taken from reference:
25 * A. Alexandrescu, Modern C++ Design, Addison Wesley.
26 */
27 class JTypeInfo :
28 public JComparable<JTypeInfo>
29 {
30 public:
31 /**
32 * Default constructor.
33 */
35 {
36 class JNullType {};
37
38 pType = &typeid(JNullType);
39 }
40
41
42 /**
43 * Constructor.
44 *
45 * \param type type information
46 */
47 JTypeInfo(const std::type_info& type) :
48 pType(&type)
49 {}
50
51
52 /**
53 * Get type information.
54 *
55 * \return type information
56 */
57 const std::type_info& get() const
58 {
59 if (pType == NULL)
60 THROW(JTypeInformationException, "No type information.");
61 else
62 return *pType;
63 }
64
65
66 /**
67 * Less than operation.
68 *
69 * \param that object to be compared
70 * \return true if this type information less than that type information; else false
71 */
72 bool less(const JTypeInfo& that) const
73 {
74 return get().before(that.get()) != 0;
75 }
76
77
78 /**
79 * Evaluate order.
80 *
81 * \param type type information
82 * \return true if this type before given type; else false
83 */
84 bool before(const JTypeInfo& type) const
85 {
86 return get().before(type.get()) != 0;
87 }
88
89
90 /**
91 * Get type name.
92 *
93 * \return type name
94 */
95 const char* name() const
96 {
97 return get().name();
98 }
99
100
101 private:
102 const std::type_info* pType;
103 };
104}
105
106#endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
This class is a wrapper around the STL type_info class.
Definition JTypeInfo.hh:29
bool before(const JTypeInfo &type) const
Evaluate order.
Definition JTypeInfo.hh:84
JTypeInfo(const std::type_info &type)
Constructor.
Definition JTypeInfo.hh:47
bool less(const JTypeInfo &that) const
Less than operation.
Definition JTypeInfo.hh:72
const char * name() const
Get type name.
Definition JTypeInfo.hh:95
const std::type_info & get() const
Get type information.
Definition JTypeInfo.hh:57
const std::type_info * pType
Definition JTypeInfo.hh:102
JTypeInfo()
Default constructor.
Definition JTypeInfo.hh:34
Exception for absence of type information.
Auxiliary classes and methods for language specific functionality.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Template definition of auxiliary base class for comparison of data structures.
Auxiliary class for no type definition.
Definition JNullType.hh:19