GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
MultipleInstructionMetadata.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 #pragma once
7 
8 #include "GDCore/Extensions/Metadata/ExpressionMetadata.h"
9 #include "GDCore/Extensions/Metadata/InstructionMetadata.h"
10 #include "GDCore/String.h"
11 #include "ParameterOptions.h"
12 
13 namespace gd {} // namespace gd
14 
15 namespace gd {
16 
25  public:
26  static MultipleInstructionMetadata WithExpressionAndCondition(
27  gd::ExpressionMetadata &expression, gd::InstructionMetadata &condition) {
28  return MultipleInstructionMetadata(expression, condition);
29  }
30  static MultipleInstructionMetadata WithExpressionAndConditionAndAction(
31  gd::ExpressionMetadata &expression,
32  gd::InstructionMetadata &condition,
33  gd::InstructionMetadata &action) {
34  return MultipleInstructionMetadata(expression, condition, action);
35  }
36  static MultipleInstructionMetadata WithConditionAndAction(
38  return MultipleInstructionMetadata(condition, action);
39  }
40 
45  const gd::String &type,
46  const gd::String &label,
47  const gd::String &supplementaryInformation = "",
48  bool parameterIsOptional = false) override {
49  if (expression)
50  expression->AddParameter(
51  type, label, supplementaryInformation, parameterIsOptional);
52  if (condition)
53  condition->AddParameter(
54  type, label, supplementaryInformation, parameterIsOptional);
55  if (action)
56  action->AddParameter(
57  type, label, supplementaryInformation, parameterIsOptional);
58  return *this;
59  }
60 
65  const gd::String &type, const gd::String &supplementaryInformation) override {
66  if (expression)
67  expression->AddCodeOnlyParameter(type, supplementaryInformation);
68  if (condition)
69  condition->AddCodeOnlyParameter(type, supplementaryInformation);
70  if (action) action->AddCodeOnlyParameter(type, supplementaryInformation);
71  return *this;
72  }
73 
77  MultipleInstructionMetadata &SetDefaultValue(const gd::String &defaultValue) override {
78  if (expression) expression->SetDefaultValue(defaultValue);
79  if (condition) condition->SetDefaultValue(defaultValue);
80  if (action) action->SetDefaultValue(defaultValue);
81  return *this;
82  };
83 
88  const gd::String &defaultValue) override {
89  if (expression) expression->SetParameterExtraInfo(defaultValue);
90  if (condition) condition->SetParameterExtraInfo(defaultValue);
91  if (action) action->SetParameterExtraInfo(defaultValue);
92  return *this;
93  };
94 
99  const gd::String &longDescription) override {
100  if (expression) expression->SetParameterLongDescription(longDescription);
101  if (condition) condition->SetParameterLongDescription(longDescription);
102  if (action) action->SetParameterLongDescription(longDescription);
103  return *this;
104  };
105 
110  if (expression) expression->SetHidden();
111  if (condition) condition->SetHidden();
112  if (action) action->SetHidden();
113  return *this;
114  };
115 
120  const gd::String &capability) {
121  if (expression) expression->SetRequiresBaseObjectCapability(capability);
122  if (condition) condition->SetRequiresBaseObjectCapability(capability);
123  if (action) action->SetRequiresBaseObjectCapability(capability);
124  return *this;
125  }
126 
132  const gd::String &type, const ParameterOptions &options) {
133  if (condition)
134  condition->UseStandardRelationalOperatorParameters(type, options);
135  if (action) action->UseStandardOperatorParameters(type, options);
136  return *this;
137  }
138 
139  MultipleInstructionMetadata &SetFunctionName(const gd::String &functionName) override {
140  if (expression) expression->SetFunctionName(functionName);
141  if (condition) condition->SetFunctionName(functionName);
142  if (action) action->SetFunctionName(functionName);
143  return *this;
144  }
145 
146  MultipleInstructionMetadata &SetGetter(const gd::String &getter) {
147  if (expression) expression->SetFunctionName(getter);
148  if (condition) condition->SetFunctionName(getter);
149  if (action) action->SetGetter(getter);
150  return *this;
151  }
152 
157  MultipleInstructionMetadata &SetIncludeFile(const gd::String &includeFile) override {
158  if (expression)
159  expression->SetIncludeFile(includeFile);
160  if (condition)
161  condition->SetIncludeFile(includeFile);
162  if (action) action->SetIncludeFile(includeFile);
163  return *this;
164  }
165 
166  MultipleInstructionMetadata &AddIncludeFile(const gd::String &includeFile) override {
167  if (expression)
168  expression->GetCodeExtraInformation().AddIncludeFile(includeFile);
169  if (condition)
170  condition->AddIncludeFile(includeFile);
171  if (action) action->AddIncludeFile(includeFile);
172  return *this;
173  }
174 
178  const std::vector<gd::String> &GetIncludeFiles() const override {
179  if (expression)
180  return expression->GetCodeExtraInformation().GetIncludeFiles();
181  if (condition)
182  return condition->GetIncludeFiles();
183  if (action) return action->GetIncludeFiles();
184  // It can't actually happen.
185  throw std::logic_error("no instruction metadata");
186  }
187 
192  if (expression) expression->SetPrivate();
193  if (condition) condition->SetPrivate();
194  if (action) action->SetPrivate();
195  return *this;
196  }
197 
202  if (expression) expression->SetHelpPath(path);
203  if (condition) condition->SetHelpPath(path);
204  if (action) action->SetHelpPath(path);
205  return *this;
206  }
207 
212  if (condition) condition->MarkAsSimple();
213  if (action) action->MarkAsSimple();
214  return *this;
215  }
216 
221  if (condition) condition->MarkAsAdvanced();
222  if (action) action->MarkAsAdvanced();
223  return *this;
224  }
225 
230  if (condition) condition->MarkAsComplex();
231  if (action) action->MarkAsComplex();
232  return *this;
233  }
234 
239  if (condition) condition->SetRelevantForLayoutEventsOnly();
240  if (action) action->SetRelevantForLayoutEventsOnly();
241  return *this;
242  }
243 
248  if (condition) condition->SetRelevantForFunctionEventsOnly();
249  if (action) action->SetRelevantForFunctionEventsOnly();
250  return *this;
251  }
252 
257  if (condition) condition->SetRelevantForAsynchronousFunctionEventsOnly();
258  if (action) action->SetRelevantForAsynchronousFunctionEventsOnly();
259  return *this;
260  }
261 
266  if (condition) condition->SetRelevantForCustomObjectEventsOnly();
267  if (action) action->SetRelevantForCustomObjectEventsOnly();
268  return *this;
269  }
270 
275  : expression(nullptr), condition(nullptr), action(nullptr){};
276 
277  private:
279  gd::InstructionMetadata &condition_)
280  : expression(&expression_), condition(&condition_), action(nullptr){};
281  MultipleInstructionMetadata(gd::ExpressionMetadata &expression_,
282  gd::InstructionMetadata &condition_,
283  gd::InstructionMetadata &action_)
284  : expression(&expression_), condition(&condition_), action(&action_){};
285  MultipleInstructionMetadata(gd::InstructionMetadata &condition_,
286  gd::InstructionMetadata &action_)
287  : expression(nullptr), condition(&condition_), action(&action_){};
288 
289  gd::ExpressionMetadata *expression;
290  gd::InstructionMetadata *condition;
291  gd::InstructionMetadata *action;
292 };
293 
294 } // namespace gd
Describe user-friendly information about an expression or an instruction (action or condition),...
Definition: AbstractFunctionMetadata.h:36
Describe user-friendly information about an expression, its parameters and the function name as well ...
Definition: ExpressionMetadata.h:47
ExpressionMetadata & SetParameterExtraInfo(const gd::String &extraInfo) override
Set the additional information, used for some parameters with special type (for example,...
Definition: ExpressionMetadata.h:221
gd::ExpressionMetadata & AddParameter(const gd::String &type, const gd::String &label, const gd::String &supplementaryInformation="", bool parameterIsOptional=false) override
Definition: ExpressionMetadata.cpp:36
ExpressionMetadata & SetHelpPath(const gd::String &path)
Definition: ExpressionMetadata.h:93
ExpressionMetadata & GetCodeExtraInformation()
Return the structure containing the information about code generation for the expression.
Definition: ExpressionMetadata.h:352
ExpressionMetadata & SetHidden() override
Set the expression as not shown in the IDE.
Definition: ExpressionMetadata.cpp:31
const std::vector< gd::String > & GetIncludeFiles() const override
Get the files that must be included to use the instruction.
Definition: ExpressionMetadata.h:316
ExpressionMetadata & SetDefaultValue(const gd::String &defaultValue) override
Definition: ExpressionMetadata.h:195
ExpressionMetadata & SetIncludeFile(const gd::String &includeFile) override
Erase any existing include file and add the specified include.
Definition: ExpressionMetadata.h:294
ExpressionMetadata & SetRequiresBaseObjectCapability(const gd::String &capability)
Mark this (object) expression as requiring the specified capability, offered by the base object....
Definition: ExpressionMetadata.cpp:78
ExpressionMetadata & SetFunctionName(const gd::String &functionName) override
Set the function name which will be used when generating the code.
Definition: ExpressionMetadata.h:268
ExpressionMetadata & SetParameterLongDescription(const gd::String &longDescription) override
Set the long description shown in the editor for the last added parameter.
Definition: ExpressionMetadata.h:208
gd::ExpressionMetadata & AddCodeOnlyParameter(const gd::String &type, const gd::String &supplementaryInformation) override
Definition: ExpressionMetadata.cpp:66
ExpressionMetadata & AddIncludeFile(const gd::String &includeFile) override
Add a file to the already existing include files.
Definition: ExpressionMetadata.h:304
ExpressionMetadata & SetPrivate() override
Definition: ExpressionMetadata.h:108
Describe user-friendly information about an instruction (action or condition), its parameters and the...
Definition: InstructionMetadata.h:38
InstructionMetadata & MarkAsComplex()
Consider that the instruction is complex for a user to understand.
Definition: InstructionMetadata.h:373
InstructionMetadata & UseStandardOperatorParameters(const gd::String &type, const ParameterOptions &options)
Add the default parameters for an instruction manipulating the specified type ("string",...
Definition: InstructionMetadata.cpp:95
InstructionMetadata & MarkAsSimple()
Consider that the instruction is easy for a user to understand.
Definition: InstructionMetadata.h:356
InstructionMetadata & SetDefaultValue(const gd::String &defaultValue_) override
Set the default value used in editor (or if an optional parameter is empty during code generation) fo...
Definition: InstructionMetadata.h:258
InstructionMetadata & SetRelevantForAsynchronousFunctionEventsOnly() override
Definition: InstructionMetadata.h:154
InstructionMetadata & SetHelpPath(const gd::String &path)
Definition: InstructionMetadata.h:86
InstructionMetadata & SetGetter(const gd::String &getter)
Definition: InstructionMetadata.h:482
InstructionMetadata & SetIncludeFile(const gd::String &includeFile) override
Erase any existing include file and add the specified include.
Definition: InstructionMetadata.h:500
InstructionMetadata & SetRelevantForLayoutEventsOnly() override
Definition: InstructionMetadata.h:138
InstructionMetadata & UseStandardRelationalOperatorParameters(const gd::String &type, const ParameterOptions &options)
Add the default parameters for an instruction comparing the specified type ("string",...
Definition: InstructionMetadata.cpp:160
InstructionMetadata & SetPrivate() override
Definition: InstructionMetadata.h:101
InstructionMetadata & AddIncludeFile(const gd::String &includeFile) override
Add a file to the already existing include files.
Definition: InstructionMetadata.h:509
const std::vector< gd::String > & GetIncludeFiles() const override
Get the files that must be included to use the instruction.
Definition: InstructionMetadata.h:520
InstructionMetadata & SetParameterExtraInfo(const gd::String &extraInfo) override
Set the additional information, used for some parameters with special type (for example,...
Definition: InstructionMetadata.h:283
InstructionMetadata & SetRequiresBaseObjectCapability(const gd::String &capability)
Mark this (object) instruction as requiring the specified capability, offered by the base object....
Definition: InstructionMetadata.cpp:213
InstructionMetadata & AddParameter(const gd::String &type, const gd::String &label, const gd::String &supplementaryInformation="", bool parameterIsOptional=false) override
Add a parameter to the instruction metadata.
Definition: InstructionMetadata.cpp:54
InstructionMetadata & SetRelevantForFunctionEventsOnly() override
Definition: InstructionMetadata.h:146
InstructionMetadata & SetParameterLongDescription(const gd::String &longDescription) override
Set the long description shown in the editor for the last added parameter.
Definition: InstructionMetadata.h:269
InstructionMetadata & SetFunctionName(const gd::String &functionName_) override
Definition: InstructionMetadata.h:414
InstructionMetadata & SetRelevantForCustomObjectEventsOnly() override
Definition: InstructionMetadata.h:162
InstructionMetadata & MarkAsAdvanced()
Consider that the instruction is harder for a user to understand than a normal instruction.
Definition: InstructionMetadata.h:365
InstructionMetadata & AddCodeOnlyParameter(const gd::String &type, const gd::String &supplementaryInformation) override
Add a parameter not displayed in editor.
Definition: InstructionMetadata.cpp:84
InstructionMetadata & SetHidden() override
Set the instruction to be hidden in the IDE.
Definition: InstructionMetadata.h:197
A "composite" metadata that can be used to easily declare both an expression and a related condition ...
Definition: MultipleInstructionMetadata.h:24
MultipleInstructionMetadata & SetRequiresBaseObjectCapability(const gd::String &capability)
Definition: MultipleInstructionMetadata.h:119
MultipleInstructionMetadata & SetRelevantForLayoutEventsOnly() override
Definition: MultipleInstructionMetadata.h:238
const std::vector< gd::String > & GetIncludeFiles() const override
Get the files that must be included to use the instruction.
Definition: MultipleInstructionMetadata.h:178
MultipleInstructionMetadata & SetDefaultValue(const gd::String &defaultValue) override
Definition: MultipleInstructionMetadata.h:77
MultipleInstructionMetadata & AddParameter(const gd::String &type, const gd::String &label, const gd::String &supplementaryInformation="", bool parameterIsOptional=false) override
Definition: MultipleInstructionMetadata.h:44
MultipleInstructionMetadata & SetIncludeFile(const gd::String &includeFile) override
Definition: MultipleInstructionMetadata.h:157
MultipleInstructionMetadata & SetRelevantForCustomObjectEventsOnly() override
Definition: MultipleInstructionMetadata.h:265
MultipleInstructionMetadata & UseStandardParameters(const gd::String &type, const ParameterOptions &options)
Definition: MultipleInstructionMetadata.h:131
MultipleInstructionMetadata & MarkAsSimple()
Definition: MultipleInstructionMetadata.h:211
MultipleInstructionMetadata & SetRelevantForAsynchronousFunctionEventsOnly() override
Definition: MultipleInstructionMetadata.h:256
MultipleInstructionMetadata & SetParameterLongDescription(const gd::String &longDescription) override
Definition: MultipleInstructionMetadata.h:98
MultipleInstructionMetadata & AddCodeOnlyParameter(const gd::String &type, const gd::String &supplementaryInformation) override
Definition: MultipleInstructionMetadata.h:64
MultipleInstructionMetadata & MarkAsAdvanced()
Definition: MultipleInstructionMetadata.h:220
MultipleInstructionMetadata & SetRelevantForFunctionEventsOnly() override
Definition: MultipleInstructionMetadata.h:247
MultipleInstructionMetadata & SetHelpPath(const gd::String &path)
Definition: MultipleInstructionMetadata.h:201
MultipleInstructionMetadata & SetFunctionName(const gd::String &functionName) override
Set the function that should be called when generating the source code from events.
Definition: MultipleInstructionMetadata.h:139
MultipleInstructionMetadata & AddIncludeFile(const gd::String &includeFile) override
Add a file to the already existing include files.
Definition: MultipleInstructionMetadata.h:166
MultipleInstructionMetadata & SetParameterExtraInfo(const gd::String &defaultValue) override
Definition: MultipleInstructionMetadata.h:87
MultipleInstructionMetadata & SetPrivate() override
Definition: MultipleInstructionMetadata.h:191
MultipleInstructionMetadata()
Don't use, only here to fulfill Emscripten bindings requirements.
Definition: MultipleInstructionMetadata.h:274
MultipleInstructionMetadata & MarkAsComplex()
Definition: MultipleInstructionMetadata.h:229
MultipleInstructionMetadata & SetHidden() override
Definition: MultipleInstructionMetadata.h:109
String represents an UTF8 encoded string.
Definition: String.h:31
Definition: CommonTools.h:24
Definition: ParameterOptions.h:15