GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
EventsList.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 #if defined(GD_IDE_ONLY)
7 #ifndef GDCORE_EVENTSLIST_H
8 #define GDCORE_EVENTSLIST_H
9 #include <memory>
10 #include <vector>
11 #include "GDCore/String.h"
12 namespace gd {
13 class Project;
14 }
15 namespace gd {
16 class BaseEvent;
17 }
18 namespace gd {
19 class SerializerElement;
20 }
21 
22 #undef CreateEvent
23 
24 namespace gd {
25 
32 class GD_CORE_API EventsList {
33  public:
34  EventsList();
35  EventsList(const EventsList&);
36  virtual ~EventsList(){};
37  EventsList& operator=(const EventsList& rhs);
38 
47  gd::BaseEvent& InsertEvent(const gd::BaseEvent& event,
48  size_t position = (size_t)-1);
49 
58  void InsertEvent(std::shared_ptr<gd::BaseEvent> event,
59  size_t position = (size_t)-1);
60 
69  gd::BaseEvent& InsertNewEvent(gd::Project& project,
70  const gd::String& eventType,
71  size_t position = (size_t)-1);
72 
76  void InsertEvents(const EventsList& otherEvents,
77  size_t begin,
78  size_t end,
79  size_t position = (size_t)-1);
80 
84  size_t GetEventsCount() const { return events.size(); };
85 
90  std::shared_ptr<BaseEvent> GetEventSmartPtr(size_t index) {
91  return events[index];
92  };
93 
98  std::shared_ptr<const BaseEvent> GetEventSmartPtr(size_t index) const {
99  return events[index];
100  };
101 
106  gd::BaseEvent& GetEvent(size_t index) { return *events[index]; };
107 
112  const gd::BaseEvent& GetEvent(size_t index) const { return *events[index]; };
113 
117  void RemoveEvent(const gd::BaseEvent& event);
118 
122  void RemoveEvent(size_t index);
123 
127  bool IsEmpty() const { return events.empty(); };
128 
132  void Clear() { return events.clear(); };
133 
138 
143  bool Contains(const gd::BaseEvent& eventToSearch,
144  bool recursive = true) const;
145 
161  bool MoveEventToAnotherEventsList(const gd::BaseEvent& eventToMove,
162  gd::EventsList& newEventsList,
163  std::size_t newPosition);
165 
170 
175  size_t size() const { return GetEventsCount(); }
176 
181  gd::BaseEvent& operator[](size_t index) { return GetEvent(index); };
182 
187  const gd::BaseEvent& operator[](size_t index) const {
188  return GetEvent(index);
189  };
191 
196 
200  void SerializeTo(SerializerElement& element) const;
201 
206  void UnserializeFrom(gd::Project& project, const SerializerElement& element);
208 
209  private:
210  std::vector<std::shared_ptr<BaseEvent> > events;
211 
216  void Init(const gd::EventsList& other);
217 };
218 
219 } // namespace gd
220 
221 #endif
222 #endif
Base class defining an event.
Definition: Event.h:43
A list of events.
Definition: EventsList.h:32
size_t size() const
Alias for GetEventsCount()
Definition: EventsList.h:175
const gd::BaseEvent & GetEvent(size_t index) const
Return a reference to the event at position index in the events list.
Definition: EventsList.h:112
const gd::BaseEvent & operator[](size_t index) const
Alias for GetEvent()
Definition: EventsList.h:187
std::shared_ptr< BaseEvent > GetEventSmartPtr(size_t index)
Return the smart pointer to the event at position index in the events list.
Definition: EventsList.h:90
size_t GetEventsCount() const
Return the number of events.
Definition: EventsList.h:84
void Clear()
Clear the list of events.
Definition: EventsList.h:132
bool IsEmpty() const
Return true if there isn't any event in the list.
Definition: EventsList.h:127
gd::BaseEvent & GetEvent(size_t index)
Return a reference to the event at position index in the events list.
Definition: EventsList.h:106
std::shared_ptr< const BaseEvent > GetEventSmartPtr(size_t index) const
Return the smart pointer to the event at position index in the events list.
Definition: EventsList.h:98
gd::BaseEvent & operator[](size_t index)
Alias for GetEvent()
Definition: EventsList.h:181
Base class representing a project (game), including all resources, scenes, objects,...
Definition: Project.h:51
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