libosmscout  1.1.1
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 
30 namespace osmscout {
31 
32  class OSMSCOUT_API TypeInfoSetConstIterator CLASS_FINAL
33  {
34  public:
35  using self_type = TypeInfoSetConstIterator;
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 
57  TypeInfoSetConstIterator(const TypeInfoSetConstIterator& other) = default;
58 
59  TypeInfoSetConstIterator& operator++()
60  {
61  ++iterCurrent;
62 
63  while (iterCurrent!=iterEnd &&
64  !*iterCurrent) {
65  ++iterCurrent;
66  }
67 
68  return *this;
69  }
70 
71  TypeInfoSetConstIterator operator++(int)
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 
125  void Adapt(const TypeConfig& typeConfig);
126 
127  inline void Clear()
128  {
129  if (count>0) {
130  types.clear();
131  }
132 
133  count=0;
134  }
135 
136  void Set(const TypeInfoRef& type);
137  void Set(const std::vector<TypeInfoRef>& types);
138  void Set(const TypeInfoSet& other);
139 
140  void Add(const TypeInfoSet& types);
141 
142  void Remove(const TypeInfoRef& type);
143  void Remove(const TypeInfoSet& otherTypes);
144 
145  void Intersection(const TypeInfoSet& otherTypes);
146 
147  inline bool IsSet(const TypeInfoRef& type) const
148  {
149  assert(type);
150 
151  return type->GetIndex()<types.size() &&
152  types[type->GetIndex()];
153  }
154 
155  inline bool Empty() const
156  {
157  return count==0;
158  }
159 
160  inline size_t Size() const
161  {
162  return count;
163  }
164 
165  bool Intersects(const TypeInfoSet& otherTypes) const;
166 
167  inline TypeInfoSet& operator=(const TypeInfoSet& other)
168  {
169  if (&other!=this) {
170  this->types=other.types;
171  this->count=other.count;
172  }
173 
174  return *this;
175  }
176 
177  bool operator==(const TypeInfoSet& other) const;
178  bool operator!=(const TypeInfoSet& other) const;
179 
180  inline TypeInfoSetConstIterator begin() const
181  {
182  return TypeInfoSetConstIterator(types.begin(),
183  types.end());
184  }
185 
186  inline TypeInfoSetConstIterator end() const
187  {
188  return TypeInfoSetConstIterator(types.end(),
189  types.end());
190  }
191  };
192 }
193 
194 #endif
TypeInfoRef pointer
Definition: TypeInfoSet.h:38
TypeInfoSet & operator=(const TypeInfoSet &other)
Definition: TypeInfoSet.h:167
const TypeInfoRef & operator*() const
Definition: TypeInfoSet.h:90
TypeInfoSetConstIterator end() const
Definition: TypeInfoSet.h:186
TypeInfoSetConstIterator(const std::vector< value_type >::const_iterator &iterCurrent, const std::vector< value_type >::const_iterator &iterEnd)
Definition: TypeInfoSet.h:46
TypeInfoRef operator->() const
Definition: TypeInfoSet.h:95
bool operator!=(const MapViewStruct &r1, const MapViewStruct &r2)
Definition: DBThread.h:61
bool IsSet(const TypeInfoRef &type) const
Definition: TypeInfoSet.h:147
bool operator==(const TypeInfoSetConstIterator &other) const
Definition: TypeInfoSet.h:80
TypeInfoRef value_type
Definition: TypeInfoSet.h:36
Definition: Area.h:38
const TypeInfoRef & reference
Definition: TypeInfoSet.h:37
#define CLASS_FINAL
Definition: Compiler.h:26
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
TypeInfoSetConstIterator begin() const
Definition: TypeInfoSet.h:180
TypeInfoSetConstIterator & operator++()
Definition: TypeInfoSet.h:59
void Clear()
Definition: TypeInfoSet.h:127
TypeInfoSetConstIterator operator++(int)
Definition: TypeInfoSet.h:71
bool operator==(const MapView &a, const MapView &b)
Definition: InputHandler.h:222
Definition: DBThread.h:86
TypeInfoSetConstIterator self_type
Definition: TypeInfoSet.h:35
std::shared_ptr< TypeInfo > TypeInfoRef
Definition: TypeConfig.h:58
bool Empty() const
Definition: TypeInfoSet.h:155
size_t Size() const
Definition: TypeInfoSet.h:160
bool operator!=(const TypeInfoSetConstIterator &other) const
Definition: TypeInfoSet.h:85
std::input_iterator_tag iterator_category
Definition: TypeInfoSet.h:39