Main MRPT website
>
C++ reference for MRPT 1.4.0
mrpt
utils
TTypeName.h
Go to the documentation of this file.
1
/* +---------------------------------------------------------------------------+
2
| Mobile Robot Programming Toolkit (MRPT) |
3
| http://www.mrpt.org/ |
4
| |
5
| Copyright (c) 2005-2016, Individual contributors, see AUTHORS file |
6
| See: http://www.mrpt.org/Authors - All rights reserved. |
7
| Released under BSD License. See details in http://www.mrpt.org/License |
8
+---------------------------------------------------------------------------+ */
9
#ifndef TTYPENAME_H
10
#define TTYPENAME_H
11
12
#include <
mrpt/utils/mrpt_stdint.h
>
// compiler-independent version of "stdint.h"
13
#include <string>
14
15
namespace
mrpt
16
{
17
namespace
utils
18
{
19
/** @name Conversion of type to string at compile time
20
* IMPORTANT: See also the implementation of Serialization for STL containers in <mrpt/utils/stl_serialization.h>
21
@{ */
22
23
/** A template to obtain the type of its argument as a string at compile time.
24
* It works with all classes derived from CSerializable, plus many specializations for the plain data types (bool, double, uint8_t, etc...)
25
* For example:
26
* \code
27
* cout << TTypeName<double>::get() << endl; // "double"
28
* cout << TTypeName<CPose2D>::get() << endl; // "CPose2D"
29
* cout << TTypeName<mrpt::maps::COccupancyGridMap2D>::get() << endl; // "COccupancyGridMap2D"
30
* \endcode
31
*
32
* Users can extend this for custom structs/classes with the macro DECLARE_CUSTOM_TTYPENAME:
33
* \code
34
* class MyClass { ... };
35
* DECLARE_CUSTOM_TTYPENAME(MyClass)
36
* cout << TTypeName<MyClass>::get() << endl; // "MyClass"
37
* \endcode
38
*
39
* The following types are NOT ALLOWED since they have platform-dependant sizes:
40
* - int, unsigned int
41
* - long, unsigned long
42
* - short, unsigned short
43
* - size_t
44
*
45
*/
46
template
<
typename
T>
47
struct
TTypeName
48
{
49
static
std::string
get
() {
50
return
std::string( T::classinfo->className );
51
}
52
};
53
54
/** Identical to MRPT_DECLARE_TTYPENAME but intended for user code.
55
* MUST be placed at the GLOBAL namespace.
56
*/
57
#define DECLARE_CUSTOM_TTYPENAME(_TYPE) \
58
namespace mrpt { namespace utils { MRPT_DECLARE_TTYPENAME(_TYPE) } }
59
60
#define MRPT_DECLARE_TTYPENAME(_TYPE) \
61
template<> struct TTypeName <_TYPE > { \
62
static std::string get() { return std::string(#_TYPE); } };
63
64
#define MRPT_DECLARE_TTYPENAME_NAMESPACE(_TYPE,__NS) \
65
template<> struct TTypeName <__NS :: _TYPE > { \
66
static std::string get() { return std::string(#_TYPE); } };
67
68
#define MRPT_DECLARE_TTYPENAME_PTR(_TYPE) \
69
template<> struct TTypeName <_TYPE##Ptr> { \
70
static std::string get() { return TTypeName<_TYPE>::get(); } };
71
72
#define MRPT_DECLARE_TTYPENAME_PTR_NAMESPACE(_TYPE,__NS) \
73
template<> struct TTypeName <__NS :: _TYPE##Ptr> { \
74
static std::string get() { return TTypeName<__NS :: _TYPE>::get(); } };
75
76
MRPT_DECLARE_TTYPENAME
(
bool
)
77
MRPT_DECLARE_TTYPENAME
(
double
)
78
MRPT_DECLARE_TTYPENAME
(
float
)
79
MRPT_DECLARE_TTYPENAME
(uint64_t)
80
MRPT_DECLARE_TTYPENAME
(int64_t)
81
MRPT_DECLARE_TTYPENAME
(uint32_t)
82
MRPT_DECLARE_TTYPENAME
(int32_t)
83
MRPT_DECLARE_TTYPENAME
(uint16_t)
84
MRPT_DECLARE_TTYPENAME
(int16_t)
85
MRPT_DECLARE_TTYPENAME
(uint8_t)
86
MRPT_DECLARE_TTYPENAME
(int8_t)
87
88
/** @} */
89
90
}
// End of namespace
91
}
// End of namespace
92
93
#endif
MRPT_DECLARE_TTYPENAME
#define MRPT_DECLARE_TTYPENAME(_TYPE)
Definition:
TTypeName.h:60
mrpt::utils::TTypeName::get
static std::string get()
Definition:
TTypeName.h:49
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition:
CParticleFilter.h:16
mrpt_stdint.h
mrpt::utils::TTypeName
A template to obtain the type of its argument as a string at compile time.
Definition:
TTypeName.h:47
Page generated by
Doxygen 1.8.16
for MRPT 1.4.0 SVN: at Mon Oct 14 22:32:58 UTC 2019