Main MRPT website > C++ reference for MRPT 1.5.7
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  {
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.
Definition: TEnumType.h:35
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
int val
Definition: mrpt_jpeglib.h:953
GLsizei const GLchar ** string
Definition: glext.h:3919
static bimap< ENUMTYPE, std::string > & getBimap()
Singleton access.
Definition: TEnumType.h:47
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:41
GLuint const GLchar * name
Definition: glext.h:3891
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3520



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 8277875f6 Mon Jun 11 02:47:32 2018 +0200 at lun oct 28 01:50:49 CET 2019