Skip to content

Commit

Permalink
curve: Make element wrapper member access private.
Browse files Browse the repository at this point in the history
Prevents unexpected manipulation.
  • Loading branch information
heinezen committed Dec 25, 2024
1 parent 4159602 commit d6bf5b9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
39 changes: 29 additions & 10 deletions libopenage/curve/element_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@ namespace openage::curve {
* Stores the lifetime of the element (insertion time and erasure time) alongside the value.
*/
template <typename T>
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.
*
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion libopenage/curve/map_filter_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MapFilterIterator : public CurveIterator<val_t, container_t> {
* 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();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions libopenage/curve/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ const T &Queue<T>::front(const time::time_t &time) const {
<< ", container size: " << this->container.size()
<< ")");

return this->container.at(at).value;
return this->container.at(at).value();
}


Expand All @@ -303,7 +303,7 @@ const T &Queue<T>::pop_front(const time::time_t &time) {

this->changes(time);

return this->container.at(at).value;
return this->container.at(at).value();
}


Expand Down
2 changes: 1 addition & 1 deletion libopenage/curve/queue_filter_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class QueueFilterIterator : public CurveIterator<val_t, container_t, typename co

const val_t &value() const override {
const auto &a = *this->get_base();
return a.value;
return a.value();
}
};

Expand Down

0 comments on commit d6bf5b9

Please sign in to comment.