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 {}
27 };
28
32 typedef std::string::size_type pos_type;
36 typedef ssize_t ip_type;
41 {
43 idUnknown = 0,
53 idKeyword
54 };
55
59 struct IdInfo
60 {
64 int _index{0};
68 EIdentifier _id{idUnknown};
72 const char* _name{nullptr};
77 int _paramCount{0};
81 void* _data{nullptr};
82 };
83
87 explicit ScriptObject(const char* type_name, ScriptObject* parent = nullptr);
88
92 virtual ~ScriptObject() = default;
93
97 [[nodiscard]] virtual const IdInfo* getInfo(const std::string& name) const = 0;
98
102 virtual std::string getStatusText();
106 virtual bool getSetValue(const IdInfo* info, Value* value, Value::vector_type* params, bool flag_set) = 0;
107
111 virtual void destroyObject(bool& should_delete) = 0;
112
116 [[nodiscard]] inline int getRefCount() const
117 {
118 return _refCount;
119 }
120
124 explicit operator Value() const;
125
129 static const IdInfo* getInfoUnknown();
130
134 [[nodiscard]] std::string getTypeName() const;
135
140 {
141 return _parent;
142 }
143
147 [[nodiscard]] inline const ScriptObject* getParent() const
148 {
149 return _parent;
150 }
151
156
157 protected:
165 void setParent(ScriptObject* parent);
166
167 private:
171 int _refCount{0};
175 const char* _typeName{nullptr};
179 ScriptObject* _parent{nullptr};
180
181 friend class ScriptInterpreter;
182
183 // Declarations of static functions and data members to be able to create implementations.
185};
186
187}// 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:36
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:41
@ idConstant
Definition ScriptObject.h:45
@ idTypedef
Definition ScriptObject.h:51
@ idFunction
Definition ScriptObject.h:49
@ idVariable
Definition ScriptObject.h:47
std::string::size_type pos_type
Source position type.
Definition ScriptObject.h:32
const ScriptObject * getParent() const
Gets the script object owner.
Definition ScriptObject.h:147
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:116
virtual ~ScriptObject()=default
Virtual destructor which can be overloaded to clean up objects.
ScriptObject * getParent()
Gets the script object owner.
Definition ScriptObject.h:139
std::string getTypeName() const
Returns the type name Set at the constructor.
Counted vector having additional methods and operators for ease of usage.
Definition TVector.h:25
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:60
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:25
Value::vector_type * _arguments
Definition ScriptObject.h:26