Main MRPT website > C++ reference for MRPT 1.9.9
TEnumType.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-2017, 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 mrpt_TEnumType_H
10 #define mrpt_TEnumType_H
11 
12 #include <mrpt/utils/core_defs.h>
13 #include <mrpt/utils/bimap.h>
14 
15 namespace mrpt
16 {
17 namespace utils
18 {
19 /** Only specializations of this class are defined for each enum type of
20  * interest
21  * \sa TEnumType \ingroup mrpt_base_grp
22  */
23 template <typename ENUMTYPE>
25 {
26  typedef ENUMTYPE enum_t;
28 };
29 
30 /** For use in specializations of TEnumTypeFiller */
31 #define MRPT_FILL_ENUM(_X) m_map.insert(_X, #_X)
32 #define MRPT_FILL_ENUM_MEMBER(_CLASS, _VALUE) \
33  m_map.insert(_CLASS::_VALUE, #_VALUE)
34 
35 /** A helper class that can convert an enum value into its textual
36  * representation, and viceversa. \ingroup mrpt_base_grp */
37 template <typename ENUMTYPE>
38 struct TEnumType
39 {
40  /** Gives the numerical name for a given enum text name \exception
41  * std::exception on unknown enum name */
42  static ENUMTYPE name2value(const std::string& name)
43  {
44  return getBimap().inverse(name);
45  }
46 
47  /** Gives the textual name for a given enum value \exception std::exception
48  * on unknown enum value name */
49  static std::string value2name(const ENUMTYPE val)
50  {
51  return getBimap().direct(val);
52  }
53 
54  /** Singleton access */
56  {
59  return data;
60  }
61 };
62 
63 } // End of namespace
64 } // end of namespace
65 #endif
static ENUMTYPE name2value(const std::string &name)
Gives the numerical name for a given enum text name.
Definition: TEnumType.h:42
static void fill(mrpt::utils::bimap< enum_t, std::string > &m_map)
Only specializations of this class are defined for each enum type of interest.
Definition: TEnumType.h:24
A helper class that can convert an enum value into its textual representation, and viceversa...
Definition: TEnumType.h:38
A bidirectional version of std::map, declared as bimap<KEY,VALUE> and which actually contains two std...
Definition: bimap.h:34
int val
Definition: mrpt_jpeglib.h:955
GLsizei const GLchar ** string
Definition: glext.h:4101
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
static std::string value2name(const ENUMTYPE val)
Gives the textual name for a given enum value.
Definition: TEnumType.h:49
GLuint const GLchar * name
Definition: glext.h:4054
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3546
static bimap< ENUMTYPE, std::string > & getBimap()
Singleton access.
Definition: TEnumType.h:55



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019