GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
VariablesContainer.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_VARIABLESCONTAINER_H
8 #define GDCORE_VARIABLESCONTAINER_H
9 #include <memory>
10 #include <vector>
11 #include "GDCore/Project/Variable.h"
12 #include "GDCore/String.h"
13 namespace gd {
14 class SerializerElement;
15 }
16 class TiXmlElement;
17 
18 namespace gd {
19 
30 class GD_CORE_API VariablesContainer {
31  public:
34  virtual ~VariablesContainer(){};
35 
36  VariablesContainer& operator=(const VariablesContainer& rhs);
37 
42 
46  bool Has(const gd::String& name) const;
47 
51  Variable& Get(const gd::String& name);
52 
56  const Variable& Get(const gd::String& name) const;
57 
62  Variable& Get(std::size_t index);
63 
68  const Variable& Get(std::size_t index) const;
69 
78  Variable& Insert(const gd::String& name,
79  const Variable& variable,
80  std::size_t position);
81 
85  std::size_t Count() const { return variables.size(); };
86 
90  const gd::String& GetNameAt(std::size_t index) const;
91 
92 #if defined(GD_IDE_ONLY)
97  std::size_t GetPosition(const gd::String& name) const;
98 
106  Variable& InsertNew(const gd::String& name, std::size_t position = -1);
107 
112  void Remove(const gd::String& name);
113 
117  void RemoveRecursively(const gd::Variable& variable);
118 
123  bool Rename(const gd::String& oldName, const gd::String& newName);
124 
128  void Swap(std::size_t firstVariableIndex, std::size_t secondVariableIndex);
129 
133  void Move(std::size_t oldIndex, std::size_t newIndex);
134 #endif
135 
139  inline void Clear() { variables.clear(); }
140 
144  void ForEachVariableMatchingSearch(const gd::String& search, std::function<void(const gd::String& name, const gd::Variable& variable)> fn) const;
146 
151 
154  void SerializeTo(SerializerElement& element) const;
155 
159  void UnserializeFrom(const SerializerElement& element);
160 
165  VariablesContainer& ResetPersistentUuid();
166 
171  VariablesContainer& ClearPersistentUuid();
172 
177  const gd::String& GetPersistentUuid() const { return persistentUuid; };
179 
180  private:
181  std::vector<std::pair<gd::String, std::shared_ptr<gd::Variable>>> variables;
182  mutable gd::String persistentUuid;
184  static gd::Variable badVariable;
185  static gd::String badName;
186 
191  void Init(const VariablesContainer& other);
192 };
193 
194 } // namespace gd
195 
196 #endif // GDCORE_VARIABLESCONTAINER_H
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
Defines a variable which can be used by an object, a layout or a project.
Definition: Variable.h:29
Class defining a container for gd::Variable.
Definition: VariablesContainer.h:30
const gd::String & GetPersistentUuid() const
Get the persistent UUID used to recognize the same variables between serialization.
Definition: VariablesContainer.h:177
void Clear()
Clear all variables of the container.
Definition: VariablesContainer.h:139
std::size_t Count() const
Return the number of variables.
Definition: VariablesContainer.h:85
Definition: CommonTools.h:24