From d6bf5b910ce0425d9cf9d9f1a991ebef1c937abc Mon Sep 17 00:00:00 2001 From: heinezen Date: Wed, 25 Dec 2024 14:56:03 +0100 Subject: [PATCH] curve: Make element wrapper member access private. Prevents unexpected manipulation. --- libopenage/curve/element_wrapper.h | 39 ++++++++++++++++++------ libopenage/curve/map_filter_iterator.h | 2 +- libopenage/curve/queue.h | 4 +-- libopenage/curve/queue_filter_iterator.h | 2 +- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/libopenage/curve/element_wrapper.h b/libopenage/curve/element_wrapper.h index 498ee550cc..764b61d5cd 100644 --- a/libopenage/curve/element_wrapper.h +++ b/libopenage/curve/element_wrapper.h @@ -12,14 +12,8 @@ namespace openage::curve { * Stores the lifetime of the element (insertion time and erasure time) alongside the value. */ template -struct element_wrapper { - /// Time of insertion of the element into the container - time::time_t _alive; - /// Time of erasure of the element from the container - time::time_t _dead; - /// Element value - T value; - +class element_wrapper { +public: /** * Create a new element with insertion time \p time and a given value. * @@ -31,7 +25,7 @@ struct element_wrapper { element_wrapper(const time::time_t &time, const T &value) : _alive{time}, _dead{time::TIME_MAX}, - value{value} {} + _value{value} {} /** * Create a new element with insertion time \p alive and erasure time \p dead and a given value. @@ -43,7 +37,7 @@ struct element_wrapper { element_wrapper(const time::time_t &alive, const time::time_t &dead, const T &value) : _alive{alive}, _dead{dead}, - value{value} {} + _value{value} {} /** * Get the insertion time of this element. @@ -71,6 +65,31 @@ struct element_wrapper { void set_dead(const time::time_t &time) { _dead = time; } + + /** + * Get the value of this element. + * + * @return Value of the element. + */ + const T &value() const { + return _value; + } + +private: + /** + * Time of insertion of the element into the container + */ + time::time_t _alive; + + /** + * Time of erasure of the element from the container + */ + time::time_t _dead; + + /** + * Element value + */ + T _value; }; } // namespace openage::curve diff --git a/libopenage/curve/map_filter_iterator.h b/libopenage/curve/map_filter_iterator.h index e60f762c26..3aec2a899e 100644 --- a/libopenage/curve/map_filter_iterator.h +++ b/libopenage/curve/map_filter_iterator.h @@ -44,7 +44,7 @@ class MapFilterIterator : public CurveIterator { * Nicer way of accessing it beside operator *. */ val_t const &value() const override { - return this->get_base()->second.value; + return this->get_base()->second.value(); } /** diff --git a/libopenage/curve/queue.h b/libopenage/curve/queue.h index 210670ee7b..9314dd3a0e 100644 --- a/libopenage/curve/queue.h +++ b/libopenage/curve/queue.h @@ -277,7 +277,7 @@ const T &Queue::front(const time::time_t &time) const { << ", container size: " << this->container.size() << ")"); - return this->container.at(at).value; + return this->container.at(at).value(); } @@ -303,7 +303,7 @@ const T &Queue::pop_front(const time::time_t &time) { this->changes(time); - return this->container.at(at).value; + return this->container.at(at).value(); } diff --git a/libopenage/curve/queue_filter_iterator.h b/libopenage/curve/queue_filter_iterator.h index 248abb44ad..cf6bc5aa2c 100644 --- a/libopenage/curve/queue_filter_iterator.h +++ b/libopenage/curve/queue_filter_iterator.h @@ -40,7 +40,7 @@ class QueueFilterIterator : public CurveIteratorget_base(); - return a.value; + return a.value(); } };