Arduino DLNA Server
Loading...
Searching...
No Matches
Vector.h
Go to the documentation of this file.
1#include "dlna_config.h"
2#include "Allocator.h"
3
4#pragma once
5#include <assert.h>
6#include <vector>
7#include <memory>
8
9namespace tiny_dlna {
10
38template <class T, class Alloc = DLNA_ALLOCATOR<T>>
39class Vector : public std::vector<T, Alloc> {
40 public:
41 using Base = std::vector<T, Alloc>;
42 using Base::Base;
43 using value_type = T;
44 using iterator = typename Base::iterator;
45 using const_iterator = typename Base::const_iterator;
46 // expose base erase overloads (iterator, range) alongside our index helper
47 using Base::erase;
48
49 Vector() = default;
50 explicit Vector(size_t count) : Base(count) {}
51 Vector(size_t count, const T &value) : Base(count, value) {}
52 template <class It>
53 Vector(It first, It last) : Base(first, last) {}
54 Vector(std::initializer_list<T> il) : Base(il) {}
55 explicit Vector(const Alloc &alloc) : Base(alloc) {}
56
62 void eraseIndex(int index) {
63 if (index < 0 || static_cast<size_t>(index) >= this->size()) return;
64 Base::erase(this->begin() + index);
65 }
66
73 iterator erase(size_t index) {
74 if (index >= this->size()) return this->end();
75 return Base::erase(this->begin() + static_cast<typename Base::difference_type>(index));
76 }
77
83 void reset() {
84 this->clear();
85 this->shrink_to_fit();
86 }
87};
88
89} // namespace tiny_dlna
Lightweight wrapper around std::vector with Arduino-friendly helpers and a pluggable allocator.
Definition: Vector.h:39
std::vector< T, Alloc > Base
Definition: Vector.h:41
T value_type
Definition: Vector.h:43
void reset()
Reset the container by clearing and shrinking capacity to fit.
Definition: Vector.h:83
void eraseIndex(int index)
Erase element by index (no-op on out-of-range).
Definition: Vector.h:62
typename Base::iterator iterator
Definition: Vector.h:44
Vector(It first, It last)
Definition: Vector.h:53
Vector(size_t count)
Definition: Vector.h:50
Vector(std::initializer_list< T > il)
Definition: Vector.h:54
typename Base::const_iterator const_iterator
Definition: Vector.h:45
Vector(const Alloc &alloc)
Definition: Vector.h:55
iterator erase(size_t index)
Convenience overload to erase by index.
Definition: Vector.h:73
Vector(size_t count, const T &value)
Definition: Vector.h:51
Definition: Allocator.h:13