Main MRPT website > C++ reference for MRPT 1.3.2
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-2015, 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  if (getBimap().empty()) TEnumTypeFiller<ENUMTYPE>::fill(getBimap());
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  {
44  if (getBimap().empty()) TEnumTypeFiller<ENUMTYPE>::fill(getBimap());
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
static ENUMTYPE name2value(const std::string &name)
Gives the numerical name for a given enum text name.
Definition: TEnumType.h:35
EIGEN_STRONG_INLINE bool empty() const
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
static bimap< ENUMTYPE, std::string > & getBimap()
Singleton access.
Definition: TEnumType.h:49
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:42



Page generated by Doxygen 1.8.12 for MRPT 1.3.2 SVN: at Thu Nov 10 13:46:27 UTC 2016