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 MoveEventsFunction(std::size_t oldIndex, std::size_t newIndex) {
111  return Move(oldIndex, newIndex);
112  };
113  std::size_t GetEventsFunctionPosition(const gd::EventsFunction& eventsFunction) {
114  return GetPosition(eventsFunction);
115  };
116 
120  const std::vector<std::unique_ptr<gd::EventsFunction>>& GetInternalVector()
121  const {
122  return elements;
123  };
124 
128  std::vector<std::unique_ptr<gd::EventsFunction>>& GetInternalVector() {
129  return elements;
130  };
132 
136 
140  return SerializeElementsTo("eventsFunction", element);
141  };
142 
147  const SerializerElement& element) {
148  return UnserializeElementsFrom("eventsFunction", project, element);
149  };
151  protected:
156  void Init(const gd::EventsFunctionsContainer& other) {
158  };
159 
160 private:
161  FunctionOwner owner;
162 };
163 
164 } // namespace gd
165 
166 #endif // GDCORE_EVENTSFUNCTIONSCONTAINER_H
167 #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:39
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:139
std::vector< std::unique_ptr< gd::EventsFunction > > & GetInternalVector()
Provide a raw access to the vector containing the functions.
Definition: EventsFunctionsContainer.h:128
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:120
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:146
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:156
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:169
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