GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
EventsFunctionsContainer.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 #if defined(GD_IDE_ONLY)
7 #ifndef GDCORE_EVENTSFUNCTIONSCONTAINER_H
8 #define GDCORE_EVENTSFUNCTIONSCONTAINER_H
9 #include <vector>
10 #include "GDCore/Project/EventsFunction.h"
11 #include "GDCore/String.h"
12 #include "GDCore/Tools/SerializableWithNameList.h"
13 namespace gd {
14 class SerializerElement;
15 }
16 
17 namespace gd {
18 
26 class GD_CORE_API EventsFunctionsContainer
27  : private SerializableWithNameList<gd::EventsFunction> {
28 public:
29  enum FunctionOwner {
30  Extension,
31  Object,
32  Behavior};
33 
34  EventsFunctionsContainer(FunctionOwner source_) : owner(source_) {}
35 
37  : owner(other.owner) {
38  Init(other);
39  }
40 
41  EventsFunctionsContainer &operator=(const EventsFunctionsContainer &other) {
42  if (this != &other) {
43  owner = other.owner;
44  Init(other);
45  }
46 
47  return *this;
48  }
49 
56  FunctionOwner GetOwner() const {
57  return owner;
58  }
59 
63 
66  bool HasEventsFunctionNamed(const gd::String& name) const {
67  return Has(name);
68  }
69 
77  return Get(name);
78  }
79 
86  const gd::EventsFunction& GetEventsFunction(const gd::String& name) const {
87  return Get(name);
88  }
89 
96  gd::EventsFunction& GetEventsFunction(std::size_t index) {
97  return Get(index);
98  }
99 
106  const gd::EventsFunction& GetEventsFunction(std::size_t index) const {
107  return Get(index);
108  }
109 
113  std::size_t GetEventsFunctionsCount() const { return GetCount(); }
114 
115  gd::EventsFunction& InsertNewEventsFunction(const gd::String& name,
116  std::size_t position) {
117  return InsertNew(name, position);
118  }
119  gd::EventsFunction& InsertEventsFunction(const gd::EventsFunction& object,
120  std::size_t position) {
121  return Insert(object, position);
122  }
123  void RemoveEventsFunction(const gd::String& name) { return Remove(name); }
124  void ClearEventsFunctions() { return Clear(); }
125  void MoveEventsFunction(std::size_t oldIndex, std::size_t newIndex) {
126  return Move(oldIndex, newIndex);
127  };
128  std::size_t GetEventsFunctionPosition(const gd::EventsFunction& eventsFunction) {
129  return GetPosition(eventsFunction);
130  };
131 
135  const std::vector<std::unique_ptr<gd::EventsFunction>>& GetInternalVector()
136  const {
137  return elements;
138  };
139 
143  std::vector<std::unique_ptr<gd::EventsFunction>>& GetInternalVector() {
144  return elements;
145  };
147 
151 
155  return SerializeElementsTo("eventsFunction", element);
156  };
157 
162  const SerializerElement& element) {
163  return UnserializeElementsFrom("eventsFunction", project, element);
164  };
166  protected:
171  void Init(const gd::EventsFunctionsContainer& other) {
173  };
174 
175 private:
176  FunctionOwner owner;
177 };
178 
179 } // namespace gd
180 
181 #endif // GDCORE_EVENTSFUNCTIONSCONTAINER_H
182 #endif
Base class used to represents a behavior that can be applied to an object. It stores the content (i....
Definition: Behavior.h:23
Events that can be generated as a stand-alone function, and used as a condition, action or expression...
Definition: EventsFunction.h:38
Used as a base class for classes that will own events-backed functions.
Definition: EventsFunctionsContainer.h:27
FunctionOwner GetOwner() const
Get the source of the function container.
Definition: EventsFunctionsContainer.h:56
std::size_t GetEventsFunctionsCount() const
Return the number of functions.
Definition: EventsFunctionsContainer.h:113
gd::EventsFunction & GetEventsFunction(const gd::String &name)
Get the function with the specified name.
Definition: EventsFunctionsContainer.h:76
void SerializeEventsFunctionsTo(SerializerElement &element) const
Serialize events functions.
Definition: EventsFunctionsContainer.h:154
std::vector< std::unique_ptr< gd::EventsFunction > > & GetInternalVector()
Provide a raw access to the vector containing the functions.
Definition: EventsFunctionsContainer.h:143
gd::EventsFunction & GetEventsFunction(std::size_t index)
Get the function at the specified index in the list.
Definition: EventsFunctionsContainer.h:96
const std::vector< std::unique_ptr< gd::EventsFunction > > & GetInternalVector() const
Provide a raw access to the vector containing the functions.
Definition: EventsFunctionsContainer.h:135
const gd::EventsFunction & GetEventsFunction(std::size_t index) const
Get the function at the specified index in the list.
Definition: EventsFunctionsContainer.h:106
bool HasEventsFunctionNamed(const gd::String &name) const
Check if the function with the specified name exists.
Definition: EventsFunctionsContainer.h:66
void UnserializeEventsFunctionsFrom(gd::Project &project, const SerializerElement &element)
Unserialize the events functions.
Definition: EventsFunctionsContainer.h:161
const gd::EventsFunction & GetEventsFunction(const gd::String &name) const
Get the function with the specified name.
Definition: EventsFunctionsContainer.h:86
void Init(const gd::EventsFunctionsContainer &other)
Definition: EventsFunctionsContainer.h:171
Represent an object of a platform.
Definition: Object.h:37
Base class representing a project (game), including all resources, scenes, objects,...
Definition: Project.h:50
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
Definition: CommonTools.h:24