summaryrefslogtreecommitdiffhomepage
path: root/src/tile-iterator.hpp
blob: f3b19dfc769b81c30823e0f675403aaa61c2d831 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#pragma once

#include "local-coords.hpp"
#include "tile.hpp"

#include <iterator>

namespace floormat {

struct tile_iterator_tuple final { // NOLINT(cppcoreguidelines-pro-type-member-init)
    const tile_iterator_tuple* operator->() const noexcept { return this; }
    tile_iterator_tuple* operator->() noexcept { return this; }

    tile_ref x;
    size_t k;
    local_coords pt;
};

struct tile_const_iterator_tuple final { // NOLINT(cppcoreguidelines-pro-type-member-init)
    const tile_const_iterator_tuple* operator->() const noexcept { return this; }
    tile_const_iterator_tuple* operator->() noexcept { return this; }

    tile_proto x;
    size_t k;
    local_coords pt;
};

class tile_iterator final {
    chunk* c;
    size_t pos;

    friend bool operator==(const tile_iterator&, const tile_iterator&) noexcept;

public:
    explicit tile_iterator(chunk& c, size_t pos) noexcept;
    tile_iterator(const tile_iterator&) noexcept;
    tile_iterator& operator=(const tile_iterator&) noexcept;

    void swap(tile_iterator& other) noexcept;

    tile_iterator& operator++() noexcept;
    tile_iterator operator++(int) noexcept;
    tile_iterator_tuple operator->() noexcept;
    tile_iterator_tuple operator*() noexcept;

    using difference_type = ptrdiff_t;
    using value_type = tile_iterator_tuple;
    using pointer = value_type;
    using reference = value_type;
    using iterator_category = std::input_iterator_tag;
};

class tile_const_iterator final {
    const chunk* c;
    size_t pos;

    friend bool operator==(const tile_const_iterator&, const tile_const_iterator&) noexcept;

public:
    explicit tile_const_iterator(const chunk& c, size_t pos) noexcept;
    tile_const_iterator(const tile_const_iterator&) noexcept;
    tile_const_iterator& operator=(const tile_const_iterator&) noexcept;

    void swap(tile_const_iterator& other) noexcept;

    tile_const_iterator& operator++() noexcept;
    tile_const_iterator operator++(int) noexcept;
    tile_const_iterator_tuple operator->() noexcept;
    tile_const_iterator_tuple operator*() noexcept;

    using difference_type = ptrdiff_t;
    using value_type = tile_const_iterator_tuple;
    using pointer = value_type;
    using reference = value_type;
    using iterator_category = std::input_iterator_tag;
};

} // namespace floormat