Main MRPT website > C++ reference for MRPT 1.5.6
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 interest
20  * \sa TEnumType \ingroup mrpt_base_grp
21  */
22  template <typename ENUMTYPE>
24  {
25  typedef ENUMTYPE enum_t;
26  static void fill(mrpt::utils::bimap<enum_t,std::string> &m_map);
27  };
28 
29 
30  /** A helper class that can convert an enum value into its textual representation, and viceversa. \ingroup mrpt_base_grp */
31  template <typename ENUMTYPE>
32  struct TEnumType
33  {
34  /** Gives the numerical name for a given enum text name \exception std::exception on unknown enum name */
35  static ENUMTYPE name2value(const std::string &name)
36  {
37  return getBimap().inverse(name);
38  }
39 
40  /** Gives the textual name for a given enum value \exception std::exception on unknown enum value name */
41  static std::string value2name(const ENUMTYPE val)
42  {
43  return getBimap().direct(val);
44  }
45 
46  /** Singleton access */
48  {
50  if (data.empty()) TEnumTypeFiller<ENUMTYPE>::fill(data);
51  return data;
52  }
53  };
54 
55  } // End of namespace
56 } // end of namespace
57 #endif
static ENUMTYPE name2value(const std::string &name)
Gives the numerical name for a given enum text name on unknown enum name.
Definition: TEnumType.h:35
bool empty() const
Definition: bimap.h:55
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:23
A helper class that can convert an enum value into its textual representation, and viceversa...
A bidirectional version of std::map, declared as bimap<KEY,VALUE> and which actually contains two std::...
Definition: bimap.h:28
GLuint const GLchar * name
Definition: glew.h:1721
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1284
static bimap< ENUMTYPE, std::string > & getBimap()
Singleton access.
Definition: TEnumType.h:47
GLsizei const GLcharARB ** string
Definition: glew.h:3293
static std::string value2name(const ENUMTYPE val)
Gives the textual name for a given enum value on unknown enum value name.
Definition: TEnumType.h:41
GLuint GLfloat * val
Definition: glew.h:7785



Page generated by Doxygen 1.8.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018