Visual Computing Library
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/misc/pair.h>
27#include <vclib/space/core/point.h>
28
29namespace vcl {
30
31template<typename KeyType, typename ValueType, typename GridType>
33{
34 using VecIt = std::vector<std::pair<uint, ValueType>>::iterator;
35
36 VecIt mVecIt;
37 const GridType* mGrid = nullptr;
38
39public:
41 using value_type = T;
42
44 {
45 T mValue;
46
47 public:
48 ArrowHelper(T value) : mValue(value) {}
49
50 const T* operator->() const { return &mValue; }
51 };
52
53 StaticGridIterator() = default;
54
55 StaticGridIterator(VecIt it, const GridType& g) : mVecIt(it), mGrid(&g) {}
56
57 value_type operator*() const
58 {
59 KeyType cell = mGrid->cellOfIndex(mVecIt->first);
60 return value_type(cell, mVecIt->second);
61 }
62
63 ArrowHelper operator->() const { return **this; }
64
65 bool operator==(const StaticGridIterator& oi) const
66 {
67 return mVecIt == oi.mVecIt;
68 }
69
70 bool operator!=(const StaticGridIterator& oi) const
71 {
72 return mVecIt != oi.mVecIt;
73 }
74
75 StaticGridIterator operator++()
76 {
77 ++mVecIt;
78 return *this;
79 }
80
81 StaticGridIterator operator++(int)
82 {
83 StaticGridIterator old = *this;
84 ++mVecIt;
85 return old;
86 }
87};
88
89template<typename KeyType, typename ValueType, typename GridType>
91{
92 using VecIt = std::vector<std::pair<uint, ValueType>>::const_iterator;
93
94 VecIt mVecIt;
95 const GridType* mGrid = nullptr;
96
97public:
99 using value_type = T;
100
101 ConstStaticGridIterator() = default;
102
103 ConstStaticGridIterator(VecIt it, const GridType& g) : mVecIt(it), mGrid(&g)
104 {
105 }
106
107 value_type operator*() const
108 {
109 KeyType cell = mGrid->cellOfIndex(mVecIt->first);
110 return value_type(cell, mVecIt->second);
111 }
112
113 auto operator->() const { return FakePointerWithValue(**this); }
114
115 bool operator==(const ConstStaticGridIterator& oi) const
116 {
117 return mVecIt == oi.mVecIt;
118 }
119
120 bool operator!=(const ConstStaticGridIterator& oi) const
121 {
122 return mVecIt != oi.mVecIt;
123 }
124
125 ConstStaticGridIterator operator++()
126 {
127 ++mVecIt;
128 return *this;
129 }
130
131 ConstStaticGridIterator operator++(int)
132 {
134 ++mVecIt;
135 return old;
136 }
137};
138
139} // namespace vcl
140
141#endif // VCL_SPACE_COMPLEX_GRID_ITERATORS_STATIC_GRID_ITERATOR_H
Definition static_grid_iterator.h:91
A simple utility class to represent a pointer with a value.
Definition base.h:121
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
Definition static_grid_iterator.h:44
Definition static_grid_iterator.h:33