Visual Computing Library  devel
Loading...
Searching...
No Matches
static_grid_iterator.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_SPACE_COMPLEX_GRID_ITERATORS_STATIC_GRID_ITERATOR_H
24#define VCL_SPACE_COMPLEX_GRID_ITERATORS_STATIC_GRID_ITERATOR_H
25
26#include <vclib/space/core.h>
27
28namespace vcl {
29
30template<typename KeyType, typename ValueType, typename GridType>
32{
33 using VecIt = std::vector<std::pair<uint, ValueType>>::iterator;
34
35 VecIt mVecIt;
36 const GridType* mGrid = nullptr;
37
38public:
40 using value_type = T;
41
43 {
44 T mValue;
45
46 public:
47 ArrowHelper(T value) : mValue(value) {}
48
49 const T* operator->() const { return &mValue; }
50 };
51
52 StaticGridIterator() = default;
53
54 StaticGridIterator(VecIt it, const GridType& g) : mVecIt(it), mGrid(&g) {}
55
56 value_type operator*() const
57 {
58 KeyType cell = mGrid->cellOfIndex(mVecIt->first);
59 return value_type(cell, mVecIt->second);
60 }
61
62 ArrowHelper operator->() const { return **this; }
63
64 bool operator==(const StaticGridIterator& oi) const
65 {
66 return mVecIt == oi.mVecIt;
67 }
68
69 bool operator!=(const StaticGridIterator& oi) const
70 {
71 return mVecIt != oi.mVecIt;
72 }
73
74 StaticGridIterator operator++()
75 {
76 ++mVecIt;
77 return *this;
78 }
79
80 StaticGridIterator operator++(int)
81 {
82 StaticGridIterator old = *this;
83 ++mVecIt;
84 return old;
85 }
86};
87
88template<typename KeyType, typename ValueType, typename GridType>
90{
91 using VecIt = std::vector<std::pair<uint, ValueType>>::const_iterator;
92
93 VecIt mVecIt;
94 const GridType* mGrid = nullptr;
95
96public:
98 using value_type = T;
99
100 ConstStaticGridIterator() = default;
101
102 ConstStaticGridIterator(VecIt it, const GridType& g) : mVecIt(it), mGrid(&g)
103 {
104 }
105
106 value_type operator*() const
107 {
108 KeyType cell = mGrid->cellOfIndex(mVecIt->first);
109 return value_type(cell, mVecIt->second);
110 }
111
112 auto operator->() const { return FakePointerWithValue(**this); }
113
114 bool operator==(const ConstStaticGridIterator& oi) const
115 {
116 return mVecIt == oi.mVecIt;
117 }
118
119 bool operator!=(const ConstStaticGridIterator& oi) const
120 {
121 return mVecIt != oi.mVecIt;
122 }
123
124 ConstStaticGridIterator operator++()
125 {
126 ++mVecIt;
127 return *this;
128 }
129
130 ConstStaticGridIterator operator++(int)
131 {
133 ++mVecIt;
134 return old;
135 }
136};
137
138} // namespace vcl
139
140#endif // VCL_SPACE_COMPLEX_GRID_ITERATORS_STATIC_GRID_ITERATOR_H
A class representing a box in N-dimensional space.
Definition box.h:46
Definition static_grid_iterator.h:90
A simple utility class to represent a pointer with a value.
Definition base.h:121
Definition static_grid_iterator.h:43
Definition static_grid_iterator.h:32