MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / Iterator

Class Iterator

src/core/bitmath_func.hpp:278–311  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

276template <typename Tbitpos = uint, typename Tbitset = uint>
277struct SetBitIterator {
278 struct Iterator {
279 typedef Tbitpos value_type;
280 typedef value_type *pointer;
281 typedef value_type &reference;
282 typedef size_t difference_type;
283 typedef std::forward_iterator_tag iterator_category;
284
285 explicit Iterator(Tbitset bitset) : bitset(bitset), bitpos(static_cast<Tbitpos>(0))
286 {
287 this->Validate();
288 }
289
290 bool operator==(const Iterator &other) const
291 {
292 return this->bitset == other.bitset;
293 }
294 Tbitpos operator*() const { return this->bitpos; }
295 Iterator & operator++() { this->Next(); this->Validate(); return *this; }
296
297 private:
298 Tbitset bitset;
299 Tbitpos bitpos;
300 void Validate()
301 {
302 if (this->bitset != 0) {
303 typename std::make_unsigned<Tbitset>::type unsigned_value = this->bitset;
304 this->bitpos = static_cast<Tbitpos>(FindFirstBit(unsigned_value));
305 }
306 }
307 void Next()
308 {
309 this->bitset = KillFirstBit(this->bitset);
310 }
311 };
312
313 SetBitIterator(Tbitset bitset) : bitset(bitset) {}
314 Iterator begin() { return Iterator(this->bitset); }

Callers 2

beginMethod · 0.70
endMethod · 0.70

Calls 2

NextMethod · 0.95
ValidateMethod · 0.95

Tested by

no test coverage detected