GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
ParameterMetadata.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 
7 #pragma once
8 
9 #include <map>
10 #include <memory>
11 
12 #include "GDCore/String.h"
13 #include "GDCore/Extensions/Metadata/ValueTypeMetadata.h"
14 
15 namespace gd {
16 class SerializerElement;
17 } // namespace gd
18 
19 namespace gd {
20 
27 class GD_CORE_API ParameterMetadata {
28  public:
30  virtual ~ParameterMetadata(){};
31 
36  ParameterMetadata* Clone() const { return new ParameterMetadata(*this); };
37 
41  gd::ValueTypeMetadata &GetValueTypeMetadata() { return valueTypeMetadata; }
42 
46  const gd::ValueTypeMetadata &GetValueTypeMetadata() const { return valueTypeMetadata; }
47 
52  valueTypeMetadata = valueTypeMetadata_;
53  return *this;
54  }
55 
61  const gd::String &GetType() const { return valueTypeMetadata.GetName(); }
62 
68  valueTypeMetadata.SetName(type_);
69  return *this;
70  }
71 
79  const gd::String &GetName() const { return name; }
80 
89  name = name_;
90  return *this;
91  }
92 
99  const gd::String &GetExtraInfo() const { return valueTypeMetadata.GetExtraInfo(); }
100 
107  ParameterMetadata &SetExtraInfo(const gd::String &supplementaryInformation_) {
108  valueTypeMetadata.SetExtraInfo(supplementaryInformation_);
109  return *this;
110  }
111 
116  bool IsOptional() const { return valueTypeMetadata.IsOptional(); }
117 
122  ParameterMetadata &SetOptional(bool optional_ = true) {
123  valueTypeMetadata.SetOptional(optional_);
124  return *this;
125  }
126 
130  const gd::String &GetDescription() const { return description; }
131 
136  description = description_;
137  return *this;
138  }
139 
144  bool IsCodeOnly() const { return codeOnly; }
145 
150  ParameterMetadata &SetCodeOnly(bool codeOnly_ = true) {
151  codeOnly = codeOnly_;
152  return *this;
153  }
154 
158  const gd::String &GetDefaultValue() const {
159  return valueTypeMetadata.GetDefaultValue();
160  }
161 
166  valueTypeMetadata.SetDefaultValue(defaultValue_);
167  return *this;
168  }
169 
173  const gd::String &GetLongDescription() const { return longDescription; }
174 
178  ParameterMetadata &SetLongDescription(const gd::String &longDescription_) {
179  longDescription = longDescription_;
180  return *this;
181  }
182 
183  // TODO Remove these deprecated functions.
184 
192  static bool IsObject(const gd::String &parameterType) {
193  return gd::ValueTypeMetadata::IsTypeObject(parameterType);
194  }
195 
202  static bool IsBehavior(const gd::String &parameterType) {
203  return gd::ValueTypeMetadata::IsTypeBehavior(parameterType);
204  }
205 
214  static bool IsExpression(const gd::String &type,
215  const gd::String &parameterType) {
216  return gd::ValueTypeMetadata::IsTypeExpression(type, parameterType);
217  }
218 
225  static const gd::String &GetExpressionValueType(const gd::String &parameterType) {
227  }
228 
232 
235  void SerializeTo(gd::SerializerElement &element) const;
236 
240  void UnserializeFrom(const gd::SerializerElement &element);
242 
243  // TODO: Deprecated public fields. Any direct usage should be moved to
244  // getter/setter.
245 
247  bool codeOnly;
249  private:
250  gd::ValueTypeMetadata valueTypeMetadata;
251  gd::String longDescription;
252  gd::String name;
254 };
255 
256 } // namespace gd
Describe a parameter of an instruction (action, condition) or of an expression: type,...
Definition: ParameterMetadata.h:27
ParameterMetadata & SetName(const gd::String &name_)
Set the name of the parameter.
Definition: ParameterMetadata.h:88
ParameterMetadata & SetDefaultValue(const gd::String &defaultValue_)
Set the default value, if the parameter is optional.
Definition: ParameterMetadata.h:165
ParameterMetadata & SetLongDescription(const gd::String &longDescription_)
Set the user friendly, long description for the parameter.
Definition: ParameterMetadata.h:178
ParameterMetadata & SetExtraInfo(const gd::String &supplementaryInformation_)
Set an optional additional information, used for some parameters with special type (for example,...
Definition: ParameterMetadata.h:107
const gd::ValueTypeMetadata & GetValueTypeMetadata() const
Return the metadata of the parameter type.
Definition: ParameterMetadata.h:46
ParameterMetadata & SetType(const gd::String &type_)
Set the type of the parameter.
Definition: ParameterMetadata.h:67
const gd::String & GetName() const
Return the name of the parameter.
Definition: ParameterMetadata.h:79
static bool IsExpression(const gd::String &type, const gd::String &parameterType)
Return true if the type of the parameter is an expression of the given type.
Definition: ParameterMetadata.h:214
bool IsOptional() const
Return true if the parameter is optional.
Definition: ParameterMetadata.h:116
ParameterMetadata & SetDescription(const gd::String &description_)
Set the description of the parameter.
Definition: ParameterMetadata.h:135
gd::ValueTypeMetadata & GetValueTypeMetadata()
Return the metadata of the parameter type.
Definition: ParameterMetadata.h:41
ParameterMetadata * Clone() const
Return a pointer to a new ParameterMetadata constructed from this one.
Definition: ParameterMetadata.h:36
static const gd::String & GetExpressionValueType(const gd::String &parameterType)
Return the expression type from the parameter type. Declinations of "number" and "string" types (like...
Definition: ParameterMetadata.h:225
ParameterMetadata & SetValueTypeMetadata(const gd::ValueTypeMetadata &valueTypeMetadata_)
Set the metadata of the parameter type.
Definition: ParameterMetadata.h:51
const gd::String & GetExtraInfo() const
Return an optional additional information, used for some parameters with special type (for example,...
Definition: ParameterMetadata.h:99
const gd::String & GetDescription() const
Return the description of the parameter.
Definition: ParameterMetadata.h:130
static bool IsObject(const gd::String &parameterType)
Return true if the type of the parameter is representing one object (or more, i.e: an object group).
Definition: ParameterMetadata.h:192
ParameterMetadata & SetOptional(bool optional_=true)
Set if the parameter is optional.
Definition: ParameterMetadata.h:122
gd::String description
Description shown in editor.
Definition: ParameterMetadata.h:246
bool codeOnly
Definition: ParameterMetadata.h:247
static bool IsBehavior(const gd::String &parameterType)
Return true if the type of the parameter is "behavior".
Definition: ParameterMetadata.h:202
const gd::String & GetLongDescription() const
Get the user friendly, long description for the parameter.
Definition: ParameterMetadata.h:173
bool IsCodeOnly() const
Return true if the parameter is only meant to be completed during compilation and must not be display...
Definition: ParameterMetadata.h:144
const gd::String & GetDefaultValue() const
Get the default value for the parameter.
Definition: ParameterMetadata.h:158
ParameterMetadata & SetCodeOnly(bool codeOnly_=true)
Set if the parameter is only meant to be completed during compilation and must not be displayed to th...
Definition: ParameterMetadata.h:150
const gd::String & GetType() const
Return the type of the parameter.
Definition: ParameterMetadata.h:61
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
Define a type for parameters of a function (action, condition or expression) or the returned value of...
Definition: ValueTypeMetadata.h:26
static bool IsTypeBehavior(const gd::String &parameterType)
Return true if the type is "behavior".
Definition: ValueTypeMetadata.h:183
static bool IsTypeExpression(const gd::String &type, const gd::String &parameterType)
Return true if the type is an expression of the given type from the caller point of view.
Definition: ValueTypeMetadata.h:195
static const gd::String & GetExpressionPrimitiveValueType(const gd::String &parameterType)
Return the expression type from the parameter type. Declinations of "number" and "string" types (like...
Definition: ValueTypeMetadata.cpp:41
static bool IsTypeObject(const gd::String &parameterType)
Return true if the type is representing one object (or more, i.e: an object group).
Definition: ValueTypeMetadata.h:173
Definition: CommonTools.h:24