1#ifndef TATOOINE_PROPERTY_H
2#define TATOOINE_PROPERTY_H
12template <
typename Handle,
typename ValueType>
13struct typed_vector_property;
15template <
typename Handle>
32 virtual
void resize(std::
size_t n) = 0;
38 virtual
void erase(std::
size_t) = 0;
44 [[nodiscard]] virtual auto
type() const -> const std::type_info& = 0;
46 template <typename ValueType>
48 return type() ==
typeid(ValueType);
53 template <typename ValueType>
58 template <
typename ValueType>
62 virtual auto clean(std::set<Handle>
const&) ->
void = 0;
65template <
typename Handle,
typename ValueType>
72 using size_type =
typename container_type::size_type;
74 using reference =
typename container_type::reference;
76 using pointer =
typename container_type::pointer;
78 using iterator =
typename container_type::iterator;
82 typename container_type::const_reverse_iterator;
97 m_data{std::move(other.m_data)},
98 m_value{std::move(other.m_value)} {}
109 m_data = std::move(other.m_data);
110 m_value = std::move(other.m_value);
134 return m_data.erase(first, last);
138 return m_data.erase(first, last);
141 auto erase(std::size_t i) ->
void override {
151 template <
typename... Ts>
153 m_data.emplace_back(std::forward<Ts>(ts)...);
168 auto at(std::size_t
const i) ->
auto& {
169 assert(i <
m_data.size());
174 auto at(std::size_t
const i)
const ->
const auto& {
175 assert(i <
m_data.size());
205 assert(i <
m_data.size());
211 assert(i <
m_data.size());
215 [[nodiscard]]
auto type() const -> const std::type_info&
override {
216 return typeid(ValueType);
220 return std::unique_ptr<this_type>{
new this_type{*
this}};
223 auto clean(std::set<Handle>
const& invalid_handles) ->
void override {
225 cleaned_data.reserve(
m_data.size() - invalid_handles.size());
226 auto invalid_it = invalid_handles.begin();
227 auto i = std::size_t{};
228 for (
auto const& date :
m_data) {
229 if (invalid_it != invalid_handles.end() && *invalid_it == Handle{i}) {
232 cleaned_data.push_back(date);
236 m_data = std::move(cleaned_data);
240template <
typename Handle,
typename ValueType>
241struct typed_deque_property;
243template <
typename Handle>
266 virtual
void erase(std::
size_t) = 0;
272 [[nodiscard]] virtual auto
type() const -> const std::type_info& = 0;
274 template <typename ValueType>
276 return type() ==
typeid(ValueType);
279 template <
typename ValueType>
284 template <
typename ValueType>
292template <typename Handle, typename ValueType>
303 using pointer =
typename container_type::pointer;
305 using iterator =
typename container_type::iterator;
309 typename container_type::const_reverse_iterator;
320 :
parent_type{other}, m_data{other.m_data}, m_value{other.m_value} {}
324 m_data{std::move(other.m_data)},
325 m_value{std::move(other.m_value)} {}
328 parent_type::operator=(other);
329 m_data = other.m_data;
330 m_value = other.m_value;
335 parent_type::operator=(std::move(other));
336 m_data = std::move(other.m_data);
337 m_value = std::move(other.m_value);
341 auto size() {
return m_data.size(); }
344 void resize(std::size_t n)
override { m_data.resize(n); }
346 void push_back()
override { m_data.push_back(m_value); }
347 void push_back(
const ValueType& value) { m_data.push_back(value); }
350 void push_front(
const ValueType& value) { m_data.push_front(value); }
352 auto front() ->
auto& {
return m_data.front(); }
353 auto front() const -> const auto& {
return m_data.front(); }
355 auto back() ->
auto& {
return m_data.back(); }
356 auto back() const -> const auto& {
return m_data.back(); }
363 return m_data.erase(first, last);
367 return m_data.erase(first, last);
372 auto begin() {
return m_data.begin(); }
373 auto begin()
const {
return m_data.begin(); }
375 auto end() {
return m_data.end(); }
376 auto end()
const {
return m_data.end(); }
378 template <
typename... Ts>
380 m_data.emplace_back(std::forward<Ts>(ts)...);
385 m_data.shrink_to_fit();
390 auto data()
const {
return m_data.data(); }
392 auto size()
const {
return m_data.size(); }
420 assert(i < m_data.size());
426 assert(i < m_data.size());
430 [[nodiscard]]
auto type() const -> const std::type_info&
override {
431 return typeid(ValueType);
435 return std::unique_ptr<this_type>{
new this_type{*
this}};
Definition: algorithm.h:6
auto begin(Range &&range)
Definition: iterator_facade.h:318
auto next(Iter iter)
Definition: iterator_facade.h:325
Definition: property.h:244
virtual void erase(std::size_t)=0
Resize storage to hold n elements.
virtual void resize(std::size_t n)=0
Resize storage to hold n elements.
deque_property(const deque_property &other)=default
virtual auto clone() const -> std::unique_ptr< this_type >=0
virtual void push_back()=0
pushes element at back
virtual auto type() const -> const std::type_info &=0
for identifying type.
auto cast_to_typed() const -> decltype(auto)
Definition: property.h:285
auto cast_to_typed() -> decltype(auto)
Definition: property.h:280
deque_property(deque_property &&other) noexcept=default
virtual void clear()=0
Free unused memory.
auto operator=(const deque_property &) -> deque_property &=default
virtual void push_front()=0
pushes element at front
auto holds_type() const
Definition: property.h:275
auto operator=(deque_property &&) noexcept -> deque_property &
auto index() const
Definition: handle.h:64
Definition: property.h:293
auto emplace_back(Ts &&... ts) -> void
Definition: property.h:379
auto operator=(const typed_deque_property &other) -> auto &
Definition: property.h:327
auto clone() const -> std::unique_ptr< parent_type > override
Definition: property.h:434
typename container_type::const_iterator const_iterator
Definition: property.h:306
typename container_type::const_pointer const_pointer
Definition: property.h:304
auto erase(iterator first, iterator last)
Definition: property.h:362
auto end()
Definition: property.h:375
auto back() const -> const auto &
Definition: property.h:356
auto size()
Definition: property.h:341
auto back() -> auto &
Definition: property.h:355
auto internal_container() const -> const auto &
Definition: property.h:388
typename container_type::reverse_iterator reverse_iterator
Definition: property.h:307
typename container_type::pointer pointer
Definition: property.h:303
void push_back() override
pushes element at back
Definition: property.h:346
auto clear() -> void override
Free unused memory.
Definition: property.h:383
std::deque< ValueType > container_type
Definition: property.h:296
typename container_type::allocator_type allocator_type
Definition: property.h:298
typename container_type::difference_type difference_type
Definition: property.h:300
auto erase(iterator pos)
Definition: property.h:358
auto operator=(typed_deque_property &&other) noexcept -> auto &
Definition: property.h:334
typed_deque_property(typed_deque_property &&other) noexcept
Definition: property.h:322
typename container_type::reference reference
Definition: property.h:301
ValueType m_value
Definition: property.h:313
auto operator[](std::size_t const i) const -> const auto &
Const access to the i'th element.
Definition: property.h:425
auto operator[](Handle handle) -> auto &
Access the i'th element.
Definition: property.h:407
auto operator[](Handle handle) const -> const auto &
Const access to the i'th element.
Definition: property.h:413
void erase(std::size_t i) override
Resize storage to hold n elements.
Definition: property.h:370
auto type() const -> const std::type_info &override
for identifying type.
Definition: property.h:430
void resize(std::size_t n) override
Resize storage to hold n elements.
Definition: property.h:344
void push_front() override
pushes element at front
Definition: property.h:349
auto size() const
Definition: property.h:392
typename container_type::iterator iterator
Definition: property.h:305
auto begin() const
Definition: property.h:373
typed_deque_property(const ValueType &value=ValueType{})
Definition: property.h:316
void push_front(const ValueType &value)
Definition: property.h:350
auto erase(const_iterator first, const_iterator last)
Definition: property.h:366
auto front() const -> const auto &
Definition: property.h:353
typename container_type::const_reverse_iterator const_reverse_iterator
Definition: property.h:309
typename container_type::const_reference const_reference
Definition: property.h:302
auto at(Handle handle) const -> const auto &
Const access to the i'th element.
Definition: property.h:401
auto erase(const_iterator pos)
Definition: property.h:360
auto data() const
Definition: property.h:390
void push_back(const ValueType &value)
Definition: property.h:347
auto end() const
Definition: property.h:376
container_type m_data
Definition: property.h:312
auto front() -> auto &
Definition: property.h:352
typename container_type::value_type value_type
Definition: property.h:297
typename container_type::size_type size_type
Definition: property.h:299
auto operator[](std::size_t const i) -> auto &
Access the i'th element.
Definition: property.h:419
typed_deque_property(const typed_deque_property &other)
Definition: property.h:319
auto at(Handle handle) -> auto &
Access the i'th element.
Definition: property.h:395
auto begin()
Definition: property.h:372
Definition: property.h:66
std::vector< ValueType > container_type
Definition: property.h:69
auto size()
Definition: property.h:114
typename container_type::size_type size_type
Definition: property.h:72
typed_vector_property(typed_vector_property &&other) noexcept
Definition: property.h:95
auto data() const
Definition: property.h:161
auto end() const
Definition: property.h:149
auto erase(const_iterator pos)
Definition: property.h:131
typename container_type::const_reference const_reference
Definition: property.h:75
auto back() const -> const auto &
Definition: property.h:127
void push_back() override
pushes element at back
Definition: property.h:120
auto operator[](Handle handle) const -> const auto &
Const access to the i'th element.
Definition: property.h:198
auto operator=(const typed_vector_property &other) -> auto &
Definition: property.h:100
auto back() -> auto &
Definition: property.h:126
typename container_type::difference_type difference_type
Definition: property.h:73
void reserve(std::size_t n) override
Reserve memory for n elements.
Definition: property.h:116
typename container_type::allocator_type allocator_type
Definition: property.h:71
typename container_type::const_iterator const_iterator
Definition: property.h:79
auto operator=(typed_vector_property &&other) noexcept -> auto &
Definition: property.h:107
container_type m_data
Definition: property.h:85
typename container_type::const_reverse_iterator const_reverse_iterator
Definition: property.h:82
void push_back(const ValueType &value)
Definition: property.h:121
typename container_type::reference reference
Definition: property.h:74
auto front() const -> const auto &
Definition: property.h:124
auto at(Handle handle) -> auto &
Access the i'th element.
Definition: property.h:180
void clear() override
Free unused memory.
Definition: property.h:156
auto at(Handle handle) const -> const auto &
Const access to the i'th element.
Definition: property.h:186
typename container_type::pointer pointer
Definition: property.h:76
auto begin()
Definition: property.h:145
auto at(std::size_t const i) -> auto &
Access the i'th element.
Definition: property.h:168
auto front() -> auto &
Definition: property.h:123
void resize(std::size_t n) override
Resize storage to hold n elements.
Definition: property.h:118
typed_vector_property(const ValueType &value=ValueType{})
Definition: property.h:89
auto erase(iterator first, iterator last)
Definition: property.h:133
auto size() const
Definition: property.h:165
auto operator[](Handle handle) -> auto &
Access the i'th element.
Definition: property.h:192
typename container_type::const_pointer const_pointer
Definition: property.h:77
ValueType m_value
Definition: property.h:86
auto clone() const -> std::unique_ptr< parent_type > override
Definition: property.h:219
auto type() const -> const std::type_info &override
for identifying type.
Definition: property.h:215
auto erase(iterator pos)
Definition: property.h:129
auto begin() const
Definition: property.h:146
auto internal_container() const -> auto const &
Definition: property.h:163
auto at(std::size_t const i) const -> const auto &
Const access to the i'th element.
Definition: property.h:174
void emplace_back(Ts &&... ts)
Definition: property.h:152
typename container_type::reverse_iterator reverse_iterator
Definition: property.h:80
auto end()
Definition: property.h:148
auto erase(const_iterator first, const_iterator last)
Definition: property.h:137
auto erase(std::size_t i) -> void override
Resize storage to hold n elements.
Definition: property.h:141
typed_vector_property(const typed_vector_property &other)
Definition: property.h:92
typename container_type::value_type value_type
Definition: property.h:70
typename container_type::iterator iterator
Definition: property.h:78
auto operator[](std::size_t const i) -> auto &
Access the i'th element.
Definition: property.h:204
auto operator[](std::size_t const i) const -> const auto &
Const access to the i'th element.
Definition: property.h:210
auto clean(std::set< Handle > const &invalid_handles) -> void override
Definition: property.h:223
Definition: property.h:16
virtual auto clean(std::set< Handle > const &) -> void=0
virtual auto clone() const -> std::unique_ptr< this_type >=0
auto operator=(const vector_property &) -> vector_property &=default
vector_property()=default
virtual void clear()=0
Free unused memory.
auto cast_to_typed() -> decltype(auto)
Definition: property.h:54
auto operator=(vector_property &&) noexcept -> vector_property &=default
auto holds_type() const
Definition: property.h:47
virtual auto type() const -> const std::type_info &=0
for identifying type.
virtual void push_back()=0
pushes element at back
virtual void erase(std::size_t)=0
Resize storage to hold n elements.
virtual void reserve(std::size_t n)=0
Reserve memory for n elements.
vector_property(vector_property &&other) noexcept=default
auto cast_to_typed() const -> decltype(auto)
Definition: property.h:59
vector_property(const vector_property &other)=default
virtual void resize(std::size_t n)=0
Resize storage to hold n elements.