diff --git a/library/phx/core/engine.hpp b/library/phx/core/engine.hpp index fabc9c0bd93fe3fa98a91c9c1dd28950dc96b83c..3edf391198d788e2bed4a9bb06538d28361fc63d 100644 --- a/library/phx/core/engine.hpp +++ b/library/phx/core/engine.hpp @@ -46,7 +46,7 @@ SUPPRESS_WARNINGS_END #include "phx/export.hpp" #include "phx/scripting/behavior.hpp" #include "phx/utility/aspects/loggable.hpp" -#include "phx/utility/orderable_list.hpp" +#include "phx/utility/orderable_vector.hpp" namespace phx { @@ -137,7 +137,7 @@ class PHOENIX_EXPORT Engine final : public Loggable { void UpdateSystems(); - OrderableList<System> systems_; + OrderableVector<System> systems_; bool is_running_ = false; std::shared_ptr<Scene> scene_; diff --git a/library/phx/utility/orderable_list.hpp b/library/phx/utility/orderable_vector.hpp similarity index 78% rename from library/phx/utility/orderable_list.hpp rename to library/phx/utility/orderable_vector.hpp index 20965c02a5859aee301e79ab224df355f399ba86..691bd22bf3a7656d306f8de556629c54a32d684a 100644 --- a/library/phx/utility/orderable_list.hpp +++ b/library/phx/utility/orderable_vector.hpp @@ -20,8 +20,8 @@ // limitations under the License. //------------------------------------------------------------------------------ -#ifndef LIBRARY_PHX_UTILITY_ORDERABLE_LIST_HPP_ -#define LIBRARY_PHX_UTILITY_ORDERABLE_LIST_HPP_ +#ifndef LIBRARY_PHX_UTILITY_ORDERABLE_VECTOR_HPP_ +#define LIBRARY_PHX_UTILITY_ORDERABLE_VECTOR_HPP_ #include <memory> #include <utility> @@ -33,20 +33,20 @@ namespace phx { template <typename ElementType> -class PHOENIX_EXPORT OrderableList { +class PHOENIX_EXPORT OrderableVector { public: typedef typename std::vector<std::unique_ptr<ElementType>>::iterator - orderable_list_iterator; + iterator; typedef typename std::vector<std::unique_ptr<ElementType>>::const_iterator - orderable_list_const_iterator; + const_iterator; std::size_t size() const { return data_.size(); } - orderable_list_iterator begin() { return data_.begin(); } - orderable_list_iterator end() { return data_.end(); } - orderable_list_const_iterator begin() const { return data_.begin(); } - orderable_list_const_iterator end() const { return data_.end(); } - orderable_list_iterator erase(orderable_list_const_iterator first, - orderable_list_const_iterator last) { + iterator begin() { return data_.begin(); } + iterator end() { return data_.end(); } + const_iterator begin() const { return data_.begin(); } + const_iterator end() const { return data_.end(); } + iterator erase(const_iterator first, + const_iterator last) { return data_.erase(first, last); } @@ -65,7 +65,7 @@ class PHOENIX_EXPORT OrderableList { } private: - orderable_list_iterator FindElement(ElementType* element); + iterator FindElement(ElementType* element); void MoveRelativeTo(ElementType* element, ElementType* relative_to, int distance); @@ -73,7 +73,7 @@ class PHOENIX_EXPORT OrderableList { }; template <typename ElementType> -void phx::OrderableList<ElementType>::MoveToFront(ElementType* element) { +void phx::OrderableVector<ElementType>::MoveToFront(ElementType* element) { auto it = FindElement(element); if (it == data_.end()) { phx::error( @@ -86,7 +86,7 @@ void phx::OrderableList<ElementType>::MoveToFront(ElementType* element) { } template <typename ElementType> -void phx::OrderableList<ElementType>::MoveToBack(ElementType* element) { +void phx::OrderableVector<ElementType>::MoveToBack(ElementType* element) { auto it = FindElement(element); if (it == data_.end()) { phx::error( @@ -101,7 +101,7 @@ void phx::OrderableList<ElementType>::MoveToBack(ElementType* element) { template <typename ElementType> typename std::vector<std::unique_ptr<ElementType>>::iterator -phx::OrderableList<ElementType>::FindElement(ElementType* element) { +phx::OrderableVector<ElementType>::FindElement(ElementType* element) { auto find_func = [element](const std::unique_ptr<ElementType>& elem) { return elem.get() == element; }; @@ -109,7 +109,7 @@ phx::OrderableList<ElementType>::FindElement(ElementType* element) { } template <typename ElementType> -void phx::OrderableList<ElementType>::MoveRelativeTo(ElementType* element, +void phx::OrderableVector<ElementType>::MoveRelativeTo(ElementType* element, ElementType* relative_to, int distance) { if (element == relative_to) return; @@ -132,4 +132,4 @@ void phx::OrderableList<ElementType>::MoveRelativeTo(ElementType* element, } // namespace phx -#endif // LIBRARY_PHX_UTILITY_ORDERABLE_LIST_HPP_ +#endif // LIBRARY_PHX_UTILITY_ORDERABLE_VECTOR_HPP_ diff --git a/tests/src/test_orderable_list.cpp b/tests/src/test_orderable_vector.cpp similarity index 57% rename from tests/src/test_orderable_list.cpp rename to tests/src/test_orderable_vector.cpp index ee67a84a3dc235e3c8d5efaefc917466faf4225a..fb6032c759c1eae5f0449a985e4d1aa8a6c879bf 100644 --- a/tests/src/test_orderable_list.cpp +++ b/tests/src/test_orderable_vector.cpp @@ -26,33 +26,34 @@ #include "catch/catch.hpp" #include "trompeloeil.hpp" -#include "phx/utility/orderable_list.hpp" +#include "phx/utility/orderable_vector.hpp" using trompeloeil::_; using trompeloeil::ne; extern template struct trompeloeil::reporter<trompeloeil::specialized>; -SCENARIO("An OderableList can be used as a list", "[phx][phx::OrderableList]") { - GIVEN("An empty OrderableList") { - phx::OrderableList<int> orderable_list; +SCENARIO("An OrderableVector can be used as a vector", + "[phx][phx::OrderableVector]") { + GIVEN("An empty OrderableVector") { + phx::OrderableVector<int> orderable_vector; THEN("It does not contain anything") { - REQUIRE(orderable_list.size() == 0); + REQUIRE(orderable_vector.size() == 0); WHEN("we add one element") { - orderable_list.PushBack(std::make_unique<int>(1)); + orderable_vector.PushBack(std::make_unique<int>(1)); THEN("the number of elements is correct") { - REQUIRE(orderable_list.size() == 1); + REQUIRE(orderable_vector.size() == 1); WHEN("we add one more") { - orderable_list.PushBack(std::make_unique<int>(2)); + orderable_vector.PushBack(std::make_unique<int>(2)); THEN("the number of elements is correct") { - REQUIRE(orderable_list.size() == 2); + REQUIRE(orderable_vector.size() == 2); WHEN("We remove it again") { - orderable_list.erase(orderable_list.begin() + 1, - orderable_list.end()); + orderable_vector.erase(orderable_vector.begin() + 1, + orderable_vector.end()); THEN("it has 1 element again") { - REQUIRE(orderable_list.size() == 1); + REQUIRE(orderable_vector.size() == 1); } } } @@ -63,17 +64,18 @@ SCENARIO("An OderableList can be used as a list", "[phx][phx::OrderableList]") { } } -SCENARIO("An OderableList can looped through", "[phx][phx::OrderableList]") { - GIVEN("An OrderableList with 3 elements") { - phx::OrderableList<int> orderable_list; - orderable_list.PushBack(std::make_unique<int>(1)); - orderable_list.PushBack(std::make_unique<int>(2)); - orderable_list.PushBack(std::make_unique<int>(3)); +SCENARIO("An OrderableVector can looped through", + "[phx][phx::OrderableVector]") { + GIVEN("An OrderableVector with 3 elements") { + phx::OrderableVector<int> orderable_vector; + orderable_vector.PushBack(std::make_unique<int>(1)); + orderable_vector.PushBack(std::make_unique<int>(2)); + orderable_vector.PushBack(std::make_unique<int>(3)); THEN("it can be iterated over the elements using a for each loop") { int elements = 0; int correct_order = true; - for (auto& it : orderable_list) { + for (auto& it : orderable_vector) { elements++; if (*it != elements) correct_order = false; } @@ -91,9 +93,9 @@ SCENARIO("An OderableList can looped through", "[phx][phx::OrderableList]") { namespace { std::string GetOrderString( - const phx::OrderableList<std::string>& orderable_list) { + const phx::OrderableVector<std::string>& orderable_vector) { std::string order_string; - for (auto& it : orderable_list) { + for (auto& it : orderable_vector) { order_string += *it; } return order_string; @@ -106,43 +108,43 @@ std::string GetOrderString( #endif SCENARIO("The order in which elements are ordered can be changed", - "[phx][phx::OrderableList]") { - GIVEN("An OrderableList set up with 4 number of elements") { - phx::OrderableList<std::string> orderable_list; - auto elem1 = orderable_list.PushBack(std::make_unique<std::string>("A")); - auto elem2 = orderable_list.PushBack(std::make_unique<std::string>("B")); - auto elem3 = orderable_list.PushBack(std::make_unique<std::string>("C")); - auto elem4 = orderable_list.PushBack(std::make_unique<std::string>("D")); + "[phx][phx::OrderableVector]") { + GIVEN("An OrderableVector set up with 4 number of elements") { + phx::OrderableVector<std::string> orderable_vector; + auto elem1 = orderable_vector.PushBack(std::make_unique<std::string>("A")); + auto elem2 = orderable_vector.PushBack(std::make_unique<std::string>("B")); + auto elem3 = orderable_vector.PushBack(std::make_unique<std::string>("C")); + auto elem4 = orderable_vector.PushBack(std::make_unique<std::string>("D")); THEN("The elements are in the same order in which they were added") { - REQUIRE(::GetOrderString(orderable_list) == "ABCD"); + REQUIRE(::GetOrderString(orderable_vector) == "ABCD"); } WHEN("We change the second element to be first") { - orderable_list.MoveToFront(elem2); + orderable_vector.MoveToFront(elem2); THEN("The elements are in order 2-1-3-4") { - REQUIRE(::GetOrderString(orderable_list) == "BACD"); + REQUIRE(::GetOrderString(orderable_vector) == "BACD"); } } WHEN("We change the second element to update last") { - orderable_list.MoveToBack(elem2); + orderable_vector.MoveToBack(elem2); THEN("The elements are in order 1-3-4-2") { - REQUIRE(::GetOrderString(orderable_list) == "ACDB"); + REQUIRE(::GetOrderString(orderable_vector) == "ACDB"); } } WHEN("We change order to have element 2 after element 3") { - orderable_list.MoveAfter(elem2, elem3); + orderable_vector.MoveAfter(elem2, elem3); THEN("The elements are in order 1-3-2-4") { - REQUIRE(::GetOrderString(orderable_list) == "ACBD"); + REQUIRE(::GetOrderString(orderable_vector) == "ACBD"); } } WHEN("We change order to have element 4 before element 1") { - orderable_list.MoveBefore(elem4, elem1); + orderable_vector.MoveBefore(elem4, elem1); THEN("The elements are in order 4-1-2-3") { - REQUIRE(::GetOrderString(orderable_list) == "DABC"); + REQUIRE(::GetOrderString(orderable_vector) == "DABC"); } } }