Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
ScriptGlobalEntry.h
Go to the documentation of this file.
1#pragma once
2
4#include <misc/gen/Value.h>
5#include <misc/global.h>
6
7namespace sf
8{
9
14{
15 public:
19 static constexpr size_t unlimitedArgs = std::numeric_limits<int>::max();
20
27 ScriptGlobalEntry(const std::string& name, const std::string& description, int argumentCount);
28
34
39
44
48 [[nodiscard]] std::string getName() const
49 {
50 return _name;
51 }
52
56 void setDescription(const std::string& description)
57 {
58 _description = description;
59 }
60
64 [[nodiscard]] std::string getDescription() const
65 {
66 return _description;
67 }
68
74 [[nodiscard]] int getArgumentCount() const
75 {
76 return _argumentCount;
77 }
78
82 virtual void call(const Value::vector_type& arguments, Value& result) const = 0;
83
92 static bool call(const std::string& name, const Value::vector_type& arguments, Value& result);
93
99 static ScriptGlobalEntry* getEntry(const std::string& name);
100
101 protected:
105 std::string _name;
109 std::string _description;
113 int _argumentCount{0};
114};
115
121template<typename T>
123{
124 public:
125 typedef Value (T::*FunctionType)(const Value::vector_type&);
126
127 TScriptGlobalEntry(T* self, FunctionType func, const std::string& name, int argumentCount, const std::string& description)
128 : ScriptGlobalEntry(name, description, argumentCount)
129 , _self(self)
130 , _func(func)
131 {}
132
134
136
137 private:
138 void call(const Value::vector_type& arguments, Value& result) const override
139 {
140 result = _self->*_func(arguments);
141 }
142
143 T* _self;
144 FunctionType _func;
145};
146
151{
152 public:
153 typedef Value (*FunctionType)(const Value::vector_type& arguments);
154
155 ScriptGlobalStaticEntry(FunctionType func, const std::string& name, const std::string& description, int argumentCount)
156 : ScriptGlobalEntry(name, description, argumentCount)
157 , _func(func)
158 {}
159
161
163
164 private:
165 void call(const Value::vector_type& arguments, Value& result) const override
166 {
167 result = (*_func)(arguments);
168 }
169
170 FunctionType _func;
171};
172
173}// namespace sf
Pure virtual class to register script accessible entries through the use of sf::ScriptGlobalObject cl...
Definition ScriptGlobalEntry.h:14
static bool call(const std::string &name, const Value::vector_type &arguments, Value &result)
Finds the function with name 'name' and returns true when the function was found passing the correct ...
int getArgumentCount() const
Gets the amount of parameters that is needed for this function.
Definition ScriptGlobalEntry.h:74
ScriptGlobalEntry(const ScriptGlobalEntry &)=delete
Not allowed to copy.
ScriptGlobalEntry(const std::string &name, const std::string &description, int argumentCount)
Default Constructor adding itself to the global mapped entries.
virtual void call(const Value::vector_type &arguments, Value &result) const =0
Must be implemented to be able to call the function.
ScriptGlobalEntry & operator=(const ScriptGlobalEntry &)=delete
Not allowed to copy.
std::string getDescription() const
Gets the description of the entry.
Definition ScriptGlobalEntry.h:64
virtual ~ScriptGlobalEntry()
Destructor. Removes itself from the mapped entries.
std::string _description
Holds description of the entry.
Definition ScriptGlobalEntry.h:109
std::string getName() const
Gets the name of the entry.
Definition ScriptGlobalEntry.h:48
std::string _name
Holds the name of the entry.
Definition ScriptGlobalEntry.h:105
static ScriptGlobalEntry * getEntry(const std::string &name)
Gets the entry pointer by name.
void setDescription(const std::string &description)
Sets the description of the entry.
Definition ScriptGlobalEntry.h:56
sf::ScriptGlobalEntry derived class to link static functions or methods.
Definition ScriptGlobalEntry.h:151
ScriptGlobalStaticEntry(const ScriptGlobalStaticEntry &)=delete
Value(* FunctionType)(const Value::vector_type &arguments)
Definition ScriptGlobalEntry.h:153
ScriptGlobalStaticEntry & operator=(const ScriptGlobalStaticEntry &)=delete
ScriptGlobalStaticEntry(FunctionType func, const std::string &name, const std::string &description, int argumentCount)
Definition ScriptGlobalEntry.h:155
Template for creating a script global entry linking a dynamic created method.
Definition ScriptGlobalEntry.h:123
TScriptGlobalEntry(T *self, FunctionType func, const std::string &name, int argumentCount, const std::string &description)
Definition ScriptGlobalEntry.h:127
TScriptGlobalEntry & operator=(const TScriptGlobalEntry &)=delete
TScriptGlobalEntry(const TScriptGlobalEntry &)=delete
Value(T::* FunctionType)(const Value::vector_type &)
Definition ScriptGlobalEntry.h:125
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