TrinityCore
DBStorageIterator.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef DBStorageIterator_h__
19#define DBStorageIterator_h__
20
21#include "Define.h"
22#include <iterator>
23
24template<class T>
26{
27public:
28 using iterator_category = std::forward_iterator_tag;
29 using value_type = T;
30 using difference_type = std::ptrdiff_t;
31 using pointer = T*;
32 using reference = T&;
33
34 DBStorageIterator() : _index(nullptr), _pos(0), _end(0) { }
35 DBStorageIterator(T const* const* index, uint32 size, uint32 pos = 0) : _index(index), _pos(pos), _end(size)
36 {
37 if (_pos < _end)
38 {
39 while (_pos < _end && !_index[_pos])
40 ++_pos;
41 }
42 }
43
44 T const* operator->() const { return _index[_pos]; }
45 T const* operator*() const { return _index[_pos]; }
46
47 bool operator==(DBStorageIterator const& right) const { /*ASSERT(_index == right._index, "Iterator belongs to a different container")*/ return _pos == right._pos; }
48
50 {
51 if (_pos < _end)
52 {
53 do
54 ++_pos;
55 while (_pos < _end && !_index[_pos]);
56 }
57
58 return *this;
59 }
60
62 {
63 DBStorageIterator tmp = *this;
64 ++*this;
65 return tmp;
66 }
67
68private:
69 T const* const* _index;
72};
73
74#endif // DBStorageIterator_h__
uint32_t uint32
Definition: Define.h:142
T const *const * _index
DBStorageIterator & operator++()
std::ptrdiff_t difference_type
std::forward_iterator_tag iterator_category
DBStorageIterator(T const *const *index, uint32 size, uint32 pos=0)
bool operator==(DBStorageIterator const &right) const
T const * operator->() const
DBStorageIterator operator++(int)
T const * operator*() const
constexpr std::size_t size()
Definition: UpdateField.h:796