23#ifndef VCL_SPACE_CORE_VECTOR_POLYMORPHIC_OBJECT_VECTOR_H
24#define VCL_SPACE_CORE_VECTOR_POLYMORPHIC_OBJECT_VECTOR_H
26#include "pointer_vector.h"
28#include <vclib/concepts/polymorphism.h>
64template<Cloneable T,
int N = -1>
72 using ValueType = Base::ValueType;
80 using Iterator = BaseVector::ConstIterator;
112 using Base::operator[];
113 using Base::operator();
129 if constexpr (N < 0) {
133 other.begin(),
other.end(), Base::begin(), [](
const auto& e) {
165 if constexpr (N >= 0) {
168 "Vector must have " + std::to_string(N) +
" size.");
194 template<
typename ItType>
214 template<Range RangeType>
233 ValueType
at(uint
i) {
return Base::at(
i); }
245 ValueType
atMod(
int i) {
return Base::atMod(
i); }
255 ValueType
front() {
return Base::front(); }
265 ValueType
back() {
return Base::back(); }
279 Base::at(
i) = e.clone();
294 Base::at(
it - Base::begin()) = e.clone();
316 uint
n = std::ranges::distance(
r);
318 if constexpr (N >= 0) {
319 n = std::min((uint) N,
n);
328 std::ranges::begin(
r),
329 std::ranges::begin(
r) +
n,
347 for (uint
i = 0;
i <
size();
i++) {
348 Base::at(
i) = e.clone();
368 void resize(uint
n,
const T& v)
requires (N < 0)
374 Base::at(
i) = v.clone();
429 void insert(uint
i,
const T& v)
requires (N < 0)
515 Iterator
begin() {
return Base::begin(); }
522 Iterator
end() {
return Base::end(); }
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
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
bool contains(const MakeConstPointerT< T > &e) const
Check if the Vector contains the specified element.
Definition vector.h:471
bool empty() const noexcept
Returns whether the vector is empty (i.e. whether its size is 0).
Definition vector.h:651
void set(uint i, const T &e)
Set the value of the element at the specified position.
Definition vector.h:366
void fill(const T &e)
Fill all elements of the Vector with the specified value.
Definition vector.h:457
Vector()=default
Creates an empty Vector object.
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
friend void swap(Vector &a, Vector &b)
Definition vector.h:542
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
The PolymorphicObjectVector class is a container that stores a collection of polymorphic objects,...
Definition polymorphic_object_vector.h:66
std::size_t size() const
Returns the size of the container.
Definition vector.h:221
PolymorphicObjectVector & operator=(PolymorphicObjectVector other)
Assignment operator of the PolymorphicObjectVector.
Definition polymorphic_object_vector.h:502
ValueType atMod(int i)
Access the specified element, computing first the module of the position w.r.t. the size of the conta...
Definition polymorphic_object_vector.h:245
friend void swap(PolymorphicObjectVector &a, PolymorphicObjectVector &b)
Definition polymorphic_object_vector.h:473
void pushBack(T &&v)
Add an element to the end of the Vector.
Definition polymorphic_object_vector.h:410
ValueType at(uint i)
Access the specified element with bounds checking.
Definition polymorphic_object_vector.h:233
Iterator begin()
Return an iterator pointing to the beginning of the Vector.
Definition polymorphic_object_vector.h:515
void resize(uint n, const T &v)
Resize the Vector to the specified size.
Definition polymorphic_object_vector.h:368
void fill(const T &e)
Fill all elements of the Vector with clones of the specified value.
Definition polymorphic_object_vector.h:345
PolymorphicObjectVector(ItType first, ItType last)
Constructs the container with the contents of the range [first, last).
Definition polymorphic_object_vector.h:195
void set(Base::ConstIterator it, const T &e)
Set the value of the element at the specified position.
Definition polymorphic_object_vector.h:291
void swap(PolymorphicObjectVector &other)
Swaps the contents of the container with those of other.
Definition polymorphic_object_vector.h:462
void set(uint i, const T &e)
Set the value of the element at the specified position.
Definition polymorphic_object_vector.h:276
void pushBack(const T &v)
Add an element to the end of the Vector.
Definition polymorphic_object_vector.h:394
PolymorphicObjectVector(PolymorphicObjectVector &&other) noexcept
Move constructor.
Definition polymorphic_object_vector.h:143
ValueType operator[](uint i)
Returns a reference to the element at specified location i. No bounds checking is performed.
Definition polymorphic_object_vector.h:486
void set(Rng &&r)
Set the elements of the Vector using the values from a range.
Definition polymorphic_object_vector.h:314
PolymorphicObjectVector(const PolymorphicObjectVector &other)
Creates a Vector object with copied of the elements of the other Vector.
Definition polymorphic_object_vector.h:127
PolymorphicObjectVector(RangeType &&rng)
Constructs the container with the contents of the range rng.
Definition polymorphic_object_vector.h:215
void insert(uint i, const T &v)
Insert an element at the specified position in the Vector.
Definition polymorphic_object_vector.h:429
void insert(uint i, T &&v)
Insert an element at the specified position in the Vector.
Definition polymorphic_object_vector.h:451
ValueType front()
Access the first element of the Vector.
Definition polymorphic_object_vector.h:255
PolymorphicObjectVector(std::size_t size, const T &value)
Creates a Vector object with the specified size.
Definition polymorphic_object_vector.h:163
ValueType back()
Access the last element of the Vector.
Definition polymorphic_object_vector.h:265
Iterator end()
Return an iterator pointing to the end of the Vector.
Definition polymorphic_object_vector.h:522
ValueType operator()(uint i)
Returns a reference to the element at specified location i. No bounds checking is performed.
Definition polymorphic_object_vector.h:494
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
The View class is a simple class that stores and exposes two iterators begin and end.
Definition view.h:67
Exception thrown when the size (generally of a container) is not the expected one.
Definition misc.h:38