Visual Computing Library
Loading...
Searching...
No Matches
pointer_vector.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_CORE_VECTOR_POINTER_VECTOR_H
24#define VCL_SPACE_CORE_VECTOR_POINTER_VECTOR_H
25
26#include "vector.h"
27
28#include <vclib/concepts/pointers.h>
29#include <vclib/misc/iterators/const_pointer_iterator.h>
30
31namespace vcl {
32
74template<IsAnyPointer T, int N = -1>
75class PointerVector : protected Vector<T, N>
76{
77 using Base = Vector<T, N>;
78
79public:
80 // types
81 using ValueType = Base::ValueType;
82
84
85 using Reference = Base::Reference;
86
87 using ConstPointer = const ConstValueType*;
88
89 using Pointer = Base::Pointer;
90
91 using Iterator = Base::Iterator;
92
94
95 using Base::SIZE;
96
97 // constructors
98 using Base::Vector;
99
100 // exposing members of base class, later we will redefine const member
101 // functions
102 using Base::at;
103 using Base::atMod;
104 using Base::back;
105 using Base::clear;
106 using Base::contains;
107 using Base::data;
108 using Base::empty;
109 using Base::erase;
110 using Base::fill;
111 using Base::find;
112 using Base::front;
113 using Base::indexOf;
114 using Base::insert;
115 using Base::pushBack;
116 using Base::resize;
117 using Base::set;
118 using Base::size;
119 using Base::swap;
120 using Base::operator[];
121 using Base::operator();
122 using Base::begin;
123 using Base::end;
124
125 // const member function redefinitions: return types change to const
126
127 ConstValueType at(uint i) const { return Base::at(i); }
128
129 ConstValueType atMod(uint i) const { return Base::atMod(i); }
130
131 ConstValueType front() const { return Base::front(); }
132
133 ConstValueType back() const { return Base::back(); }
134
135 ConstPointer data() const { return Base::data(); }
136
137 ConstIterator find(const MakeConstPointer<T>& e) const
138 {
139 return Base::find(e);
140 }
141
142 ConstValueType operator[](uint i) const { return Base::operator[](i); }
143
144 ConstValueType operator()(uint i) const { return Base::operator()(i); }
145
146 ConstIterator begin() const { return Base::begin(); }
147
148 ConstIterator end() const { return Base::end(); }
149};
150
151} // namespace vcl
152
153#endif // VCL_SPACE_CORE_VECTOR_POINTER_VECTOR_H
The ConstPointerIterator class is a utility class that wraps an iterator of a container of [shared] p...
Definition const_pointer_iterator.h:57
The PointerVector class is a utility container that stores a sequence of pointers that preserve their...
Definition pointer_vector.h:76
Pointer data()
Returns a pointer to the underlying array serving as element storage. The pointer is such that range ...
Definition vector.h:343
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
The Vector class is a generic container of objects of type T, that could have fixed or dynamic size,...
Definition vector.h:65
Reference operator()(uint i)
Returns a reference to the element at specified location i. No bounds checking is performed.
Definition vector.h:708
Reference atMod(int i)
Access the specified element, computing first the module of the position w.r.t. the size of the conta...
Definition vector.h:271
Container::reference Reference
A reference to the type of the elements stored in the Vector.
Definition vector.h:91
std::size_t size() const
Returns the size of the container.
Definition vector.h:221
void resize(uint n, const T &v=T())
Resize the Vector to the specified size.
Definition vector.h:557
void erase(uint i)
Remove the element at the specified index from the Vector.
Definition vector.h:664
Container::iterator Iterator
An iterator to the elements of the Vector.
Definition vector.h:102
bool contains(const MakeConstPointerT< T > &e) const
Check if the Vector contains the specified element.
Definition vector.h:471
Reference back()
Access the last element of the Vector.
Definition vector.h:321
bool empty() const noexcept
Returns whether the vector is empty (i.e. whether its size is 0).
Definition vector.h:651
Container::value_type ValueType
The type of the elements stored in the Vector.
Definition vector.h:82
void set(uint i, const T &e)
Set the value of the element at the specified position.
Definition vector.h:366
Container::pointer Pointer
A pointer to the type of the elements stored in the Vector.
Definition vector.h:99
void fill(const T &e)
Fill all elements of the Vector with the specified value.
Definition vector.h:457
Reference at(uint i)
Access the specified element with bounds checking.
Definition vector.h:244
Vector()=default
Creates an empty Vector object.
Iterator find(const MakeConstPointerT< T > &e)
Find the first occurrence of the specified element in the Vector.
Definition vector.h:487
Pointer data()
Returns a pointer to the underlying array serving as element storage. The pointer is such that range ...
Definition vector.h:343
Reference operator[](uint i)
Returns a reference to the element at specified location i. No bounds checking is performed.
Definition vector.h:692
uint indexOf(const MakeConstPointerT< T > &e) const
Get the index of the first occurrence of the specified element in the Vector.
Definition vector.h:519
void pushBack(const T &v)
Add an element to the end of the Vector.
Definition vector.h:573
void insert(uint i, const T &v)
Insert an element at the specified position in the Vector.
Definition vector.h:603
void clear()
Remove all elements from the Vector.
Definition vector.h:678
Iterator end()
Return an iterator pointing to the end of the Vector.
Definition vector.h:732
friend void swap(Vector &a, Vector &b)
Definition vector.h:542
Reference front()
Access the first element of the Vector.
Definition vector.h:301
Iterator begin()
Return an iterator pointing to the beginning of the Vector.
Definition vector.h:725
static const int SIZE
Size of the vector at compile time. It will be -1 if the Vector has dynamic size.
Definition vector.h:111