Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
type_of.h
1 /*
2  * type_of function definition
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2017, IRIT UPS.
6  *
7  * OTAWA is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * OTAWA is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OTAWA; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef ELM_RTTI_TYPE_OF_H_
22 #define ELM_RTTI_TYPE_OF_H_
23 
24 #include <elm/arch.h>
25 #include <elm/string/CString.h>
26 #include <elm/string/String.h>
27 #include <elm/types.h>
28 
29 #include "Type.h"
30 
31 namespace elm { namespace rtti {
32 
33 class AbstractClass;
34 
35 class Object {
36 public:
37  static const Type& __type;
38  virtual ~Object(void);
39  virtual const Type& getType(void) const;
40 };
41 
42 // base types
46 
47 // type determination
48 template <class T> struct _type
49  { static inline const Type& _(void) { return T::__type; } };
50 template <> inline const Type& _type<char>::_(void) { return int8_type; }
51 template <> inline const Type& _type<t::int8>::_(void) { return int8_type; }
52 template <> inline const Type& _type<t::int16>::_(void) { return int16_type; }
53 template <> inline const Type& _type<t::int32>::_(void) { return int32_type; }
54 template <> inline const Type& _type<t::int64>::_(void) { return int64_type; }
55 template <> inline const Type& _type<t::uint8>::_(void) { return uint8_type; }
56 template <> inline const Type& _type<t::uint16>::_(void) { return uint16_type; }
57 template <> inline const Type& _type<t::uint32>::_(void) { return uint32_type; }
58 template <> inline const Type& _type<t::uint64>::_(void) { return uint64_type; }
59 template <> inline const Type& _type<float>::_(void) { return float_type; }
60 template <> inline const Type& _type<double>::_(void) { return double_type; }
61 template <> inline const Type& _type<long double>::_(void) { return long_double_type; }
62 template <> inline const Type& _type<bool>::_(void) { return bool_type; }
63 template <> inline const Type& _type<cstring>::_(void) { return cstring_type; }
64 template <> inline const Type& _type<string>::_(void) { return string_type; }
65 template <> inline const Type& _type<void>::_(void) { return void_type; }
66 
67 template <class T> struct _type<T *>
68  { static inline const Type& _(void) { return _type<T>::_().pointer(); } };
69 template <class T> struct _type<const T &>
70  { static inline const Type& _(void) { return _type<T>::_(); } };
71 
72 template <class T> struct _templ
73  { static inline const Type& _(void) { return *static_cast<const Type *>(nullptr); } };
74 
75 } // rtti
76 
77 template <class T> inline const rtti::Type& type_of(void) { return rtti::_type<T>::_(); }
78 template <class T> inline const rtti::Type& type_of(const T& v) { return rtti::_type<T>::_(); }
79 template <class T> inline const rtti::Type& template_of(void) { return rtti::_templ<T>(); }
80 template <class T> inline const rtti::Type& template_of(const T& v) { return rtti::_templ<T>(); }
81 
82 } // elm
83 
84 #endif /* ELM_RTTI_TYPE_OF_H_ */
Definition: type_of.h:35
virtual ~Object(void)
Definition: rtti.cpp:178
virtual const Type & getType(void) const
Definition: rtti.cpp:187
static const Type & __type
Definition: type_of.h:37
Definition: Type.h:83
const PointerType & pointer(void) const
Definition: rtti.cpp:338
const Type & cstring_type
Definition: type_of.h:45
const Type & int64_type
Definition: type_of.h:43
const Type & void_type
Definition: type_of.h:45
const Type & uint8_type
Definition: type_of.h:43
const rtti::Type & type_of(void)
Definition: type_of.h:77
const Type & uint32_type
Definition: type_of.h:43
const Type & double_type
Definition: type_of.h:44
const Type & bool_type
Definition: rtti.cpp:723
const Type & int8_type
Definition: rtti.cpp:620
const Type & string_type
Definition: type_of.h:45
const Type & int16_type
Definition: type_of.h:43
const Type & uint16_type
Definition: type_of.h:43
const Type & int32_type
Definition: type_of.h:43
const Type & long_double_type
Definition: type_of.h:44
const Type & float_type
Definition: rtti.cpp:688
const Type & uint64_type
Definition: type_of.h:43
Definition: adapter.h:26
const rtti::Type & template_of(void)
Definition: type_of.h:79
Definition: type_of.h:73
static const Type & _(void)
Definition: type_of.h:73
static const Type & _(void)
Definition: type_of.h:68
static const Type & _(void)
Definition: type_of.h:70
Definition: type_of.h:49
static const Type & _(void)
Definition: type_of.h:49