Main MRPT website
>
C++ reference for MRPT 1.9.9
test.cpp
Go to the documentation of this file.
1
/* +------------------------------------------------------------------------+
2
| Mobile Robot Programming Toolkit (MRPT) |
3
| http://www.mrpt.org/ |
4
| |
5
| Copyright (c) 2005-2018, 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
/** \example typemeta_TEnumType/test.cpp */
10
11
//! [example]
12
#include <
mrpt/typemeta/TEnumType.h
>
13
#include <iostream>
14
#include <string>
15
16
// Example declaration of "enum class"
17
enum class
TestColors
18
{
19
Black
= 0,
20
Gray
= 7,
21
White
= 15
22
};
23
24
MRPT_ENUM_TYPE_BEGIN
(
TestColors
)
25
MRPT_FILL_ENUM_MEMBER
(
TestColors
, Black);
26
MRPT_FILL_ENUM_MEMBER
(
TestColors
, Gray);
27
MRPT_FILL_ENUM_MEMBER
(
TestColors
, White);
28
MRPT_ENUM_TYPE_END
()
29
30
// Example declaration of plain enum
31
enum
Directions
32
{
33
North
,
34
East
,
35
South
,
36
West
37
};
38
// Example declaration of "enum class"
39
MRPT_ENUM_TYPE_BEGIN
(
Directions
)
40
MRPT_FILL_ENUM
(
North
);
41
MRPT_FILL_ENUM
(
East
);
42
MRPT_FILL_ENUM
(
South
);
43
MRPT_FILL_ENUM
(
West
);
44
MRPT_ENUM_TYPE_END
()
45
46
void
Test_EnumType
()
47
{
48
using namespace
std;
49
using namespace
mrpt::typemeta
;
50
51
cout <<
"White => "
<< (int)
TEnumType<TestColors>::name2value
(
"White"
)
52
<< endl;
53
cout <<
"Black => "
<< (int)
TEnumType<TestColors>::name2value
(
"Black"
)
54
<< endl;
55
cout <<
"Gray => "
<< (int)
TEnumType<TestColors>::name2value
(
"Gray"
)
56
<< endl;
57
58
cout <<
"7 <= "
<<
TEnumType<TestColors>::value2name
(
TestColors
(7))
59
<< endl;
60
}
61
//! [example]
62
63
int
main
(
int
argc,
char
** argv)
64
{
65
try
66
{
67
Test_EnumType
();
68
return
0;
69
}
70
catch
(std::exception& e)
71
{
72
std::cout <<
"Exception: "
<< e.what() << std::endl;
73
return
-1;
74
}
75
}
MRPT_ENUM_TYPE_END
#define MRPT_ENUM_TYPE_END()
Definition:
TEnumType.h:74
mrpt::typemeta
Definition:
config/CConfigFileBase.h:21
South
@ South
Definition:
enumtype_unittest.cpp:32
TestColors::White
@ White
TestColors::Black
@ Black
TestColors
TestColors
Definition:
enumtype_unittest.cpp:14
MRPT_ENUM_TYPE_BEGIN
#define MRPT_ENUM_TYPE_BEGIN(_ENUM_TYPE_WITH_NS)
Definition:
TEnumType.h:58
Directions
Directions
Definition:
enumtype_unittest.cpp:28
TestColors::Gray
@ Gray
East
@ East
Definition:
enumtype_unittest.cpp:31
main
int main()
Definition:
vision_stereo_rectify/test.cpp:78
TEnumType.h
mrpt::typemeta::TEnumType
A helper class that can convert an enum value into its textual representation, and viceversa.
Definition:
config/CConfigFileBase.h:24
MRPT_FILL_ENUM
#define MRPT_FILL_ENUM(_X)
For use in specializations of TEnumTypeFiller.
Definition:
TEnumType.h:82
North
@ North
Definition:
enumtype_unittest.cpp:30
MRPT_FILL_ENUM_MEMBER
#define MRPT_FILL_ENUM_MEMBER(_CLASS, _VALUE)
Definition:
TEnumType.h:84
void
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
West
@ West
Definition:
enumtype_unittest.cpp:33
Test_EnumType
void Test_EnumType()
Definition:
vision_stereo_rectify/test.cpp:46
Page generated by
Doxygen 1.8.17
for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST