Main MRPT website > C++ reference for MRPT 1.4.0
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-2016, 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;
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  {
38  return getBimap().inverse(name);
39  }
40 
41  /** Gives the textual name for a given enum value \exception std::exception on unknown enum value name */
42  static std::string value2name(const ENUMTYPE val)
43  {
45  return getBimap().direct(val);
46  }
47 
48  /** Singleton access */
50  {
51  static bimap<ENUMTYPE,std::string> data;
52  return data;
53  }
54  };
55 
56  } // End of namespace
57 } // end of namespace
58 #endif
A bidirectional version of std::map, declared as bimap<KEY,VALUE> and which actually contains two std...
Definition: bimap.h:29
EIGEN_STRONG_INLINE bool empty() const
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Only specializations of this class are defined for each enum type of interest.
Definition: TEnumType.h:24
static void fill(mrpt::utils::bimap< enum_t, std::string > &m_map)
A helper class that can convert an enum value into its textual representation, and viceversa.
Definition: TEnumType.h:33
static bimap< ENUMTYPE, std::string > & getBimap()
Singleton access.
Definition: TEnumType.h:49
static ENUMTYPE name2value(const std::string &name)
Gives the numerical name for a given enum text name.
Definition: TEnumType.h:35
static std::string value2name(const ENUMTYPE val)
Gives the textual name for a given enum value.
Definition: TEnumType.h:42



Page generated by Doxygen 1.9.1 for MRPT 1.4.0 SVN: at Mon Apr 18 03:37:47 UTC 2022