MetaEnum.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2011, SRI International (R)
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <vector>
19 #include <algorithm>
20 
21 #include <OpenKarto/MetaEnum.h>
22 
23 namespace karto
24 {
25 
29 
31  {
33 
34  typedef std::vector<EnumPair> EnumPairVector;
35  EnumPairVector m_EnumPairs;
36  };
37 
41 
43  : m_pPrivate(new MetaEnumPrivate)
44  {
45  m_pPrivate->m_Name = rName;
46  }
47 
49  {
50  delete m_pPrivate;
51  }
52 
54  {
55  return std::find_if(m_pPrivate->m_EnumPairs.begin(), m_pPrivate->m_EnumPairs.end(), FindByName(rName)) != m_pPrivate->m_EnumPairs.end();
56  }
57 
59  {
60  return std::find_if(m_pPrivate->m_EnumPairs.begin(), m_pPrivate->m_EnumPairs.end(), FindByValue(value)) != m_pPrivate->m_EnumPairs.end();
61  }
62 
64  {
65  MetaEnumPrivate::EnumPairVector::const_iterator iter = std::find_if(m_pPrivate->m_EnumPairs.begin(), m_pPrivate->m_EnumPairs.end(), FindByName(rName));
66  if (iter == m_pPrivate->m_EnumPairs.end())
67  {
68  assert(false);
69  throw karto::Exception("No EnumPair with name: " +rName);
70  }
71 
72  return iter->value;
73  }
74 
76  {
77  return m_pPrivate->m_Name;
78  }
79 
81  {
82  MetaEnumPrivate::EnumPairVector::const_iterator iter = std::find_if(m_pPrivate->m_EnumPairs.begin(), m_pPrivate->m_EnumPairs.end(), FindByValue(value));
83  if (iter == m_pPrivate->m_EnumPairs.end())
84  {
85  assert(false);
86  throw karto::Exception("No EnumPair with value: " + karto::StringHelper::ToString(value));
87  }
88 
89  return iter->name;
90  }
91 
93  {
94  return m_pPrivate->m_EnumPairs.size();
95  }
96 
97  kt_bool MetaEnum::operator==(const MetaEnum& rOther) const
98  {
99  return m_pPrivate->m_Name == rOther.m_pPrivate->m_Name;
100  }
101 
102  kt_bool MetaEnum::operator!=(const MetaEnum& rOther) const
103  {
104  return m_pPrivate->m_Name != rOther.m_pPrivate->m_Name;
105  }
106 
108  {
109  if (index >= m_pPrivate->m_EnumPairs.size())
110  {
111  assert(false);
112  throw karto::Exception("MetaEnum::GetPair() - Index out of range");
113  }
114 
115  return m_pPrivate->m_EnumPairs[index];
116  }
117 
118  void MetaEnum::AddEnumPair(const EnumPair& rPair)
119  {
120  m_pPrivate->m_EnumPairs.push_back(rPair);
121  }
122 
123 }
bool kt_bool
Definition: Types.h:145
std::size_t kt_size_t
Definition: Types.h:138
kt_bool HasValue(kt_int64s value) const
Definition: MetaEnum.cpp:58
const EnumPair & GetPair(kt_size_t index) const
Definition: MetaEnum.cpp:107
const karto::String & GetName() const
Definition: MetaEnum.cpp:75
kt_size_t GetSize() const
Definition: MetaEnum.cpp:92
EnumPairVector m_EnumPairs
Definition: MetaEnum.cpp:35
kt_bool operator!=(const MetaEnum &rOther) const
Definition: MetaEnum.cpp:102
karto::String m_Name
Definition: MetaEnum.cpp:32
MetaEnum(const karto::String &rName)
Definition: MetaEnum.cpp:42
static String ToString(const char *value)
kt_bool operator==(const MetaEnum &rOther) const
Definition: MetaEnum.cpp:97
kt_int64s GetValue(const karto::String &rName) const
Definition: MetaEnum.cpp:63
kt_bool HasName(const karto::String &rName) const
Definition: MetaEnum.cpp:53
void AddEnumPair(const EnumPair &rPair)
Definition: MetaEnum.cpp:118
std::vector< EnumPair > EnumPairVector
Definition: MetaEnum.cpp:34
signed long long kt_int64s
Definition: Types.h:127
MetaEnumPrivate * m_pPrivate
Definition: MetaEnum.h:218
Definition: Any.cpp:20


nav2d_karto
Author(s): Sebastian Kasperski
autogenerated on Thu Jun 6 2019 19:20:24