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/ObjectGroup.h"
14 #include "GDCore/String.h"
15 namespace gd {
16 class SerializerElement;
17 }
18 
19 namespace gd {
20 
29 class GD_CORE_API ObjectGroupsContainer {
30  public:
33  virtual ~ObjectGroupsContainer(){};
34  ObjectGroupsContainer& operator=(const ObjectGroupsContainer& rhs);
35 
39  bool Has(const gd::String& name) const;
40 
44  ObjectGroup& Get(const gd::String& name);
45 
49  const ObjectGroup& Get(const gd::String& name) const;
50 
56  ObjectGroup& Get(std::size_t index);
57 
63  const ObjectGroup& Get(std::size_t index) const;
64 
72  ObjectGroup& Insert(const ObjectGroup& objectGroup,
73  std::size_t position = -1);
74 
78  std::size_t Count() const { return objectGroups.size(); };
79 
83  bool IsEmpty() const { return objectGroups.empty(); };
84 
88  std::size_t GetPosition(const gd::String& name) const;
89 
97  ObjectGroup& InsertNew(const gd::String& name, std::size_t position = -1);
98 
102  void Remove(const gd::String& name);
103 
108  bool Rename(const gd::String& oldName, const gd::String& newName);
109 
113  void Move(std::size_t oldIndex, std::size_t newIndex);
114 
118  inline void Clear() { objectGroups.clear(); }
119 
123  void ForEachNameMatchingSearch(const gd::String& search, std::function<void(const gd::String& name)> fn) const;
125 
130 
133  void SerializeTo(SerializerElement& element) const;
134 
138  void UnserializeFrom(const SerializerElement& element);
140 
145 
150  size_t size() const { return Count(); }
151 
156  bool empty() const { return IsEmpty(); }
157 
162  ObjectGroup& operator[](size_t index) { return Get(index); };
163 
168  const ObjectGroup& operator[](size_t index) const { return Get(index); };
169 
174  ObjectGroup& at(size_t index) { return Get(index); };
175 
180  const ObjectGroup& at(size_t index) const { return Get(index); };
182 
187  void Init(const gd::ObjectGroupsContainer& other);
188 
189  private:
190  std::vector<std::unique_ptr<gd::ObjectGroup>> objectGroups;
191  static ObjectGroup badGroup;
192 };
193 
194 } // namespace gd
195 
196 #endif // GDCORE_OBJECTGROUPSCONTAINER_H
Represents an object group.
Definition: ObjectGroup.h:28
A container for objects groups.
Definition: ObjectGroupsContainer.h:29
bool empty() const
Alias for IsEmpty()
Definition: ObjectGroupsContainer.h:156
const ObjectGroup & operator[](size_t index) const
Alias for Get()
Definition: ObjectGroupsContainer.h:168
void Clear()
Clear all groups of the container.
Definition: ObjectGroupsContainer.h:118
ObjectGroup & at(size_t index)
Alias for Get()
Definition: ObjectGroupsContainer.h:174
std::size_t Count() const
Return the number of groups.
Definition: ObjectGroupsContainer.h:78
ObjectGroup & operator[](size_t index)
Alias for Get()
Definition: ObjectGroupsContainer.h:162
const ObjectGroup & at(size_t index) const
Alias for Get()
Definition: ObjectGroupsContainer.h:180
bool IsEmpty() const
Return true if the container is empty.
Definition: ObjectGroupsContainer.h:83
size_t size() const
Alias for Count()
Definition: ObjectGroupsContainer.h:150
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:31
Definition: CommonTools.h:24