Skip to content
Snippets Groups Projects
Commit 000b044d authored by Jonathan Wendt's avatar Jonathan Wendt
Browse files

Merge branch 'feature/#405_rename_orderable_list' into 'master'

#405_rename_orderable_list

See merge request VR-Group/Project_Phoenix!157
parents eb345e95 78d92788
No related branches found
No related tags found
1 merge request!157#405_rename_orderable_list
...@@ -46,7 +46,7 @@ SUPPRESS_WARNINGS_END ...@@ -46,7 +46,7 @@ SUPPRESS_WARNINGS_END
#include "phx/export.hpp" #include "phx/export.hpp"
#include "phx/scripting/behavior.hpp" #include "phx/scripting/behavior.hpp"
#include "phx/utility/aspects/loggable.hpp" #include "phx/utility/aspects/loggable.hpp"
#include "phx/utility/orderable_list.hpp" #include "phx/utility/orderable_vector.hpp"
namespace phx { namespace phx {
...@@ -137,7 +137,7 @@ class PHOENIX_EXPORT Engine final : public Loggable { ...@@ -137,7 +137,7 @@ class PHOENIX_EXPORT Engine final : public Loggable {
void UpdateSystems(); void UpdateSystems();
OrderableList<System> systems_; OrderableVector<System> systems_;
bool is_running_ = false; bool is_running_ = false;
std::shared_ptr<Scene> scene_; std::shared_ptr<Scene> scene_;
......
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
// limitations under the License. // limitations under the License.
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#ifndef LIBRARY_PHX_UTILITY_ORDERABLE_LIST_HPP_ #ifndef LIBRARY_PHX_UTILITY_ORDERABLE_VECTOR_HPP_
#define LIBRARY_PHX_UTILITY_ORDERABLE_LIST_HPP_ #define LIBRARY_PHX_UTILITY_ORDERABLE_VECTOR_HPP_
#include <memory> #include <memory>
#include <utility> #include <utility>
...@@ -33,20 +33,20 @@ ...@@ -33,20 +33,20 @@
namespace phx { namespace phx {
template <typename ElementType> template <typename ElementType>
class PHOENIX_EXPORT OrderableList { class PHOENIX_EXPORT OrderableVector {
public: public:
typedef typename std::vector<std::unique_ptr<ElementType>>::iterator typedef typename std::vector<std::unique_ptr<ElementType>>::iterator
orderable_list_iterator; iterator;
typedef typename std::vector<std::unique_ptr<ElementType>>::const_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(); } std::size_t size() const { return data_.size(); }
orderable_list_iterator begin() { return data_.begin(); } iterator begin() { return data_.begin(); }
orderable_list_iterator end() { return data_.end(); } iterator end() { return data_.end(); }
orderable_list_const_iterator begin() const { return data_.begin(); } const_iterator begin() const { return data_.begin(); }
orderable_list_const_iterator end() const { return data_.end(); } const_iterator end() const { return data_.end(); }
orderable_list_iterator erase(orderable_list_const_iterator first, iterator erase(const_iterator first,
orderable_list_const_iterator last) { const_iterator last) {
return data_.erase(first, last); return data_.erase(first, last);
} }
...@@ -65,7 +65,7 @@ class PHOENIX_EXPORT OrderableList { ...@@ -65,7 +65,7 @@ class PHOENIX_EXPORT OrderableList {
} }
private: private:
orderable_list_iterator FindElement(ElementType* element); iterator FindElement(ElementType* element);
void MoveRelativeTo(ElementType* element, ElementType* relative_to, void MoveRelativeTo(ElementType* element, ElementType* relative_to,
int distance); int distance);
...@@ -73,7 +73,7 @@ class PHOENIX_EXPORT OrderableList { ...@@ -73,7 +73,7 @@ class PHOENIX_EXPORT OrderableList {
}; };
template <typename ElementType> template <typename ElementType>
void phx::OrderableList<ElementType>::MoveToFront(ElementType* element) { void phx::OrderableVector<ElementType>::MoveToFront(ElementType* element) {
auto it = FindElement(element); auto it = FindElement(element);
if (it == data_.end()) { if (it == data_.end()) {
phx::error( phx::error(
...@@ -86,7 +86,7 @@ void phx::OrderableList<ElementType>::MoveToFront(ElementType* element) { ...@@ -86,7 +86,7 @@ void phx::OrderableList<ElementType>::MoveToFront(ElementType* element) {
} }
template <typename ElementType> template <typename ElementType>
void phx::OrderableList<ElementType>::MoveToBack(ElementType* element) { void phx::OrderableVector<ElementType>::MoveToBack(ElementType* element) {
auto it = FindElement(element); auto it = FindElement(element);
if (it == data_.end()) { if (it == data_.end()) {
phx::error( phx::error(
...@@ -101,7 +101,7 @@ void phx::OrderableList<ElementType>::MoveToBack(ElementType* element) { ...@@ -101,7 +101,7 @@ void phx::OrderableList<ElementType>::MoveToBack(ElementType* element) {
template <typename ElementType> template <typename ElementType>
typename std::vector<std::unique_ptr<ElementType>>::iterator 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) { auto find_func = [element](const std::unique_ptr<ElementType>& elem) {
return elem.get() == element; return elem.get() == element;
}; };
...@@ -109,7 +109,7 @@ phx::OrderableList<ElementType>::FindElement(ElementType* element) { ...@@ -109,7 +109,7 @@ phx::OrderableList<ElementType>::FindElement(ElementType* element) {
} }
template <typename ElementType> template <typename ElementType>
void phx::OrderableList<ElementType>::MoveRelativeTo(ElementType* element, void phx::OrderableVector<ElementType>::MoveRelativeTo(ElementType* element,
ElementType* relative_to, ElementType* relative_to,
int distance) { int distance) {
if (element == relative_to) return; if (element == relative_to) return;
...@@ -132,4 +132,4 @@ void phx::OrderableList<ElementType>::MoveRelativeTo(ElementType* element, ...@@ -132,4 +132,4 @@ void phx::OrderableList<ElementType>::MoveRelativeTo(ElementType* element,
} // namespace phx } // namespace phx
#endif // LIBRARY_PHX_UTILITY_ORDERABLE_LIST_HPP_ #endif // LIBRARY_PHX_UTILITY_ORDERABLE_VECTOR_HPP_
...@@ -26,33 +26,34 @@ ...@@ -26,33 +26,34 @@
#include "catch/catch.hpp" #include "catch/catch.hpp"
#include "trompeloeil.hpp" #include "trompeloeil.hpp"
#include "phx/utility/orderable_list.hpp" #include "phx/utility/orderable_vector.hpp"
using trompeloeil::_; using trompeloeil::_;
using trompeloeil::ne; using trompeloeil::ne;
extern template struct trompeloeil::reporter<trompeloeil::specialized>; extern template struct trompeloeil::reporter<trompeloeil::specialized>;
SCENARIO("An OderableList can be used as a list", "[phx][phx::OrderableList]") { SCENARIO("An OrderableVector can be used as a vector",
GIVEN("An empty OrderableList") { "[phx][phx::OrderableVector]") {
phx::OrderableList<int> orderable_list; GIVEN("An empty OrderableVector") {
phx::OrderableVector<int> orderable_vector;
THEN("It does not contain anything") { THEN("It does not contain anything") {
REQUIRE(orderable_list.size() == 0); REQUIRE(orderable_vector.size() == 0);
WHEN("we add one element") { 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") { THEN("the number of elements is correct") {
REQUIRE(orderable_list.size() == 1); REQUIRE(orderable_vector.size() == 1);
WHEN("we add one more") { 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") { THEN("the number of elements is correct") {
REQUIRE(orderable_list.size() == 2); REQUIRE(orderable_vector.size() == 2);
WHEN("We remove it again") { WHEN("We remove it again") {
orderable_list.erase(orderable_list.begin() + 1, orderable_vector.erase(orderable_vector.begin() + 1,
orderable_list.end()); orderable_vector.end());
THEN("it has 1 element again") { 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]") { ...@@ -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]") { SCENARIO("An OrderableVector can looped through",
GIVEN("An OrderableList with 3 elements") { "[phx][phx::OrderableVector]") {
phx::OrderableList<int> orderable_list; GIVEN("An OrderableVector with 3 elements") {
orderable_list.PushBack(std::make_unique<int>(1)); phx::OrderableVector<int> orderable_vector;
orderable_list.PushBack(std::make_unique<int>(2)); orderable_vector.PushBack(std::make_unique<int>(1));
orderable_list.PushBack(std::make_unique<int>(3)); 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") { THEN("it can be iterated over the elements using a for each loop") {
int elements = 0; int elements = 0;
int correct_order = true; int correct_order = true;
for (auto& it : orderable_list) { for (auto& it : orderable_vector) {
elements++; elements++;
if (*it != elements) correct_order = false; if (*it != elements) correct_order = false;
} }
...@@ -91,9 +93,9 @@ SCENARIO("An OderableList can looped through", "[phx][phx::OrderableList]") { ...@@ -91,9 +93,9 @@ SCENARIO("An OderableList can looped through", "[phx][phx::OrderableList]") {
namespace { namespace {
std::string GetOrderString( std::string GetOrderString(
const phx::OrderableList<std::string>& orderable_list) { const phx::OrderableVector<std::string>& orderable_vector) {
std::string order_string; std::string order_string;
for (auto& it : orderable_list) { for (auto& it : orderable_vector) {
order_string += *it; order_string += *it;
} }
return order_string; return order_string;
...@@ -106,43 +108,43 @@ std::string GetOrderString( ...@@ -106,43 +108,43 @@ std::string GetOrderString(
#endif #endif
SCENARIO("The order in which elements are ordered can be changed", SCENARIO("The order in which elements are ordered can be changed",
"[phx][phx::OrderableList]") { "[phx][phx::OrderableVector]") {
GIVEN("An OrderableList set up with 4 number of elements") { GIVEN("An OrderableVector set up with 4 number of elements") {
phx::OrderableList<std::string> orderable_list; phx::OrderableVector<std::string> orderable_vector;
auto elem1 = orderable_list.PushBack(std::make_unique<std::string>("A")); auto elem1 = orderable_vector.PushBack(std::make_unique<std::string>("A"));
auto elem2 = orderable_list.PushBack(std::make_unique<std::string>("B")); auto elem2 = orderable_vector.PushBack(std::make_unique<std::string>("B"));
auto elem3 = orderable_list.PushBack(std::make_unique<std::string>("C")); auto elem3 = orderable_vector.PushBack(std::make_unique<std::string>("C"));
auto elem4 = orderable_list.PushBack(std::make_unique<std::string>("D")); auto elem4 = orderable_vector.PushBack(std::make_unique<std::string>("D"));
THEN("The elements are in the same order in which they were added") { 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") { 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") { 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") { 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") { 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") { 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") { 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") { 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") { THEN("The elements are in order 4-1-2-3") {
REQUIRE(::GetOrderString(orderable_list) == "DABC"); REQUIRE(::GetOrderString(orderable_vector) == "DABC");
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment