GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
ObjectGroupsContainer.h
1 /*
2  * GDevelop Core
3  * Copyright 2008-2016 Florian Rival ([email protected]). All rights
4  * reserved. This project is released under the MIT License.
5  */
6 
7 #ifndef GDCORE_OBJECTGROUPSCONTAINER_H
8 #define GDCORE_OBJECTGROUPSCONTAINER_H
9 #include <algorithm>
10 #include <memory>
11 #include <vector>
12 
13 #include "GDCore/Project/MemoryTrackedRegistry.h"
14 #include "GDCore/Project/ObjectGroup.h"
15 #include "GDCore/String.h"
16 namespace gd {
17 class SerializerElement;
18 }
19 
20 namespace gd {
21 
30 class GD_CORE_API ObjectGroupsContainer {
31  public:
34  virtual ~ObjectGroupsContainer(){};
35  ObjectGroupsContainer& operator=(const ObjectGroupsContainer& rhs);
36 
40  bool Has(const gd::String& name) const;
41 
45  ObjectGroup& Get(const gd::String& name);
46 
50  const ObjectGroup& Get(const gd::String& name) const;
51 
57  ObjectGroup& Get(std::size_t index);
58 
64  const ObjectGroup& Get(std::size_t index) const;
65 
73  ObjectGroup& Insert(const ObjectGroup& objectGroup,
74  std::size_t position = -1);
75 
79  std::size_t Count() const { return objectGroups.size(); };
80 
84  bool IsEmpty() const { return objectGroups.empty(); };
85 
89  std::size_t GetPosition(const gd::String& name) const;
90 
98  ObjectGroup& InsertNew(const gd::String& name, std::size_t position = -1);
99 
103  void Remove(const gd::String& name);
104 
109  bool Rename(const gd::String& oldName, const gd::String& newName);
110 
114  void Move(std::size_t oldIndex, std::size_t newIndex);
115 
119  inline void Clear() { objectGroups.clear(); }
120 
124  void ForEachNameMatchingSearch(const gd::String& search, std::function<void(const gd::String& name)> fn) const;
126 
131 
134  void SerializeTo(SerializerElement& element) const;
135 
139  void UnserializeFrom(const SerializerElement& element);
141 
146 
151  size_t size() const { return Count(); }
152 
157  bool empty() const { return IsEmpty(); }
158 
163  ObjectGroup& operator[](size_t index) { return Get(index); };
164 
169  const ObjectGroup& operator[](size_t index) const { return Get(index); };
170 
175  ObjectGroup& at(size_t index) { return Get(index); };
176 
181  const ObjectGroup& at(size_t index) const { return Get(index); };
183 
188  void Init(const gd::ObjectGroupsContainer& other);
189 
190  private:
191  std::vector<std::unique_ptr<gd::ObjectGroup>> objectGroups;
192  static ObjectGroup badGroup;
193  gd::MemoryTracked _memoryTracked{this, "ObjectGroupsContainer"};
194 };
195 
196 } // namespace gd
197 
198 #endif // GDCORE_OBJECTGROUPSCONTAINER_H
A non-copyable, non-movable member object that registers/unregisters its owner with MemoryTrackedRegi...
Definition: MemoryTrackedRegistry.h:238
Represents an object group.
Definition: ObjectGroup.h:28
A container for objects groups.
Definition: ObjectGroupsContainer.h:30
bool empty() const
Alias for IsEmpty()
Definition: ObjectGroupsContainer.h:157
const ObjectGroup & operator[](size_t index) const
Alias for Get()
Definition: ObjectGroupsContainer.h:169
void Clear()
Clear all groups of the container.
Definition: ObjectGroupsContainer.h:119
ObjectGroup & at(size_t index)
Alias for Get()
Definition: ObjectGroupsContainer.h:175
std::size_t Count() const
Return the number of groups.
Definition: ObjectGroupsContainer.h:79
ObjectGroup & operator[](size_t index)
Alias for Get()
Definition: ObjectGroupsContainer.h:163
const ObjectGroup & at(size_t index) const
Alias for Get()
Definition: ObjectGroupsContainer.h:181
bool IsEmpty() const
Return true if the container is empty.
Definition: ObjectGroupsContainer.h:84
size_t size() const
Alias for Count()
Definition: ObjectGroupsContainer.h:151
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
Definition: CommonTools.h:24