GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
Instruction.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 INSTRUCTION_H
7 #define INSTRUCTION_H
8 #include <memory>
9 #include <vector>
10 
11 #include "GDCore/Events/Expression.h"
12 #include "GDCore/Events/InstructionsList.h"
13 #include "GDCore/String.h"
14 
15 namespace gd {
16 
30 class GD_CORE_API Instruction {
31  public:
36  Instruction(gd::String type_ = "");
37 
45  Instruction(gd::String type_,
46  const std::vector<gd::Expression>& parameters_,
47  bool inverted = false);
48 
49  virtual ~Instruction(){};
50 
55  const gd::String& GetType() const { return type; }
56 
61  void SetType(const gd::String& newType) { type = newType; }
62 
67  bool IsInverted() const { return inverted; }
68 
73  void SetInverted(bool inverted_) { inverted = inverted_; }
74 
81  bool IsAwaited() const { return awaitAsync; }
82 
89  void SetAwaited(bool awaited) { awaitAsync = awaited; }
90 
94  std::size_t GetParametersCount() const { return parameters.size(); }
95 
102  void SetParametersCount(std::size_t size);
103 
110  const gd::Expression& GetParameter(std::size_t index) const;
111 
118  gd::Expression& GetParameter(std::size_t index);
119 
124  void SetParameter(std::size_t nb, const gd::Expression& val);
125 
129  void AddParameter(const gd::Expression& val);
130 
134  inline const std::vector<gd::Expression>& GetParameters() const {
135  return parameters;
136  }
137 
141  inline void SetParameters(const std::vector<gd::Expression>& val) {
142  parameters = val;
143  }
144 
148  inline const gd::InstructionsList& GetSubInstructions() const {
149  return subInstructions;
150  };
151 
155  inline gd::InstructionsList& GetSubInstructions() { return subInstructions; };
156 
163  std::weak_ptr<Instruction> GetOriginalInstruction() {
164  return originalInstruction;
165  };
166 
167  friend std::shared_ptr<Instruction> CloneRememberingOriginalElement(
168  std::shared_ptr<Instruction> instruction);
169 
170  private:
171  gd::String type;
172  bool inverted;
174  bool awaitAsync =
175  false;
177  mutable std::vector<gd::Expression>
178  parameters;
179  gd::InstructionsList subInstructions;
180 
181  std::weak_ptr<Instruction>
182  originalInstruction;
187 
188  static gd::Expression badExpression;
189 };
190 
195 std::shared_ptr<Instruction> GD_CORE_API
196 CloneRememberingOriginalElement(std::shared_ptr<Instruction> instruction);
197 
198 } // namespace gd
199 
200 #endif // INSTRUCTION_H
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
void SetType(const gd::String &newType)
Change the instruction type.
Definition: Instruction.h:61
const gd::String & GetType() const
Return the type of the instruction.
Definition: Instruction.h:55
const std::vector< gd::Expression > & GetParameters() const
Get a reference to the std::vector containing the parameters.
Definition: Instruction.h:134
std::size_t GetParametersCount() const
Return the number of parameters of the instruction.
Definition: Instruction.h:94
void SetInverted(bool inverted_)
Set if the instruction is inverted or not.
Definition: Instruction.h:73
void SetParameters(const std::vector< gd::Expression > &val)
Replace all the parameters by new ones.
Definition: Instruction.h:141
void SetAwaited(bool awaited)
Set if the async instruction is to be awaited or not. This is not relevant if the instruction is not ...
Definition: Instruction.h:89
gd::InstructionsList & GetSubInstructions()
Return a reference to the vector containing sub instructions.
Definition: Instruction.h:155
std::weak_ptr< Instruction > GetOriginalInstruction()
Return the original instruction this instruction was copied from.
Definition: Instruction.h:163
bool IsInverted() const
Return true if the condition is inverted.
Definition: Instruction.h:67
const gd::InstructionsList & GetSubInstructions() const
Return a reference to the vector containing sub instructions.
Definition: Instruction.h:148
bool IsAwaited() const
Return true if the async instruction should be awaited. This is not relevant if the instruction is no...
Definition: Instruction.h:81
Definition: InstructionsList.h:25
String represents an UTF8 encoded string.
Definition: String.h:33
Definition: CommonTools.h:24
std::shared_ptr< Instruction > GD_CORE_API CloneRememberingOriginalElement(std::shared_ptr< Instruction > instruction)
Definition: Instruction.cpp:63