libosmscout 1.1.1
Loading...
Searching...
No Matches
TypeInfoSet.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_TYPEINFOSET_H
2#define OSMSCOUT_TYPEINFOSET_H
3
4/*
5 This source is part of the libosmscout library
6 Copyright (C) 2009 Tim Teulings
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21*/
22
23#include <iterator>
24#include <vector>
25
26#include <osmscout/TypeConfig.h>
27
29
30namespace osmscout {
31
32 class OSMSCOUT_API TypeInfoSetConstIterator CLASS_FINAL
33 {
34 public:
37 using reference = const TypeInfoRef&;
39 using iterator_category = std::input_iterator_tag;
40
41 private:
42 std::vector<TypeInfoRef>::const_iterator iterCurrent;
43 std::vector<TypeInfoRef>::const_iterator iterEnd;
44
45 public:
46 TypeInfoSetConstIterator(const std::vector<value_type>::const_iterator& iterCurrent,
47 const std::vector<value_type>::const_iterator& iterEnd)
48 : iterCurrent(iterCurrent),
49 iterEnd(iterEnd)
50 {
51 while (this->iterCurrent!=this->iterEnd &&
52 !*this->iterCurrent) {
53 ++this->iterCurrent;
54 }
55 }
56
58
60 {
61 ++iterCurrent;
62
63 while (iterCurrent!=iterEnd &&
64 !*iterCurrent) {
65 ++iterCurrent;
66 }
67
68 return *this;
69 }
70
72 {
73 TypeInfoSetConstIterator tmp(*this);
74
75 operator++();
76
77 return tmp;
78 }
79
80 bool operator==(const TypeInfoSetConstIterator& other) const
81 {
82 return iterCurrent==other.iterCurrent;
83 }
84
85 bool operator!=(const TypeInfoSetConstIterator& other) const
86 {
87 return iterCurrent!=other.iterCurrent;
88 }
89
90 const TypeInfoRef& operator*() const
91 {
92 return *iterCurrent;
93 }
94
96 {
97 return *iterCurrent;
98 }
99 };
100
109 class OSMSCOUT_API TypeInfoSet CLASS_FINAL
110 {
111 private:
112 std::vector<TypeInfoRef> types;
113 size_t count = 0;
114
115 public:
116 TypeInfoSet() = default;
117 ~TypeInfoSet() = default;
118
119 explicit TypeInfoSet(const TypeConfig& typeConfig);
120 explicit TypeInfoSet(const std::vector<TypeInfoRef>& types);
121
122 TypeInfoSet(const TypeInfoSet& other) = default;
123 TypeInfoSet(TypeInfoSet&& other) noexcept;
124
126 {
127 if (&other!=this) {
128 this->types=other.types;
129 this->count=other.count;
130 }
131
132 return *this;
133 }
134
135 bool operator==(const TypeInfoSet& other) const;
136 bool operator!=(const TypeInfoSet& other) const;
137
138 void Adapt(const TypeConfig& typeConfig);
139
140 void Clear()
141 {
142 if (count>0) {
143 types.clear();
144 }
145
146 count=0;
147 }
148
149 void Set(const TypeInfoRef& type);
150 void Set(const std::vector<TypeInfoRef>& types);
151 void Set(const TypeInfoSet& other);
152
153 void Add(const TypeInfoSet& types);
154
155 void Remove(const TypeInfoRef& type);
156 void Remove(const TypeInfoSet& otherTypes);
157
158 void Intersection(const TypeInfoSet& otherTypes);
159
160 bool IsSet(const TypeInfoRef& type) const
161 {
162 assert(type);
163
164 return type->GetIndex()<types.size() &&
165 types[type->GetIndex()];
166 }
167
168 bool Empty() const
169 {
170 return count==0;
171 }
172
173 size_t Size() const
174 {
175 return count;
176 }
177
178 bool Intersects(const TypeInfoSet& otherTypes) const;
179
181 {
182 return TypeInfoSetConstIterator(types.begin(),
183 types.end());
184 }
185
187 {
188 return TypeInfoSetConstIterator(types.end(),
189 types.end());
190 }
191 };
192}
193
194#endif
#define CLASS_FINAL
Definition Compiler.h:26
#define OSMSCOUT_API
Definition CoreImportExport.h:45
Definition Area.h:88
TypeInfoSetConstIterator(const std::vector< value_type >::const_iterator &iterCurrent, const std::vector< value_type >::const_iterator &iterEnd)
Definition TypeInfoSet.h:46
TypeInfoSetConstIterator operator++(int)
Definition TypeInfoSet.h:71
void Intersection(const TypeInfoSet &otherTypes)
void Remove(const TypeInfoRef &type)
void Add(const TypeInfoSet &types)
TypeInfoRef value_type
Definition TypeInfoSet.h:36
const TypeInfoRef & operator*() const
Definition TypeInfoSet.h:90
void Adapt(const TypeConfig &typeConfig)
TypeInfoRef pointer
Definition TypeInfoSet.h:38
TypeInfoSet(const TypeInfoSet &other)=default
TypeInfoSetConstIterator & operator++()
Definition TypeInfoSet.h:59
bool Intersects(const TypeInfoSet &otherTypes) const
TypeInfoSet(const TypeConfig &typeConfig)
TypeInfoSetConstIterator begin() const
Definition TypeInfoSet.h:180
TypeInfoSet(const std::vector< TypeInfoRef > &types)
bool operator==(const TypeInfoSetConstIterator &other) const
Definition TypeInfoSet.h:80
void Set(const std::vector< TypeInfoRef > &types)
void Set(const TypeInfoSet &other)
TypeInfoSet & operator=(const TypeInfoSet &other)
Definition TypeInfoSet.h:125
bool operator==(const TypeInfoSet &other) const
void Set(const TypeInfoRef &type)
TypeInfoSetConstIterator(const TypeInfoSetConstIterator &other)=default
TypeInfoRef operator->() const
Definition TypeInfoSet.h:95
size_t Size() const
Definition TypeInfoSet.h:173
std::input_iterator_tag iterator_category
Definition TypeInfoSet.h:39
const TypeInfoRef & reference
Definition TypeInfoSet.h:37
TypeInfoSetConstIterator self_type
Definition TypeInfoSet.h:35
void Remove(const TypeInfoSet &otherTypes)
Type type
The type of the cell.
Definition GroundTile.h:92
void Clear()
Definition TypeInfoSet.h:140
TypeInfoSet(TypeInfoSet &&other) noexcept
bool operator!=(const TypeInfoSetConstIterator &other) const
Definition TypeInfoSet.h:85
bool operator!=(const TypeInfoSet &other) const
bool Empty() const
Definition TypeInfoSet.h:168
bool IsSet(const TypeInfoRef &type) const
Definition TypeInfoSet.h:160
TypeInfoSetConstIterator end() const
Definition TypeInfoSet.h:186
Definition Area.h:39
std::shared_ptr< TypeInfo > TypeInfoRef
Definition TypeConfig.h:61