GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
TestsContainer.h
1 /*
2  * GDevelop Core
3  * Copyright 2008-present Florian Rival ([email protected]). All rights
4  * reserved. This project is released under the MIT License.
5  */
6 #pragma once
7 
8 #include <vector>
9 
10 #include "GDCore/Project/Test.h"
11 #include "GDCore/String.h"
12 #include "GDCore/Tools/SerializableWithNameList.h"
13 
14 namespace gd {
15 class SerializerElement;
16 }
17 
18 namespace gd {
19 
27 class GD_CORE_API TestsContainer : private SerializableWithNameList<gd::Test> {
28  public:
29  TestsContainer() {}
30 
31  TestsContainer(const TestsContainer& other) { Init(other); }
32 
33  TestsContainer& operator=(const TestsContainer& other) {
34  if (this != &other) {
35  Init(other);
36  }
37  return *this;
38  }
39 
43 
46  bool HasTestNamed(const gd::String& name) const { return Has(name); }
47 
54  gd::Test& GetTest(const gd::String& name) { return Get(name); }
55 
62  const gd::Test& GetTest(const gd::String& name) const { return Get(name); }
63 
70  gd::Test& GetTest(std::size_t index) { return Get(index); }
71 
78  const gd::Test& GetTest(std::size_t index) const { return Get(index); }
79 
83  std::size_t GetTestsCount() const { return GetCount(); }
84 
85  gd::Test& InsertNewTest(const gd::String& name, std::size_t position) {
86  return InsertNew(name, position);
87  }
88  gd::Test& InsertTest(const gd::Test& test, std::size_t position) {
89  return Insert(test, position);
90  }
91  void RemoveTest(const gd::String& name) { return Remove(name); }
92  void ClearTests() { return Clear(); }
93  void MoveTest(std::size_t oldIndex, std::size_t newIndex) {
94  return Move(oldIndex, newIndex);
95  };
96  std::size_t GetTestPosition(const gd::Test& test) {
97  return GetPosition(test);
98  };
99 
103  const std::vector<std::unique_ptr<gd::Test>>& GetInternalVector() const {
104  return elements;
105  };
106 
110  std::vector<std::unique_ptr<gd::Test>>& GetInternalVector() {
111  return elements;
112  };
114 
118 
121  void SerializeTestsTo(SerializerElement& element) const {
122  return SerializeElementsTo("test", element);
123  };
124 
129  return UnserializeElementsFrom("test", element);
130  };
132 
133  protected:
138  void Init(const gd::TestsContainer& other) {
140  };
141 };
142 
143 } // namespace gd
A class template that store a list of elements that can be accessed by their names and serialized.
Definition: SerializableWithNameList.h:33
void Init(const SerializableWithNameList< T > &other)
Definition: SerializableWithNameList.inl:190
A generic container that can represent a value ( containing a string, double, bool or int),...
Definition: SerializerElement.h:37
String represents an UTF8 encoded string.
Definition: String.h:33
A test attached to a project or an events based extension.
Definition: Test.h:28
A container of tests (gd::Test), used by gd::Project and gd::EventsFunctionsExtension.
Definition: TestsContainer.h:27
std::vector< std::unique_ptr< gd::Test > > & GetInternalVector()
Provide a raw access to the vector containing the tests.
Definition: TestsContainer.h:110
gd::Test & GetTest(std::size_t index)
Get the test at the specified index in the list.
Definition: TestsContainer.h:70
const gd::Test & GetTest(const gd::String &name) const
Get the test with the specified name.
Definition: TestsContainer.h:62
void Init(const gd::TestsContainer &other)
Definition: TestsContainer.h:138
std::size_t GetTestsCount() const
Return the number of tests.
Definition: TestsContainer.h:83
void UnserializeTestsFrom(const SerializerElement &element)
Unserialize the tests.
Definition: TestsContainer.h:128
bool HasTestNamed(const gd::String &name) const
Check if a test with the specified name exists.
Definition: TestsContainer.h:46
gd::Test & GetTest(const gd::String &name)
Get the test with the specified name.
Definition: TestsContainer.h:54
const std::vector< std::unique_ptr< gd::Test > > & GetInternalVector() const
Provide a raw access to the vector containing the tests.
Definition: TestsContainer.h:103
void SerializeTestsTo(SerializerElement &element) const
Serialize the tests.
Definition: TestsContainer.h:121
const gd::Test & GetTest(std::size_t index) const
Get the test at the specified index in the list.
Definition: TestsContainer.h:78
Definition: CommonTools.h:24