Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
ScriptObject.h
Go to the documentation of this file.
1#pragma once
2#include <cstring>
4#include <misc/gen/Value.h>
5#include <misc/global.h>
6
7namespace sf
8{
9
14{
15 public:
20 {
21 explicit Parameters(Value::vector_type* arguments, ScriptObject* parent = nullptr)
22 : _parent(parent)
23 , _arguments(arguments)
24 {}
25
28 };
29
33 typedef std::string::size_type pos_type;
37 typedef ssize_t ip_type;
38
43 {
45 idUnknown = 0,
55 idKeyword
56 };
57
61 struct IdInfo
62 {
66 int _index{0};
70 EIdentifier _id{idUnknown};
74 const char* _name{nullptr};
79 int _paramCount{0};
83 void* _data{nullptr};
84 };
85
89 explicit ScriptObject(const char* type_name, ScriptObject* parent = nullptr);
90
94 virtual ~ScriptObject() = default;
95
99 [[nodiscard]] virtual const IdInfo* getInfo(const std::string& name) const = 0;
100
104 virtual std::string getStatusText();
108 virtual bool getSetValue(const IdInfo* info, Value* value, Value::vector_type* params, bool flag_set) = 0;
109
113 virtual void destroyObject(bool& should_delete) = 0;
114
118 [[nodiscard]] inline int getRefCount() const
119 {
120 return _refCount;
121 }
122
126 explicit operator Value() const;
127
131 static const IdInfo* getInfoUnknown();
132
136 [[nodiscard]] std::string getTypeName() const;
137
142 {
143 return _parent;
144 }
145
149 [[nodiscard]] inline const ScriptObject* getParent() const
150 {
151 return _parent;
152 }
153
158
159 protected:
167 void setParent(ScriptObject* parent);
168
169 private:
173 int _refCount{0};
177 const char* _typeName{nullptr};
181 ScriptObject* _parent{nullptr};
182
183 friend class ScriptInterpreter;
184
185 // Declarations of static functions and data members to be able to create implementations.
187};
188
189}// namespace sf
#define SF_DECL_IFACE(InterfaceType, ParamType, FuncName)
Declares a public static function in the class where it is used. Where: InterfaceType: Global typenam...
Definition TClassRegistration.h:71
Script interpreter for running a loaded script.
Definition ScriptInterpreter.h:14
Info structure for objects used in scripts.
Definition ScriptObject.h:14
virtual const IdInfo * getInfo(const std::string &name) const =0
Must be overloaded for member namespace.
virtual void destroyObject(bool &should_delete)=0
Asks if the object should be deleted after having made this call.
ScriptObject * castToObject(const Value &value)
Casts a sf::Value::vitCustom typed sf::Value to a ScriptObject typed pointer.
void makeParent(ScriptObject *so)
Makes this object the owner of the other object.
ssize_t ip_type
Instruction pointer type.
Definition ScriptObject.h:37
ScriptObject(const char *type_name, ScriptObject *parent=nullptr)
virtual bool getSetValue(const IdInfo *info, Value *value, Value::vector_type *params, bool flag_set)=0
Gets or sets the passed data member. Must be overloaded in derived class.
void setParent(ScriptObject *parent)
Sets the owner to the pass script object.
EIdentifier
Keyword identifiers.
Definition ScriptObject.h:43
@ idConstant
Definition ScriptObject.h:47
@ idTypedef
Definition ScriptObject.h:53
@ idFunction
Definition ScriptObject.h:51
@ idVariable
Definition ScriptObject.h:49
std::string::size_type pos_type
Source position type.
Definition ScriptObject.h:33
const ScriptObject * getParent() const
Gets the script object owner.
Definition ScriptObject.h:149
virtual std::string getStatusText()
Gets the status text of this object for debugging purposes.
static const IdInfo * getInfoUnknown()
Returns the static Info structure for unknowns.
int getRefCount() const
Gets the reference count.
Definition ScriptObject.h:118
virtual ~ScriptObject()=default
Virtual destructor which can be overloaded to clean up objects.
ScriptObject * getParent()
Gets the script object owner.
Definition ScriptObject.h:141
std::string getTypeName() const
Returns the type name Set at the constructor.
Counted vector having additional methods and operators for ease of usage. This template class extends...
Definition TVector.h:20
Value container class able to performing arithmetic functions.
Definition Value.h:19
#define _MISC_CLASS
Definition misc/global.h:40
Definition Application.h:10
Used to create static lookup lists.
Definition ScriptObject.h:62
Type to pass to registered classes.
Definition ScriptObject.h:20
Parameters(Value::vector_type *arguments, ScriptObject *parent=nullptr)
Definition ScriptObject.h:21
ScriptObject * _parent
Definition ScriptObject.h:26
Value::vector_type * _arguments
Definition ScriptObject.h:27