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 #pragma once
7 
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 
16 namespace gd {
17 class Instruction;
18 class BaseEvent;
19 class LinkEvent;
20 class EventsList;
21 class ObjectsContainer;
22 class Expression;
23 class ParameterMetadata;
24 } // namespace gd
25 
26 namespace gd {
27 
37 class GD_CORE_API AbstractArbitraryEventsWorker : private EventVisitor {
38  public:
41 
42 protected:
43  virtual bool VisitEvent(gd::BaseEvent& event) override;
44  void VisitEventList(gd::EventsList& events);
45 
46  private:
47  bool VisitLinkEvent(gd::LinkEvent& linkEvent) override;
48  void VisitInstructionList(gd::InstructionsList& instructions,
49  bool areConditions);
50  bool VisitInstruction(gd::Instruction& instruction, bool isCondition);
51  bool VisitEventExpression(gd::Expression& expression, const gd::ParameterMetadata& metadata);
52 
56  virtual void DoVisitEventList(gd::EventsList& events){};
57 
63  virtual bool DoVisitEvent(gd::BaseEvent& event) { return false; };
64 
73  virtual bool DoVisitLinkEvent(gd::LinkEvent& event) { return false; };
74 
78  virtual void DoVisitInstructionList(gd::InstructionsList& instructions,
79  bool areConditions){};
80 
86  virtual bool DoVisitInstruction(gd::Instruction& instruction,
87  bool isCondition) {
88  return false;
89  };
90 
96  virtual bool DoVisitEventExpression(gd::Expression& expression,
97  const gd::ParameterMetadata& metadata) {
98  return false;
99  }
100 };
101 
112 public:
114  virtual ~ArbitraryEventsWorker();
115 
119  void Launch(gd::EventsList &events) {
120  AbstractArbitraryEventsWorker::VisitEventList(events);
121  };
122 
123 private:
124  bool VisitEvent(gd::BaseEvent &event) override;
125 };
126 
137  public:
139  : currentProjectScopedContainers(nullptr){};
141 
146  void Launch(gd::EventsList& events,
147  const gd::ProjectScopedContainers& projectScopedContainers) {
148  currentProjectScopedContainers = &projectScopedContainers;
149  AbstractArbitraryEventsWorker::VisitEventList(events);
150  };
151 
152 protected:
153  const gd::ProjectScopedContainers& GetProjectScopedContainers() {
154  // Pointers are guaranteed to be not nullptr after
155  // Launch was called.
156  return *currentProjectScopedContainers;
157  };
158  const gd::ObjectsContainersList& GetObjectsContainersList() {
159  // Pointers are guaranteed to be not nullptr after
160  // Launch was called.
161  return currentProjectScopedContainers->GetObjectsContainersList();
162  };
163 
164  private:
165  bool VisitEvent(gd::BaseEvent& event) override;
166 
167  const gd::ProjectScopedContainers* currentProjectScopedContainers;
168 };
169 
180  public:
181  AbstractReadOnlyArbitraryEventsWorker() : shouldStopIteration(false) {};
183 
184 protected:
185  void StopAnyEventIteration() override;
186  virtual void VisitEvent(const gd::BaseEvent& event) override;
187 
188  void VisitEventList(const gd::EventsList& events);
189 
190  private:
191  void VisitLinkEvent(const gd::LinkEvent& linkEvent) override;
192  void VisitInstructionList(const gd::InstructionsList& instructions,
193  bool areConditions);
194  void VisitInstruction(const gd::Instruction& instruction, bool isCondition);
195  void VisitEventExpression(const gd::Expression& expression, const gd::ParameterMetadata& metadata);
196 
200  virtual void DoVisitEventList(const gd::EventsList& events){};
201 
205  virtual void DoVisitEvent(const gd::BaseEvent& event) {};
206 
212  virtual void DoVisitLinkEvent(const gd::LinkEvent& linkEvent) {};
213 
217  virtual void DoVisitInstructionList(const gd::InstructionsList& instructions,
218  bool areConditions){};
219 
223  virtual void DoVisitInstruction(const gd::Instruction& instruction,
224  bool isCondition) {};
225 
229  virtual void DoVisitEventExpression(const gd::Expression& expression,
230  const gd::ParameterMetadata& metadata) {
231  }
232 
233  bool shouldStopIteration;
234 };
235 
246 public:
249 
253  void Launch(const gd::EventsList &events) {
254  AbstractReadOnlyArbitraryEventsWorker::VisitEventList(events);
255  };
256 
257 private:
258  void VisitEvent(const gd::BaseEvent &event) override;
259 };
260 
271  public:
273  : currentProjectScopedContainers(nullptr){};
275 
280  void Launch(const gd::EventsList& events,
281  const gd::ProjectScopedContainers& projectScopedContainers) {
282  currentProjectScopedContainers = &projectScopedContainers;
283  AbstractReadOnlyArbitraryEventsWorker::VisitEventList(events);
284  };
285 
286 protected:
287  const gd::ProjectScopedContainers& GetProjectScopedContainers() {
288  // Pointers are guaranteed to be not nullptr after
289  // Launch was called.
290  return *currentProjectScopedContainers;
291  };
292 
293  private:
294  void VisitEvent(const gd::BaseEvent& event) override;
295 
296  const gd::ProjectScopedContainers* currentProjectScopedContainers;
297 };
298 
299 } // namespace gd
AbstractArbitraryEventsWorker is a base abstract class used to browse events (and instructions) and d...
Definition: ArbitraryEventsWorker.h:37
ReadOnlyArbitraryEventsWorker is an abstract class used to browse events (and instructions)....
Definition: ArbitraryEventsWorker.h:179
ArbitraryEventsWorker is an abstract class used to browse events (and instructions) and do some work ...
Definition: ArbitraryEventsWorker.h:111
void Launch(gd::EventsList &events)
Launch the worker on the specified events list.
Definition: ArbitraryEventsWorker.h:119
An events worker that will know about the context (the objects container). Useful for workers working...
Definition: ArbitraryEventsWorker.h:136
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:146
Base class defining an event.
Definition: Event.h:43
Visitor of any kind of event.
Definition: EventVisitor.h:26
A list of events.
Definition: EventsList.h:32
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:34
ReadOnlyArbitraryEventsWorker is an abstract class used to browse events (and instructions)....
Definition: ArbitraryEventsWorker.h:245
void Launch(const gd::EventsList &events)
Launch the worker on the specified events list.
Definition: ArbitraryEventsWorker.h:253
An events worker that will know about the context (the objects container). Useful for workers working...
Definition: ArbitraryEventsWorker.h:270
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:280
Visitor of any kind of event.
Definition: EventVisitor.h:54
Definition: CommonTools.h:24