MRPT  2.0.4
test.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 /** \example typemeta_TEnumType/test.cpp */
10 
11 //! [example]
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 
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"
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 (const std::exception& e)
71  {
72  std::cerr << "MRPT error: " << e.what() << std::endl;
73  return -1;
74  }
75 }
MRPT_ENUM_TYPE_END
#define MRPT_ENUM_TYPE_END()
Definition: TEnumType.h:78
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:62
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:86
argv
const char * argv[]
Definition: RawlogGrabberApp_unittest.cpp:50
North
@ North
Definition: enumtype_unittest.cpp:30
MRPT_FILL_ENUM_MEMBER
#define MRPT_FILL_ENUM_MEMBER(_CLASS, _VALUE)
Definition: TEnumType.h:88
argc
const int argc
Definition: RawlogGrabberApp_unittest.cpp:51
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 2.0.4 at Sun Jul 19 15:15:43 UTC 2020