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"
62template<Cloneable T,
int N = -1>
70 using ValueType = Base::ValueType;
78 using Iterator = BaseVector::ConstIterator;
110 using Base::operator[];
111 using Base::operator();
127 if constexpr (N < 0) {
131 other.begin(),
other.end(), Base::begin(), [](
const auto& e) {
163 if constexpr (N >= 0) {
166 "Vector must have " + std::to_string(N) +
" size.");
192 template<
typename ItType>
212 template<Range RangeType>
231 ValueType
at(uint
i) {
return Base::at(
i); }
243 ValueType
atMod(
int i) {
return Base::atMod(
i); }
253 ValueType
front() {
return Base::front(); }
263 ValueType
back() {
return Base::back(); }
277 Base::at(
i) = e.clone();
292 Base::at(
it - Base::begin()) = e.clone();
314 uint
n = std::ranges::distance(
r);
316 if constexpr (N >= 0) {
317 n = std::min((uint) N,
n);
326 std::ranges::begin(
r),
327 std::ranges::begin(
r) +
n,
345 for (uint
i = 0;
i <
size();
i++) {
346 Base::at(
i) = e.clone();
366 void resize(uint
n,
const T& v)
requires (N < 0)
372 Base::at(
i) = v.clone();
427 void insert(uint
i,
const T& v)
requires (N < 0)
513 Iterator
begin() {
return Base::begin(); }
520 Iterator
end() {
return Base::end(); }
A class representing a box in N-dimensional space.
Definition box.h:46
PointT size() const
Computes the size of the box.
Definition box.h:267
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:73
std::size_t size() const
Returns the size of the container.
Definition vector.h:218
void resize(uint n, const T &v=T())
Resize the Vector to the specified size.
Definition vector.h:554
void erase(uint i)
Remove the element at the specified index from the Vector.
Definition vector.h:661
bool contains(const MakeConstPointerT< T > &e) const
Check if the Vector contains the specified element.
Definition vector.h:468
bool empty() const noexcept
Returns whether the vector is empty (i.e. whether its size is 0).
Definition vector.h:648
void set(uint i, const T &e)
Set the value of the element at the specified position.
Definition vector.h:363
void fill(const T &e)
Fill all elements of the Vector with the specified value.
Definition vector.h:454
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:516
void pushBack(const T &v)
Add an element to the end of the Vector.
Definition vector.h:570
void insert(uint i, const T &v)
Insert an element at the specified position in the Vector.
Definition vector.h:600
void clear()
Remove all elements from the Vector.
Definition vector.h:675
friend void swap(Vector &a, Vector &b)
Definition vector.h:539
static const int SIZE
Size of the vector at compile time. It will be -1 if the Vector has dynamic size.
Definition vector.h:108
The PolymorphicObjectVector class is a container that stores a collection of polymorphic objects,...
Definition polymorphic_object_vector.h:64
std::size_t size() const
Returns the size of the container.
Definition vector.h:218
PolymorphicObjectVector & operator=(PolymorphicObjectVector other)
Assignment operator of the PolymorphicObjectVector.
Definition polymorphic_object_vector.h:500
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:243
friend void swap(PolymorphicObjectVector &a, PolymorphicObjectVector &b)
Definition polymorphic_object_vector.h:471
void pushBack(T &&v)
Add an element to the end of the Vector.
Definition polymorphic_object_vector.h:408
ValueType at(uint i)
Access the specified element with bounds checking.
Definition polymorphic_object_vector.h:231
Iterator begin()
Return an iterator pointing to the beginning of the Vector.
Definition polymorphic_object_vector.h:513
void resize(uint n, const T &v)
Resize the Vector to the specified size.
Definition polymorphic_object_vector.h:366
void fill(const T &e)
Fill all elements of the Vector with clones of the specified value.
Definition polymorphic_object_vector.h:343
PolymorphicObjectVector(ItType first, ItType last)
Constructs the container with the contents of the range [first, last).
Definition polymorphic_object_vector.h:193
void set(Base::ConstIterator it, const T &e)
Set the value of the element at the specified position.
Definition polymorphic_object_vector.h:289
void swap(PolymorphicObjectVector &other)
Swaps the contents of the container with those of other.
Definition polymorphic_object_vector.h:460
void set(uint i, const T &e)
Set the value of the element at the specified position.
Definition polymorphic_object_vector.h:274
void pushBack(const T &v)
Add an element to the end of the Vector.
Definition polymorphic_object_vector.h:392
PolymorphicObjectVector(PolymorphicObjectVector &&other) noexcept
Move constructor.
Definition polymorphic_object_vector.h:141
ValueType operator[](uint i)
Returns a reference to the element at specified location i. No bounds checking is performed.
Definition polymorphic_object_vector.h:484
void set(Rng &&r)
Set the elements of the Vector using the values from a range.
Definition polymorphic_object_vector.h:312
PolymorphicObjectVector(const PolymorphicObjectVector &other)
Creates a Vector object with copied of the elements of the other Vector.
Definition polymorphic_object_vector.h:125
PolymorphicObjectVector(RangeType &&rng)
Constructs the container with the contents of the range rng.
Definition polymorphic_object_vector.h:213
void insert(uint i, const T &v)
Insert an element at the specified position in the Vector.
Definition polymorphic_object_vector.h:427
void insert(uint i, T &&v)
Insert an element at the specified position in the Vector.
Definition polymorphic_object_vector.h:449
ValueType front()
Access the first element of the Vector.
Definition polymorphic_object_vector.h:253
PolymorphicObjectVector(std::size_t size, const T &value)
Creates a Vector object with the specified size.
Definition polymorphic_object_vector.h:161
ValueType back()
Access the last element of the Vector.
Definition polymorphic_object_vector.h:263
Iterator end()
Return an iterator pointing to the end of the Vector.
Definition polymorphic_object_vector.h:520
ValueType operator()(uint i)
Returns a reference to the element at specified location i. No bounds checking is performed.
Definition polymorphic_object_vector.h:492
The Vector class is a generic container of objects of type T, that could have fixed or dynamic size,...
Definition vector.h:62
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 exceptions.h:45