22 #ifndef CRNVECTOR_HEADER
23 #define CRNVECTOR_HEADER
56 size_t Size() const noexcept {
return data.size(); }
58 bool IsEmpty() const noexcept {
return data.empty(); }
65 SObject&
At(
size_t i) {
return data[i]; }
67 SCObject
At(
size_t i)
const {
return data[i]; }
70 SObject&
Front() {
return data.front(); }
72 SCObject
Front()
const {
return data.front(); }
74 SObject&
Back() {
return data.back(); }
76 SCObject
Back()
const {
return data.back(); }
78 bool Contains(
const SCObject &o)
const;
82 void Insert(
const SObject &d,
size_t pos);
87 void ReorderTo(
const std::vector<size_t> &to);
94 void Remove(
const SCObject &obj);
96 void Clear() noexcept { data.clear(); }
125 template<
typename T> std::vector<std::shared_ptr<T>>
ToStd()
127 std::vector<std::shared_ptr<T>> v;
129 v.push_back(std::dynamic_pointer_cast<T>(*it));
133 template<
typename T> std::vector<std::shared_ptr<const T>>
ToStd()
const
135 std::vector<std::shared_ptr<const T>> v;
137 v.push_back(std::dynamic_pointer_cast<const T>(*it));
141 std::vector<SObject>
Std() && {
return std::move(data); }
154 virtual std::string getClassName()
const {
return "Vector"; }
156 std::vector<SObject> data;
169 inline size_t Size(
const Vector &v) noexcept {
return v.Size(); }
void Swap(Vector &other) noexcept
Swaps contents with another vector.
SCObject operator[](size_t i) const
Returns an object from index (unsafe)
std::vector< SObject > Std()&&
Gets the inner data.
const_iterator Find(const SCObject &o) const
Finds an object in the container.
SCObject Back() const
Returns a reference to the last element.
#define CRN_ADD_RANGED_FOR_TO_CONST_POINTERS(TYPE)
Enables ranged for for smart pointers on a type.
SObject & Back()
Returns a reference to the last element.
void ShrinkToFit()
Optimizes the memory usage.
SCObject At(size_t i) const
Returns an object from index (unsafe)
#define CRN_ADD_RANGED_FOR_TO_POINTERS(TYPE)
Enables ranged for for smart pointers on a type.
iterator begin()
Returns an iterator to the first element.
void Remove(size_t index)
Removes an element (safe)
virtual ~Vector() override
Destructor.
Vector & operator=(const Vector &)
void Insert(const SObject &d, size_t pos)
Inserts an object at a given position.
size_t Size(const Vector &v) noexcept
Size of a vector.
const_iterator end() const
Returns a const iterator to the end of the list.
SObject & operator[](size_t i)
Returns an object from index (unsafe)
bool Contains(const SCObject &o) const
Checks of the object is in the vector.
void Clear() noexcept
Empties the vector.
double Distance(const Int &i1, const Int &i2) noexcept
xml::Element Serialize(xml::Element &parent) const
Dumps to an XML node if applicable.
const_iterator cbegin() const
Returns a const iterator to the first element.
iterator end()
Returns a iterator to the end of the list.
void Swap(Map &m1, Map &m2) noexcept
std::vector< std::shared_ptr< T > > ToStd()
Converts to a std::vector of pointers.
Vector()
Default constructor.
const_iterator begin() const
Returns a const iterator to the first element.
void Deserialize(xml::Element &el)
Reads from an XML node if applicable.
void PopBack()
Removes the last element.
void ReorderFrom(const std::vector< size_t > &from)
Reorders the elements.
std::vector< std::shared_ptr< const T > > ToStd() const
Converts to a std::vector of pointers.
#define CRN_DECLARE_CLASS_CONSTRUCTOR(classname)
Declares a class constructor.
void RemoveIf(Predicate pred)
Removes elements if predicate is true.
SCObject Front() const
Returns a reference to the first element.
void PushBack(const SObject &d)
Adds an object at the end of the vector.
SObject & Front()
Returns a reference to the first element.
SObject & At(size_t i)
Returns an object from index (unsafe)
size_t Size() const noexcept
Returns the number of data objects in the vector.
void ReorderTo(const std::vector< size_t > &to)
Reorders the elements.
const_iterator cend() const
Returns a const iterator to the end of the list.
bool IsEmpty() const noexcept
Tests if the vector is empty.