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 
42  FunctionOwner GetOwner() const {
43  return owner;
44  }
45 
49 
52  bool HasEventsFunctionNamed(const gd::String& name) const {
53  return Has(name);
54  }
55 
63  return Get(name);
64  }
65 
72  const gd::EventsFunction& GetEventsFunction(const gd::String& name) const {
73  return Get(name);
74  }
75 
82  gd::EventsFunction& GetEventsFunction(std::size_t index) {
83  return Get(index);
84  }
85 
92  const gd::EventsFunction& GetEventsFunction(std::size_t index) const {
93  return Get(index);
94  }
95 
99  std::size_t GetEventsFunctionsCount() const { return GetCount(); }
100 
101  gd::EventsFunction& InsertNewEventsFunction(const gd::String& name,
102  std::size_t position) {
103  return InsertNew(name, position);
104  }
105  gd::EventsFunction& InsertEventsFunction(const gd::EventsFunction& object,
106  std::size_t position) {
107  return Insert(object, position);
108  }
109  void RemoveEventsFunction(const gd::String& name) { return Remove(name); }
110  void ClearEventsFunctions() { return Clear(); }
111  void MoveEventsFunction(std::size_t oldIndex, std::size_t newIndex) {
112  return Move(oldIndex, newIndex);
113  };
114  std::size_t GetEventsFunctionPosition(const gd::EventsFunction& eventsFunction) {
115  return GetPosition(eventsFunction);
116  };
117 
121  const std::vector<std::unique_ptr<gd::EventsFunction>>& GetInternalVector()
122  const {
123  return elements;
124  };
125 
129  std::vector<std::unique_ptr<gd::EventsFunction>>& GetInternalVector() {
130  return elements;
131  };
133 
137 
141  return SerializeElementsTo("eventsFunction", element);
142  };
143 
148  const SerializerElement& element) {
149  return UnserializeElementsFrom("eventsFunction", project, element);
150  };
152  protected:
157  void Init(const gd::EventsFunctionsContainer& other) {
159  };
160 
161 private:
162  FunctionOwner owner;
163 };
164 
165 } // namespace gd
166 
167 #endif // GDCORE_EVENTSFUNCTIONSCONTAINER_H
168 #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:42
std::size_t GetEventsFunctionsCount() const
Return the number of functions.
Definition: EventsFunctionsContainer.h:99
gd::EventsFunction & GetEventsFunction(const gd::String &name)
Get the function with the specified name.
Definition: EventsFunctionsContainer.h:62
void SerializeEventsFunctionsTo(SerializerElement &element) const
Serialize events functions.
Definition: EventsFunctionsContainer.h:140
std::vector< std::unique_ptr< gd::EventsFunction > > & GetInternalVector()
Provide a raw access to the vector containing the functions.
Definition: EventsFunctionsContainer.h:129
gd::EventsFunction & GetEventsFunction(std::size_t index)
Get the function at the specified index in the list.
Definition: EventsFunctionsContainer.h:82
const std::vector< std::unique_ptr< gd::EventsFunction > > & GetInternalVector() const
Provide a raw access to the vector containing the functions.
Definition: EventsFunctionsContainer.h:121
const gd::EventsFunction & GetEventsFunction(std::size_t index) const
Get the function at the specified index in the list.
Definition: EventsFunctionsContainer.h:92
bool HasEventsFunctionNamed(const gd::String &name) const
Check if the function with the specified name exists.
Definition: EventsFunctionsContainer.h:52
void UnserializeEventsFunctionsFrom(gd::Project &project, const SerializerElement &element)
Unserialize the events functions.
Definition: EventsFunctionsContainer.h:147
const gd::EventsFunction & GetEventsFunction(const gd::String &name) const
Get the function with the specified name.
Definition: EventsFunctionsContainer.h:72
void Init(const gd::EventsFunctionsContainer &other)
Definition: EventsFunctionsContainer.h:157
Represent an object of a platform.
Definition: Object.h:37
Base class representing a project (game), including all resources, scenes, objects,...
Definition: Project.h:51
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