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 std::string getName() const;
49
53 void setDescription(const std::string& description);
54
58 std::string getDescription() const;
59
64 int getArgumentCount() const;
65
69 virtual void call(const Value::vector_type& arguments, Value& result) const = 0;
70
79 static bool call(const std::string& name, const Value::vector_type& arguments, Value& result);
80
86 static ScriptGlobalEntry* getEntry(const std::string& name);
87
93 static string_list getEntryStringList(bool descriptive);
94
95 protected:
99 std::string _name;
103 std::string _description;
107 int _argumentCount{0};
108};
109
115template<typename T>
117{
118 public:
119 typedef Value (T::*FunctionType)(const Value::vector_type&);
120
121 TScriptGlobalEntry(T* self, FunctionType func, const std::string& name, int argumentCount, const std::string& description)
122 : ScriptGlobalEntry(name, description, argumentCount)
123 , _self(self)
124 , _func(func)
125 {}
126
128
130
131 private:
132 void call(const Value::vector_type& arguments, Value& result) const override;
133
134 T* _self;
135 FunctionType _func;
136};
137
138template<typename T>
139void TScriptGlobalEntry<T>::call(const Value::vector_type& arguments, Value& result) const
140{
141 result = _self->*_func(arguments);
142}
143
148{
149 public:
150 typedef Value (*FunctionType)(const Value::vector_type& arguments);
151
152 StaticScriptGlobalEntry(FunctionType func, const std::string& name, const std::string& description, int arg_count);
153
155
157
158 private:
159 void call(const Value::vector_type& arguments, Value& result) const override;
160
161 FunctionType _func;
162};
163
168{
169 public:
171
172 ScriptGlobalEntryClosure(const std::string& name, const std::string& description, int arg_count);
173
176
179
182
183 private:
185 void call(const Value::vector_type& arguments, Value& result) const override;
186};
187
188}// namespace sf
sf::ScriptGlobalEntry derived class to link static functions or methods using a closure.
Definition ScriptGlobalEntry.h:168
ScriptGlobalEntryClosure(const std::string &name, const std::string &description, int arg_count)
ClosureType onCall
Closure handling the call.
Definition ScriptGlobalEntry.h:181
ScriptGlobalEntryClosure(const StaticScriptGlobalEntry &)=delete
No copying allowed.
ScriptGlobalEntryClosure & operator=(const StaticScriptGlobalEntry &)=delete
No copying allowed.
TClosure< Value, const Value::vector_type & > ClosureType
Definition ScriptGlobalEntry.h:170
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.
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.
virtual ~ScriptGlobalEntry()
Destructor. Removes itself from the mapped entries.
std::string _description
Holds description of the entry.
Definition ScriptGlobalEntry.h:103
static string_list getEntryStringList(bool descriptive)
Gets a string list containing all available global script functions.
std::string getName() const
Gets the name of the entry.
std::string _name
Holds the name of the entry.
Definition ScriptGlobalEntry.h:99
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.
sf::ScriptGlobalEntry derived class to link static functions or methods.
Definition ScriptGlobalEntry.h:148
StaticScriptGlobalEntry(FunctionType func, const std::string &name, const std::string &description, int arg_count)
StaticScriptGlobalEntry & operator=(const StaticScriptGlobalEntry &)=delete
StaticScriptGlobalEntry(const StaticScriptGlobalEntry &)=delete
Encapsulates the std::function() template.
Definition TClosure.h:14
Template for creating a script global entry linking a dynamic created method.
Definition ScriptGlobalEntry.h:117
TScriptGlobalEntry(T *self, FunctionType func, const std::string &name, int argumentCount, const std::string &description)
Definition ScriptGlobalEntry.h:121
TScriptGlobalEntry & operator=(const TScriptGlobalEntry &)=delete
TScriptGlobalEntry(const TScriptGlobalEntry &)=delete
Value(T::* FunctionType)(const Value::vector_type &)
Definition ScriptGlobalEntry.h:119
Counted vector having additional methods and operators for ease of usage. This template class extends...
Definition TVector.h:19
Value container class able to performing arithmetic functions.
Definition Value.h:19
#define _MISC_CLASS
Definition misc/global.h:40
Definition Application.h:10
TStrings< std::string > string_list
Vector of std::strings with additional functionality.
Definition TStrings.h:97