Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
OpenKarto
source
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
30
struct
MetaEnumPrivate
31
{
32
karto::String
m_Name
;
33
34
typedef
std::vector<EnumPair>
EnumPairVector
;
35
EnumPairVector
m_EnumPairs
;
36
};
37
41
42
MetaEnum::MetaEnum
(
const
karto::String
& rName)
43
: m_pPrivate(new
MetaEnumPrivate
)
44
{
45
m_pPrivate
->
m_Name
= rName;
46
}
47
48
MetaEnum::~MetaEnum
()
49
{
50
delete
m_pPrivate
;
51
}
52
53
kt_bool
MetaEnum::HasName
(
const
karto::String
& rName)
const
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
58
kt_bool
MetaEnum::HasValue
(
kt_int64s
value)
const
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
63
kt_int64s
MetaEnum::GetValue
(
const
karto::String
& rName)
const
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
75
const
karto::String
&
MetaEnum::GetName
()
const
76
{
77
return
m_pPrivate
->
m_Name
;
78
}
79
80
const
karto::String
&
MetaEnum::GetName
(
kt_int64s
value)
const
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
92
kt_size_t
MetaEnum::GetSize
()
const
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
107
const
EnumPair
&
MetaEnum::GetPair
(
kt_size_t
index)
const
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
}
kt_bool
bool kt_bool
Definition:
Types.h:145
kt_size_t
std::size_t kt_size_t
Definition:
Types.h:138
karto::MetaEnum::HasValue
kt_bool HasValue(kt_int64s value) const
Definition:
MetaEnum.cpp:58
karto::MetaEnum::GetPair
const EnumPair & GetPair(kt_size_t index) const
Definition:
MetaEnum.cpp:107
karto::String
Definition:
String.h:52
karto::MetaEnum::GetName
const karto::String & GetName() const
Definition:
MetaEnum.cpp:75
karto::MetaEnum::GetSize
kt_size_t GetSize() const
Definition:
MetaEnum.cpp:92
karto::MetaEnumPrivate::m_EnumPairs
EnumPairVector m_EnumPairs
Definition:
MetaEnum.cpp:35
karto::EnumPair
Definition:
MetaEnum.h:43
karto::MetaEnum::operator!=
kt_bool operator!=(const MetaEnum &rOther) const
Definition:
MetaEnum.cpp:102
karto::MetaEnumPrivate::m_Name
karto::String m_Name
Definition:
MetaEnum.cpp:32
karto::MetaEnum
Definition:
MetaEnum.h:121
karto::MetaEnum::MetaEnum
MetaEnum(const karto::String &rName)
Definition:
MetaEnum.cpp:42
karto::StringHelper::ToString
static String ToString(const char *value)
Definition:
StringHelper.cpp:32
karto::MetaEnum::operator==
kt_bool operator==(const MetaEnum &rOther) const
Definition:
MetaEnum.cpp:97
karto::MetaEnum::~MetaEnum
~MetaEnum()
Definition:
MetaEnum.cpp:48
karto::MetaEnum::GetValue
kt_int64s GetValue(const karto::String &rName) const
Definition:
MetaEnum.cpp:63
karto::MetaEnum::HasName
kt_bool HasName(const karto::String &rName) const
Definition:
MetaEnum.cpp:53
karto::MetaEnum::AddEnumPair
void AddEnumPair(const EnumPair &rPair)
Definition:
MetaEnum.cpp:118
karto::MetaEnumPrivate::EnumPairVector
std::vector< EnumPair > EnumPairVector
Definition:
MetaEnum.cpp:34
karto::MetaEnumPrivate
Definition:
MetaEnum.cpp:30
karto::Exception
Definition:
Exception.h:38
kt_int64s
signed long long kt_int64s
Definition:
Types.h:127
karto::MetaEnum::m_pPrivate
MetaEnumPrivate * m_pPrivate
Definition:
MetaEnum.h:218
karto
Definition:
Any.cpp:20
karto::FindByName
Definition:
MetaEnum.h:76
karto::FindByValue
Definition:
MetaEnum.h:96
MetaEnum.h
nav2d_karto
Author(s): Sebastian Kasperski
autogenerated on Thu Jun 6 2019 19:20:24