GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
ArbitraryEventsWorker.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 #ifndef GDCORE_ARBITRARYEVENTSWORKER_H
7 #define GDCORE_ARBITRARYEVENTSWORKER_H
8 #include <map>
9 #include <memory>
10 #include <vector>
11 #include "GDCore/Events/InstructionsList.h"
12 #include "GDCore/Events/EventVisitor.h"
13 #include "GDCore/Project/ProjectScopedContainers.h"
14 #include "GDCore/String.h"
15 namespace gd {
16 class Instruction;
17 class BaseEvent;
18 class LinkEvent;
19 class EventsList;
20 class ObjectsContainer;
21 class Expression;
22 class ParameterMetadata;
23 } // namespace gd
24 
25 namespace gd {
26 
36 class GD_CORE_API ArbitraryEventsWorker : private EventVisitor {
37  public:
39  virtual ~ArbitraryEventsWorker();
40 
44  void Launch(gd::EventsList& events) { VisitEventList(events); };
45 
46  private:
47  void VisitEventList(gd::EventsList& events);
48  bool VisitEvent(gd::BaseEvent& event) override;
49  bool VisitLinkEvent(gd::LinkEvent& linkEvent) override;
50  void VisitInstructionList(gd::InstructionsList& instructions,
51  bool areConditions);
52  bool VisitInstruction(gd::Instruction& instruction, bool isCondition);
53  bool VisitEventExpression(gd::Expression& expression, const gd::ParameterMetadata& metadata);
54 
58  virtual void DoVisitEventList(gd::EventsList& events){};
59 
65  virtual bool DoVisitEvent(gd::BaseEvent& event) { return false; };
66 
75  virtual bool DoVisitLinkEvent(gd::LinkEvent& event) { return false; };
76 
80  virtual void DoVisitInstructionList(gd::InstructionsList& instructions,
81  bool areConditions){};
82 
88  virtual bool DoVisitInstruction(gd::Instruction& instruction,
89  bool isCondition) {
90  return false;
91  };
92 
98  virtual bool DoVisitEventExpression(gd::Expression& expression,
99  const gd::ParameterMetadata& metadata) {
100  return false;
101  }
102 };
103 
113  : public ArbitraryEventsWorker {
114  public:
116  : projectScopedContainers(nullptr){};
118 
123  void Launch(gd::EventsList& events,
124  const gd::ProjectScopedContainers& projectScopedContainers_) {
125  projectScopedContainers = &projectScopedContainers_;
127  };
128 
129  void Launch(gd::EventsList& events) = delete;
130 
131  protected:
132  const gd::ProjectScopedContainers& GetProjectScopedContainers() {
133  // Pointers are guaranteed to be not nullptr after
134  // Launch was called.
135  return *projectScopedContainers;
136  };
137  const gd::ObjectsContainersList& GetObjectsContainersList() {
138  // Pointers are guaranteed to be not nullptr after
139  // Launch was called.
140  return projectScopedContainers->GetObjectsContainersList();
141  };
142 
143  private:
144  const gd::ProjectScopedContainers* projectScopedContainers;
145 };
146 
156  public:
157  ReadOnlyArbitraryEventsWorker() : shouldStopIteration(false) {};
159 
163  void Launch(const gd::EventsList& events) { VisitEventList(events); };
164 
165 protected:
166  void StopAnyEventIteration() override;
167 
168  private:
169  void VisitEventList(const gd::EventsList& events);
170  void VisitEvent(const gd::BaseEvent& event) override;
171  void VisitLinkEvent(const gd::LinkEvent& linkEvent) override;
172  void VisitInstructionList(const gd::InstructionsList& instructions,
173  bool areConditions);
174  void VisitInstruction(const gd::Instruction& instruction, bool isCondition);
175  void VisitEventExpression(const gd::Expression& expression, const gd::ParameterMetadata& metadata);
176 
180  virtual void DoVisitEventList(const gd::EventsList& events){};
181 
185  virtual void DoVisitEvent(const gd::BaseEvent& event) {};
186 
192  virtual void DoVisitLinkEvent(const gd::LinkEvent& linkEvent) {};
193 
197  virtual void DoVisitInstructionList(const gd::InstructionsList& instructions,
198  bool areConditions){};
199 
203  virtual void DoVisitInstruction(const gd::Instruction& instruction,
204  bool isCondition) {};
205 
209  virtual void DoVisitEventExpression(const gd::Expression& expression,
210  const gd::ParameterMetadata& metadata) {
211  }
212 
213  bool shouldStopIteration;
214 };
215 
226  public:
228  : projectScopedContainers(nullptr){};
230 
235  void Launch(const gd::EventsList& events,
236  const gd::ProjectScopedContainers& projectScopedContainers_) {
237  projectScopedContainers = &projectScopedContainers_;
239  };
240 
241  void Launch(gd::EventsList& events) = delete;
242 
243  protected:
244  const gd::ProjectScopedContainers& GetProjectScopedContainers() {
245  // Pointers are guaranteed to be not nullptr after
246  // Launch was called.
247  return *projectScopedContainers;
248  };
249 
250  private:
251  const gd::ProjectScopedContainers* projectScopedContainers;
252 };
253 
254 } // namespace gd
255 
256 #endif // GDCORE_ARBITRARYEVENTSWORKER_H
ArbitraryEventsWorker is an abstract class used to browse events (and instructions) and do some work ...
Definition: ArbitraryEventsWorker.h:36
void Launch(gd::EventsList &events)
Launch the worker on the specified events list.
Definition: ArbitraryEventsWorker.h:44
An events worker that will know about the context (the objects container). Useful for workers working...
Definition: ArbitraryEventsWorker.h:113
void Launch(gd::EventsList &events, const gd::ProjectScopedContainers &projectScopedContainers_)
Launch the worker on the specified events list, giving the objects container on which the events are ...
Definition: ArbitraryEventsWorker.h:123
Base class defining an event.
Definition: Event.h:44
Visitor of any kind of event.
Definition: EventVisitor.h:26
A list of events.
Definition: EventsList.h:33
Class representing an expression used as a parameter of a gd::Instruction. This class is nothing more...
Definition: Expression.h:30
An instruction is a member of an event: It can be a condition or an action.
Definition: Instruction.h:30
Definition: InstructionsList.h:25
A list of objects containers, useful for accessing objects in a scoped way, along with methods to acc...
Definition: ObjectsContainersList.h:29
Describe a parameter of an instruction (action, condition) or of an expression: type,...
Definition: ParameterMetadata.h:27
Holds references to variables, objects, properties and other containers.
Definition: ProjectScopedContainers.h:30
ReadOnlyArbitraryEventsWorker is an abstract class used to browse events (and instructions)....
Definition: ArbitraryEventsWorker.h:155
void Launch(const gd::EventsList &events)
Launch the worker on the specified events list.
Definition: ArbitraryEventsWorker.h:163
An events worker that will know about the context (the objects container). Useful for workers working...
Definition: ArbitraryEventsWorker.h:225
void Launch(const gd::EventsList &events, const gd::ProjectScopedContainers &projectScopedContainers_)
Launch the worker on the specified events list, giving the objects container on which the events are ...
Definition: ArbitraryEventsWorker.h:235
Visitor of any kind of event.
Definition: EventVisitor.h:54
Definition: CommonTools.h:24