Main MRPT website > C++ reference
MRPT logo
TEnumType.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (c) 2005-2013, Individual contributors, see AUTHORS file |
7  | Copyright (c) 2005-2013, MAPIR group, University of Malaga |
8  | Copyright (c) 2012-2013, University of Almeria |
9  | All rights reserved. |
10  | |
11  | Redistribution and use in source and binary forms, with or without |
12  | modification, are permitted provided that the following conditions are |
13  | met: |
14  | * Redistributions of source code must retain the above copyright |
15  | notice, this list of conditions and the following disclaimer. |
16  | * Redistributions in binary form must reproduce the above copyright |
17  | notice, this list of conditions and the following disclaimer in the |
18  | documentation and/or other materials provided with the distribution. |
19  | * Neither the name of the copyright holders nor the |
20  | names of its contributors may be used to endorse or promote products |
21  | derived from this software without specific prior written permission.|
22  | |
23  | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
24  | 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
25  | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR|
26  | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE |
27  | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL|
28  | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR|
29  | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
30  | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
31  | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
32  | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
33  | POSSIBILITY OF SUCH DAMAGE. |
34  +---------------------------------------------------------------------------+ */
35 #ifndef mrpt_TEnumType_H
36 #define mrpt_TEnumType_H
37 
38 #include <mrpt/utils/utils_defs.h>
40 
41 namespace mrpt
42 {
43  namespace utils
44  {
45  /** Only specializations of this class are defined for each enum type of interest
46  * \sa TEnumType \ingroup mrpt_base_grp
47  */
48  template <typename ENUMTYPE>
50  {
51  typedef ENUMTYPE enum_t;
52  static void fill(bimap<enum_t,std::string> &m_map);
53  };
54 
55 
56  /** A helper class that can convert an enum value into its textual representation, and viceversa. \ingroup mrpt_base_grp */
57  template <typename ENUMTYPE>
58  struct TEnumType
59  {
60  /** Gives the numerical name for a given enum text name \exception std::exception on unknown enum name */
61  static ENUMTYPE name2value(const std::string &name)
62  {
64  return getBimap().inverse(name);
65  }
66 
67  /** Gives the textual name for a given enum value \exception std::exception on unknown enum value name */
68  static std::string value2name(const ENUMTYPE val)
69  {
71  return getBimap().direct(val);
72  }
73 
74  /** Singleton access */
76  {
77  static bimap<ENUMTYPE,std::string> data;
78  return data;
79  }
80  };
81 
82  } // End of namespace
83 } // end of namespace
84 #endif
static ENUMTYPE name2value(const std::string &name)
Gives the numerical name for a given enum text name.
Definition: TEnumType.h:61
EIGEN_STRONG_INLINE bool empty() const
Only specializations of this class are defined for each enum type of interest.
Definition: TEnumType.h:49
A helper class that can convert an enum value into its textual representation, and viceversa...
Definition: TEnumType.h:58
A bidirectional version of std::map, declared as bimap<KEY,VALUE> and which actually contains two std...
Definition: bimap.h:55
static bimap< ENUMTYPE, std::string > & getBimap()
Singleton access.
Definition: TEnumType.h:75
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
static void fill(bimap< enum_t, std::string > &m_map)
static std::string value2name(const ENUMTYPE val)
Gives the textual name for a given enum value.
Definition: TEnumType.h:68



Page generated by Doxygen 1.8.14 for MRPT 1.0.2 SVN: at lun oct 28 00:52:41 CET 2019 Hosted on:
SourceForge.net Logo