From f4ead89a8bbb240d679164f33cb7bd477e447a85 Mon Sep 17 00:00:00 2001 From: Jeremiah Morgan Date: Wed, 8 Jan 2025 23:55:27 +0000 Subject: [PATCH] address new comments --- libopenage/curve/array.h | 62 +++++++++++++++++++++------- libopenage/curve/tests/container.cpp | 2 +- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/libopenage/curve/array.h b/libopenage/curve/array.h index 318859c501..7d8cf3b8f0 100644 --- a/libopenage/curve/array.h +++ b/libopenage/curve/array.h @@ -4,22 +4,31 @@ #include +#include "curve/iterator.h" #include "curve/keyframe_container.h" #include "event/evententity.h" -// remember to update docs +// ASDF: remember to update docs namespace openage { namespace curve { template class Array : event::EventEntity { public: + /** + * The underlaying container type. + */ + using container_t = std::array, Size>; + Array(const std::shared_ptr &loop, size_t id, + const T &default_val = T(), const std::string &idstr = "", const EventEntity::single_change_notifier ¬ifier = nullptr) : - EventEntity(loop, notifier), _id{id}, _idstr{idstr}, loop{loop} {} + EventEntity(loop, notifier), + _id{id}, _idstr{idstr}, loop{loop}, container{KeyframeContainer(default_val)} { + } Array(const Array &) = delete; Array &operator=(const Array &) = delete; @@ -108,53 +117,74 @@ class Array : event::EventEntity { } - // get a copy to the KeyframeContainer at index - KeyframeContainer operator[](size_t index) const { - return this->container.at(index); - } - - // Array::Iterator is used to iterate over KeyframeContainers contained in a curve at a given time. + /** + * Array::Iterator is used to iterate over KeyframeContainers contained in a curve at a given time. + */ class Iterator { public: Iterator(Array *curve, const time::time_t &time = time::TIME_MAX, size_t offset = 0) : curve(curve), time(time), offset(offset) {}; - // returns a copy of the keyframe at the current offset and time + /** + * returns a copy of the keyframe at the current offset and time + */ const T operator*() { return this->curve->frame(this->time, this->offset).second; } - // increments the Iterator to point at the next KeyframeContainer + /** + * increments the Iterator to point at the next KeyframeContainer + */ void operator++() { this->offset++; } - // Compare two Iterators by their offset + /** + * Compare two Iterators by their offset + */ bool operator!=(const Array::Iterator &rhs) const { return this->offset != rhs.offset; } private: - // used to index the Curve::Array pointed to by this iterator + /** + * used to index the Curve::Array pointed to by this iterator + */ size_t offset; - // curve::Array that this iterator is iterating over + /** + * the curve object that this iterator, iterates over + */ Array *curve; - // time at which this iterator is iterating over + /** + * time at which this iterator is iterating over + */ time::time_t time; }; - // iterator pointing to a keyframe of the first KeyframeContainer in the curve at a given time + /** + * iterator pointing to a keyframe of the first KeyframeContainer in the curve at a given time + */ Iterator begin(const time::time_t &time = time::TIME_MIN); - // iterator pointing after the last KeyframeContainer in the curve at a given time + /** + * iterator pointing after the last KeyframeContainer in the curve at a given time + */ Iterator end(const time::time_t &time = time::TIME_MIN); private: + /** + * get a copy to the KeyframeContainer at index + */ + KeyframeContainer operator[](size_t index) const { + return this->container.at(index); + } + + std::array, Size> container; /** diff --git a/libopenage/curve/tests/container.cpp b/libopenage/curve/tests/container.cpp index 8a71e47614..8aed3c8d05 100644 --- a/libopenage/curve/tests/container.cpp +++ b/libopenage/curve/tests/container.cpp @@ -247,6 +247,7 @@ void test_array() { auto f = std::make_shared(); Array a(f, 0); + const std::array &default_val = std::array(); a.set_insert(1, 0, 0); a.set_insert(1, 1, 1); a.set_insert(1, 2, 2); @@ -308,7 +309,6 @@ void test_array() { TESTEQUALS(next_frame.second, 40); TESTEQUALS(next_frame.first, 5); - // Test begin and end auto it = a.begin(1); TESTEQUALS(*it, 4);