 |
Gorgon Game Engine
|
Go to the documentation of this file.
10 #include "../Scripting.h"
11 #include "../Utils/Assert.h"
27 using ParseFn = T_(*)(
const std::string &);
35 T_
ParseThrow(
const std::string &) {
throw std::runtime_error(
"This type cannot be parsed."); }
39 StringFromFn<T_> ToString_=String::From<T_>,
40 ParseFn<T_> Parse_=String::To<T_>
42 class MappedValueType;
46 StringFromFn<T_> ToString_=&String::From<T_>,
47 ParseFn<T_*> Parse_=&ParseThrow<T_*>
49 class MappedReferenceType;
56 using traits = TMP::FunctionTraits<F_>;
84 struct extractvector {
85 enum { isvector =
false };
90 template<
template<
class,
class>
class V_,
class T_,
class A_>
91 struct extractvector<V_<T_, A_>> {
92 enum { isvector = std::is_same<V_<T_, A_>, std::vector<T_, A_>>::value };
97 template<
template<
class,
class>
class V_,
class T_,
class A_>
98 struct extractvector<const V_<T_, A_>&> {
99 enum { isvector = std::is_same<V_<T_, A_>, std::vector<T_, A_>>::value };
106 struct is_nontmpref {
109 !std::is_copy_constructible<typename std::remove_const<typename std::remove_reference<T_>::type>::type>::value ||
110 (std::is_reference<T_>::value && !std::is_const<typename std::remove_reference<T_>::type>::value) };
115 struct is_nonconstref {
117 value = (std::is_reference<T_>::value && !std::is_const<typename std::remove_reference<T_>::type>::value)
122 inline typename std::enable_if<
123 is_nontmpref<T_>::value && std::is_const<typename std::remove_reference<T_>::type>::value,
125 >::type castto(
const Data &d)
const {
126 using regtype=
typename std::remove_reference<T_>::type;
128 return d.ReferenceValue<T_>();
131 return d.ReferenceValue<
typename std::remove_const<regtype>::type &>();
136 inline typename std::enable_if<
137 is_nontmpref<T_>::value && !std::is_const<typename std::remove_reference<T_>::type>::value,
139 >::type castto(
const Data &d)
const {
140 using regtype=
typename std::remove_reference<T_>::type;
142 ASSERT(!d.IsConstant(),
"Constant data is being submitted to non-const reference");
143 return d.ReferenceValue<T_>();
147 inline typename std::enable_if<!is_nontmpref<T_>::value && std::is_pointer<T_>::value, T_>::type castto(
const Data &d)
const {
148 bool isconst=std::is_const<typename std::remove_pointer<T_>::type>::value;
150 if(isconst && !d.IsConstant()) {
151 return d.GetValue<
typename std::remove_const<typename std::remove_pointer<T_>::type>::type *>();
154 return d.GetValue<T_>();
159 inline typename std::enable_if<!is_nontmpref<T_>::value && !std::is_pointer<T_>::value, T_>::type castto(
const Data &d)
const {
160 bool isref=
false, isconst=
false;
161 if(std::is_reference<T_>::value) {
163 isconst=std::is_const<typename std::remove_reference<T_>::type>::value;
166 isconst=std::is_const<T_>::value;
169 if(isconst && !d.IsConstant()) {
171 return d.GetValue<
typename std::remove_const<typename std::remove_reference<T_>::type>::type &>();
174 return d.GetValue<
typename std::remove_const<T_>::type>();
178 return d.GetValue<T_>();
183 typename std::enable_if<!extractvector<param<P_>>::isvector, param<P_>>::type
184 accumulatevector(
const std::vector<Data> &
parameters)
const {
189 typename std::enable_if<extractvector<param<P_>>::isvector,
190 typename std::remove_const<typename std::remove_reference<param<P_>>::type>::type>::type
191 accumulatevector(
const std::vector<Data> &
parameters)
const {
192 typename std::remove_const<typename std::remove_reference<param<P_>>::type>::type v;
193 for(
unsigned i=P_; i<
parameters.size(); i++) {
194 v.push_back(castto<
typename extractvector<param<P_>>::inner>(
parameters[i]));
201 inline typename TMP::Choose<
202 is_nontmpref<param<P_>>::value && !extractvector<param<P_>>::isvector,
203 std::reference_wrapper<typename std::remove_reference<param<P_>>::type>,
204 typename TMP::Choose<extractvector<param<P_>>::isvector,
205 typename std::remove_const<typename std::remove_reference<param<P_>>::type>::type,
209 bool b=is_nontmpref<param<P_>>::value;
211 ASSERT(extractvector<param<P_>>::isvector,
"Repeating parameter should be a vector");
221 template<
class R_,
int ...S_>
222 typename std::enable_if<!std::is_same<R_, void>::value && !std::is_reference<R_>::value && !std::is_pointer<R_>::value,
Data>::type
223 callfn(TMP::Sequence<S_...>,
const std::vector<Data> &
parameters)
const {
233 "Embedded function does not return a reference");
236 if(!data.GetValue<
Data>().IsReference()) {
237 throw CastException(
"Non-reference variant",
"Reference variant",
"While returning value from "+
parent->
GetName());
244 template<
class R_,
int ...S_>
245 typename std::enable_if<!std::is_same<R_, void>::value && std::is_reference<R_>::value && !std::is_pointer<R_>::value,
Data>::type
246 callfn(TMP::Sequence<S_...>,
const std::vector<Data> &
parameters)
const {
260 template<
class R_,
int ...S_>
261 typename std::enable_if<!std::is_same<R_, void>::value && std::is_pointer<R_>::value,
Data>::type
262 callfn(TMP::Sequence<S_...>,
const std::vector<Data> &
parameters)
const {
276 template<
class R_,
int ...S_>
277 typename std::enable_if<std::is_same<R_, void>::value,
Data>::type
278 callfn(TMP::Sequence<S_...>,
const std::vector<Data> &
parameters)
const {
287 TMP::AbstractRTTC<typename std::remove_pointer<T>::type> rtt;
293 if(is_nonconstref<T>::value || (std::is_pointer<T>::value && !std::is_const<
typename std::remove_pointer<T>::type>::value)) {
295 if(P_==0 && ismember) {
299 "This function variant is marked as const, yet its implementation requires non-const "
300 "pointer or reference\n"
310 "Repeating parameter vectors cannot be non-const references"
315 ASSERT(param.IsReference(),
316 "Parameter #"+
String::From(P_-ismember)+
" is not declared as reference, "
317 "yet its implementation is\n"
322 ASSERT(!param.IsConstant(),
323 "Parameter #"+
String::From(P_-ismember)+
" is declared as constant, "
324 "yet its implementation is not const\n"
328 if(is_nonconstref<T>::value) {
329 ASSERT(!param.AllowsNull(),
330 "Parameter #"+
String::From(P_-ismember)+
" is a reference "
331 "and its implementation allows nullptr. This may cause crashes\n"
338 else if(std::is_pointer<T>::value) {
340 if(P_==0 && ismember) {
344 std::cout<<
"This function variant is not marked as const, yet its implementation requires const "
356 "Repeating parameter vectors cannot be a pointer"
360 ASSERT(param.IsReference(),
361 "Parameter #"+(
String::From(P_-ismember+1)+
", "+param.GetName())+
" is not declared as reference, "
362 "yet its implementation is\n"
368 if(!param.IsConstant()) {
369 std::cout<<
"Parameter #"+(
String::From(P_-ismember+1)+
", "+param.GetName())+
" is not marked as const, "
370 "yet its implementation requires const pointer\n"
376 else if(std::is_reference<T>::value) {
377 if(!ismember || P_!=0) {
381 if(param.IsReference()) {
383 ASSERT(!param.AllowsNull(),
384 "Parameter #"+
String::From(P_-ismember)+
" is a reference "
385 "and its implementation allows nullptr. This may cause crashes\n"
391 else if(std::is_const<T>::value) {
393 if(P_==0 && ismember) {
397 "This function variant is marked as a non-const member function, "
398 "yet its implementation requests a constant value which cannot modify the this pointer.\n"
407 ASSERT(!param.IsReference(),
408 "Parameter #"+(
String::From(P_-ismember+1)+
", "+param.GetName())+
" is declared as reference "
409 "yet its implementation not\n"
415 if(!param.IsConstant()) {
416 std::cout<<
"Parameter #"+(
String::From(P_-ismember+1)+
", "+param.GetName())+
" is not marked as const, yet its implementation requires const "
427 if(P_==0 && ismember) {
431 "This function variant is marked as a non-const member function, "
432 "yet its implementation requests a value which cannot modify the this pointer.\n"
442 ASSERT(!param.IsReference() || param.GetType()==Types::Variant(),
443 "Parameter #"+(
String::From(P_-ismember+1)+
", "+param.GetName())+
" is declared as reference, "
444 "yet its implementation not\n"
449 ASSERT(!param.IsConstant(),
450 "Parameter #"+(
String::From(P_-ismember+1)+
", "+param.GetName())+
" is declared as constant, "
451 "yet its implementation is not const\n"
462 if(P_==0 && ismember) {
467 "parameter #"+
String::From(P_-ismember+1)+
" does not match with the function type ("+
468 rtt.NormalType.Name()+
")\n"+
477 if(param.IsConstant()) {
478 if(param.IsReference()) {
479 typeinf=¶m.GetType().TypeInterface.ConstPtrType;
482 typeinf=¶m.GetType().TypeInterface.ConstType;
486 if(param.IsReference()) {
487 typeinf=¶m.GetType().TypeInterface.PtrType;
490 typeinf=¶m.GetType().TypeInterface.NormalType;
495 (TMP::RTT<
typename extractvector<T>::inner>()==*typeinf),
496 "The declared type ("+typeinf->Name()+
") of "
497 "parameter #"+
String::From(P_-ismember+1)+
" does not match with the function type ("+
498 rtt.NormalType.Name()+
")\n"+
507 rtt.NormalType==param.GetType().TypeInterface.NormalType,
508 "The declared type ("+param.GetType().GetName()+
", "+param.GetType().TypeInterface.NormalType.Name()+
") of "
509 "parameter #"+(
String::From(P_-ismember+1)+
", "+param.GetName())+
" does not match with the function type ("+
510 rtt.NormalType.Name()+
")\n"
517 void check(TMP::Sequence<S_...>) {
518 char dummy[] = {0, (checkparam<S_>(),
'\0')...};
521 virtual void dochecks(
bool ismethod)
override {
532 if(std::is_same<typename traits::ReturnType, void>::value) {
536 "This function variant expects a return type of "+
544 "Return type is marked as void. Supplied function's return type is :"+
545 Utils::GetTypeName<typename traits::ReturnType>()+
549 TMP::AbstractRTT<typename traits::ReturnType> returnrtt;
563 "with its implementation ("+returnrtt.Name()+
")"
574 "with its implementation ("+returnrtt.Name()+
")"
589 "with its implementation ("+returnrtt.Name()+
")"
600 "with its implementation ("+returnrtt.Name()+
")"
613 template<
class F_,
class ...P_>
618 template<
class F_,
class ...P_>
620 bool accessible,
bool constant,
bool returnsref,
bool returnsconst,
bool implicit) {
621 return new MappedFunction<F_>(fn, returntype, std::move(parameters), stretchlast, repeatlast, accessible,
622 constant, returnsref, returnsconst, implicit);
625 template<
class F_,
class ...P_>
640 const Type *returntype,
const Type *rhs, F_ fn) :
642 ASSERT(returntype,
"Operators should have a return type", 1, 1);
643 ASSERT(parent,
"Operators should belong a class", 1, 1);
656 std::initializer_list<Function::Overload *> overloads) :
659 for(
auto overload : overloads) {
660 ASSERT(overload->HasReturnType(),
"Operators should have a return type", 1, 1);
661 ASSERT(overload->IsConstant(),
"Operators should be constant functions", 1, 1);
662 ASSERT(overload->Parameters.size()==1,
"Operators should have a single parameter", 1, 1);
672 ASSERT(returntype,
"Operators should have a return type", 1, 1);
678 "Right hand side of the operator", rhs
692 #define MAP_COMPARE(opname, op, mappedtype, cpptype) \
693 new MappedOperator( #opname, \
694 "Compares two "#mappedtype" types.", mappedtype, \
695 Types::Bool(), mappedtype, [](cpptype l, cpptype r) { return l op r; } \
701 template<
class from_,
class to_>
730 template<
class from_,
class to_>
735 return dynamic_cast<to_&
>(val);
746 return dynamic_cast<to_&
>(val);
758 template<
class from_,
class to_>
763 return dynamic_cast<to_&
>(val);
774 return dynamic_cast<to_&
>(val);
786 template<
class from_,
class to_>
790 [](
const from_ &val) {
791 return static_cast<const to_&
>(val);
801 [](
const from_ &val) {
802 return static_cast<const to_&
>(val);
814 template<
class from_,
class to_>
818 [](
const from_ &val) {
819 return static_cast<const to_&
>(val);
829 [](
const from_ &val) {
830 return static_cast<const to_&
>(val);
843 template<
class C_,
class T_>
846 using normaltype =
typename std::remove_const<typename std::remove_pointer<T_>::type>
::type;
847 using classptr =
typename std::remove_pointer<C_>::type *;
848 using classbase =
typename std::remove_pointer<C_>::type;
851 istypeconst = std::is_const<typename std::remove_pointer<T_>::type>::value,
861 " does not match with c++ type: "+Utils::GetTypeName<normaltype>(), 1, 2);
865 template<
class T2_=T_>
866 static typename std::enable_if<istypeptr, typename std::remove_pointer<T2_>::type>
::type deref(
const T2_ val) {
870 template<
class T2_=T_>
871 static typename std::enable_if<!istypeptr, typename std::remove_pointer<T2_>::type>
::type deref(
const T2_ val) {
875 template<
class T2_=T_>
876 static typename std::enable_if<istypeptr, T2_>::type
toptr(T2_ val) {
880 template<
class T2_=T_>
881 static typename std::enable_if<!istypeptr, T2_*>::type
toptr(T2_ &val) {
885 template<
class C2_=C_>
886 static typename std::enable_if<std::is_pointer<C2_>::value,
const C2_>
::type clstoptr(
const C2_ val) {
890 template<
class C2_=C_>
891 static typename std::enable_if<!std::is_pointer<C2_>::value,
const C2_*>
::type clstoptr(
const C2_ &val) {
895 template<
class T2_=T_>
900 template<
class T2_=T_>
917 "The type of the parent does not match with the type "
918 "it has placed in.", 2, 2);
950 template<
class C_,
class T_>
952 using classbase =
typename std::remove_pointer<C_>::type;
959 ASSERT(std::is_pointer<T_>::value,
"Member "+
name+
" marked as reference but its source is not, should be a pointer");
962 ASSERT(!
constant || ref,
"Non-reference constant instance members becomes readonly, choose a readonly embedder for "+
name);
967 using classptr =
typename std::remove_pointer<C_>::type *;
969 template<
class T2_=T_>
970 typename std::enable_if<std::is_pointer<T2_>::value,
typename std::remove_pointer<T2_>::type>
::type &
getref(T2_ value)
const {
974 template<
class T2_=T_>
975 typename std::enable_if<!std::is_pointer<T2_>::value, T2_>
::type &
getref(T2_ &value)
const {
981 throw ConstantException(
"Given item");
984 if(value.
IsConstant() && this->reference && !this->constant) {
985 throw ConstantException(
"Value for "+this->
name,
"Given value for "+this->
name+
" is constant");
1027 source={source.
GetType(), obj};
1049 ASSERT(
type,
"Type cannot be nullptr", 1, 2);
1054 "Instance member implies that it could be changed, yet its implementation does not allow "
1055 "such use. For instance member "+
name);
1058 "Instance member is a reference, yet its implementation is not."
1059 "For instance member "+
name);
1124 template <
class F1_,
class F2_>
1126 const Type *
type,
const Type *
parent,
bool isconstfn,
bool isreffn,
bool ref,
bool isgetconst,
bool issetconst=
false) :
1132 },
false,
false,
true,
false,
false,
false, false
1148 const Type *membertype,
const Type *parenttype) {
1163 bool isconstant,
bool ref,
bool readonly) :
1166 ASSERT(
type,
"Type cannot be nullptr", 1, 2);
1169 template<
class T2_=T_>
1174 template<
class T2_=T_>
1184 bool isconstant=
false) :
1244 bool constant=
false,
bool ref=
false) :
1248 ASSERT(std::is_pointer<T_>::value,
"Member "+
name+
" marked as reference but its source is not, should be a pointer");
1251 ASSERT(!
constant || ref,
"Non-reference constant instance members becomes readonly, choose a readonly embedder for "+
name);
1256 template<
class T2_=T_>
1257 typename std::enable_if<std::is_pointer<T2_>::value,
typename std::remove_pointer<T2_>::type>
::type &
getref() {
1258 return *(this->
value);
1261 template<
class T2_=T_>
1262 typename std::enable_if<!std::is_pointer<T2_>::value, T2_>
::type &
getref() {
1268 if(
value.IsConstant() && this->reference && !this->constant) {
1269 throw ConstantException(
"Value for "+this->
name,
"Given value for "+this->
name+
" is constant");
1274 this->value =
value.ReferenceValue<T_>();
1277 this->value =
value.ReferenceValue<
const T_>();
1281 if(
value.IsConstant()) {
1297 StringFromFn<T_> ToString_,
1303 Type(name, help, def, new TMP::AbstractRTTC<T_>(), false)
1311 template<
class ...P_>
1313 ASSERT(
sizeof...(P_)==params.size(),
"Number of parameters does not match");
1328 return ToString_(data.
GetValue<T_>());
1333 return Data(
this, Parse_(str));
1343 throw ConstantException(
"");
1375 typename std::enable_if<std::is_copy_constructible<O_>::value,
void>::type
1385 Parameter(
"value",
"The value to be copied",
this)
1391 typename std::enable_if<!std::is_copy_constructible<O_>::value,
void>::type
1403 std::string(*ToString_)(
const T_ &),
1404 T_*(*Parse_)(
const std::string &)
1409 Type(name, help, def, new TMP::AbstractRTTC<T_>(), true)
1431 template<
class ...P_>
1433 ASSERT(
sizeof...(P_)==params.size(),
"Number of parameters does not match");
1437 auto obj=new T_(args...);
1438 VirtualMachine::Get().References.Register(obj);
1450 return Data(
this, Parse_(str));
1472 typename std::enable_if<std::is_copy_constructible<O_>::value,
void>::type
1478 auto obj=
new T_(*o);
1491 typename std::enable_if<!std::is_copy_constructible<O_>::value,
void>::type
1501 struct InternalReferenceType {
1506 Type *InternalReferenceType<T_>::type =
new MappedReferenceType<T_, &ToEmptyString<T_>>(
"",
"");
1511 struct InternalValueType {
1516 Type *InternalValueType<T_>::type =
new MappedValueType<T_>(
"",
"");
1519 struct ExtractFromHelper {
1520 R_ operator()(
const Data &d)
const {
1521 return d.GetValue<R_>();
1526 struct ExtractFromHelper<R_*> {
1527 R_ *operator()(
const Data &d)
const {
1528 return d.ReferenceValue<R_*>();
1533 struct ExtractFromHelper<R_&> {
1534 R_ &operator()(
const Data &d)
const {
1535 return d.ReferenceValue<R_&>();
1540 struct ExtractFromHelper<void> {
1541 void operator()(
const Data &d)
const {
1542 ASSERT(!d.IsValid(),
"There is valid data in even though there shouldn't be.");
1547 R_ ExtractFromData(
const Data &d) {
1548 ExtractFromHelper<R_> h;
1560 template <
class E_,
class O_,
class R_,
class ...P_>
1563 using TokenType = decltype(std::declval<E_>().Register(std::function<
void()>()));
1568 template<
class T_,
class ...Params_>
1569 void constargs(
int index, std::vector<Data> &ret,
const std::vector<Parameter> params, T_ arg, Params_&& ...rest) {
1570 auto param=params[index];
1571 ret.push_back(
Data(param.GetType(), arg, param.IsReference(), param.IsConstant()));
1572 constargs(index+1, ret, params, std::forward(rest)...);
1575 void constargs(
int index, std::vector<Data> &ret,
const std::vector<Parameter> params) {}
1577 R_ callfn(
const Scripting::Function *fn, std::vector<Data> args, Function::Overload *single) {
1578 using namespace Scripting;
1583 if(!single || single->Parameters.size()==args.size()-(fn->
IsMember()&&!fn->
IsStatic())) {
1585 return ExtractFromData<R_>(vm.ExecuteFunction(fn, args,
false));
1587 catch(SymbolNotFoundException &) {
1592 return ExtractFromData<R_>(vm.ExecuteFunction(fn, {},
false));
1596 template<
class OO_=O_>
1597 typename std::enable_if<!std::is_same<OO_, void>::value, R_>::type
1598 callfn(O_& obj,
const Scripting::Function *fn, std::vector<Data> args, Function::Overload *single) {
1602 if(this->parenttype && (!single || single->Parameters.size()==args.size()+1-(fn->IsMember()&&!fn->IsStatic()))) {
1603 args.insert(args.begin(),
Data(this->parenttype, &obj,
true, std::is_const<O_>::value));
1606 return ExtractFromData<R_>(vm.ExecuteFunction(fn, args,
false));
1608 catch(SymbolNotFoundException &) {
1609 args.erase(args.begin());
1614 return callfn(fn, args, single);
1617 template<
class OO_=O_>
1618 typename std::enable_if<std::is_same<OO_, void>::value,
TokenType>::type
1622 for(
auto &ovs : {&fn->Overloads, &fn->Methods}) {
1623 for(
auto &ov : *ovs) {
1624 if(ov.Parameters.size()==
sizeof...(P_) || ov.Parameters.size()==0) {
1632 if(!found)
throw ParameterError(
"No matching overload for the event is found.");
1635 vm.References.Increase((
void*)fn);
1637 auto tok=ev->Register([fn,
this](P_&& ...args) {
1639 std::vector<Data> pars;
1640 constargs(0, pars,
parameters, std::forward<P_...>(args)...);
1643 Function::Overload *overload=
nullptr;
1644 if(fn->Overloads.GetSize()+fn->Methods.GetSize()) {
1645 if(fn->Overloads.GetSize())
1646 overload=&fn->Overloads[0];
1648 overload=&fn->Methods[0];
1651 return callfn(fn, pars, overload);
1659 template<
class OO_=O_>
1660 typename std::enable_if<!std::is_same<OO_, void>::value,
TokenType>::type
1662 using namespace Scripting;
1665 for(
auto &ovs : {&fn->Overloads, &fn->Methods}) {
1666 for(
auto &ov : *ovs) {
1667 if(ov.Parameters.size()==
sizeof...(P_) || ov.Parameters.size()==
sizeof...(P_)+1 || ov.Parameters.size()==0) {
1675 if(!found)
throw ParameterError(
"No matching overload for the event is found.");
1679 vm.References.Increase((
void*)fn);
1681 auto tok=ev->Register([fn,
this](O_ &obj, P_&& ...args) {
1683 std::vector<Data> pars;
1684 constargs(0, pars,
parameters, std::forward<P_...>(args)...);
1687 Function::Overload *overload=
nullptr;
1688 if(fn->Overloads.GetSize()+fn->Methods.GetSize()) {
1689 if(fn->Overloads.GetSize())
1690 overload=&fn->Overloads[0];
1692 overload=&fn->Methods[0];
1695 return callfn(obj, fn, pars, overload);
1720 "Registers a new handler to this event",
1724 return this->registerfn(ev,fn);
1726 InternalValueType<TokenType>::type, {
1728 "The function to handle the event",
1737 "This function unregisters a given event handler token.",
1741 event->Unregister(token);
1743 vm.References.Decrease(
Data(
Types::Function(), this->unregistertokens[token],
true,
true));
1744 this->unregistertokens.erase(token);
1748 "Event handler token",
1749 InternalValueType<TokenType>::type
1761 return "Event object";
1765 throw std::runtime_error(
"Events cannot be parsed from a string");
1772 throw Scripting::ConstantException(
"Given data");
1779 const Type *parenttype;
1791 const std::vector<std::pair<std::string, std::string>> &strings, E_ defval=E_(),
bool binary=
false) :
1793 for(
auto &s : strings) {
1794 this->add({s.first, s.second, String::Parse<E_>(s.first)});
1800 [](E_ e) {
return e; },
this,
1801 {
Parameter(
"value",
"The value to be copied",
this) }
1804 [defval]() {
return defval; },
this,
1816 [](E_ e) -> std::string {
1817 unsigned val=(unsigned)e;
1818 unsigned digits=int(std::log2((
double)val)+1);
1819 std::string ret(
' ', digits);
1820 for(
unsigned i=0;i<digits;i++) {
1821 ret[digits-i-1]=val&1 ?
'1':
'0';
1829 [](E_ e,
unsigned digits) -> std::string {
1830 unsigned val=(unsigned)e;
1831 std::string ret(
' ', digits);
1832 for(
unsigned i=0;i<digits;i++) {
1833 ret[digits-i-1]=val&1 ?
'1':
'0';
1838 }, Types::String(), {
1839 Parameter(
"digits",
"Number of digits to be considered", Types::Unsigned())
1847 [](E_ l, E_ r) -> E_ {
1848 return (E_)((unsigned)l|(
unsigned)r);
1859 for (E_ e : Gorgon::Enumerate<E_>()) {
1869 return {
this, String::Parse<E_>(s)};
1879 throw ConstantException(
"");
1911 template<
class T_,
class I_>
1913 ASSERT(type && inherited,
"Inheritance types cannot be nullptr");
1919 return Data(*type,
dynamic_cast<const T_*
>(d.
ReferenceValue<
const I_*>()),
true,
true);
1925 return Data(*inherited,
dynamic_cast<const I_*
>(d.
ReferenceValue<
const T_*>()),
true,
true);
This class allows mapping of a data member to c++ function data member.
Definition: Embedding.h:1108
virtual void dochecks(bool ismethod)
This function should perform validity checks on the variant.
Definition: Reflection.cpp:295
const Type & GetType() const
Returns the type of this data member.
Definition: Reflection.h:1003
virtual void deleteobject(const Data &obj) const override
Definition: Embedding.h:1457
T_ value
Definition: Embedding.h:1234
MappedROStaticDataMember(T_ value, const std::string &name, const std::string &help, const Type *type, bool isconstant, bool ref, bool readonly)
Definition: Embedding.h:1162
virtual void AddOverload(Overload &overload)
Adds the given overload to this function after performing necessary checks.
Definition: Reflection.h:881
Scripting::Function::Overload * MapDynamiccast(Type *from, Type *to, bool implicit=true)
Maps a constructor for type casting, works for polymorphic types.
Definition: Embedding.h:731
std::map< TokenType, const Scripting::Function * > unregistertokens
Definition: Embedding.h:1564
T_ & GetValue()
Returns the value stored in this data.
Definition: Embedding.h:1197
Scripting::Function::Overload * MapStaticcast(Type *from, Type *to, bool implicit=true)
Maps a constructor for type casting, works for reference types.
Definition: Embedding.h:787
std::enable_if< decltype(gorgon__enum_tr_loc(T_()))::isupgradedenum, std::string >::type From(const T_ &e)
Definition: Enum.h:303
RTTS & RefType
Definition: TMP.h:375
constexpr Type Data
Data resource.
Definition: GID.h:164
MappedValueType(const std::string &name, const std::string &help)
Definition: Embedding.h:1308
std::enable_if< std::is_pointer< T2_ >::value, typename std::remove_pointer< T2_ >::type >::type & getref(T2_ value) const
Definition: Embedding.h:970
RTTS & ConstPtrType
Definition: TMP.h:375
virtual void set(Data &source, Data &value) const override
This function should perform set operation.
Definition: Embedding.h:979
MappedROInstanceMember_Function(F_ reader, const std::string &name, const std::string &help, const Type *type, const Type *parent, bool isconstfn, bool isreffn, bool constant=false)
Constructs a new MappedROInstanceMember_Function.
Definition: Embedding.h:1080
bool compare(const Data &l, const Data &r) const override
Definition: Embedding.h:1370
std::enable_if< std::is_copy_constructible< O_ >::value, void >::type addcopyconst()
Definition: Embedding.h:1376
virtual void set(Data &value) const override
Definition: Embedding.h:1266
@ OperatorTag
Makes a function operator.
Definition: Reflection.h:92
virtual ~MappedROInstanceMember_Function()
Definition: Embedding.h:1085
void MapConstructor(ParameterList params)
Definition: Embedding.h:1312
void Register(const Data &data)
Registers a new object of reference counting, this will set reference count to one.
Definition: Runtime.h:24
virtual void AddMembers(std::initializer_list< StaticMember * > newmembers) override
Adds a list of static members to this type.
Definition: Reflection.h:1228
std::enable_if< std::is_pointer< T_ >::value, T_ >::type ReferenceValue() const
Returns the value of this data in the requested format.
Definition: Data.h:112
virtual ~MappedROStaticDataMember()
Definition: Embedding.h:1189
TMP::RTTH & TypeInterface
Type interface used for this type.
Definition: Reflection.h:1414
This class can hold any other information providing type erasure.
Definition: Any.h:32
void AddOverload(F_ fn, const Type *returntype, const Type *rhs)
Adds a new operator overload.
Definition: Embedding.h:671
bool IsConstant() const
Returns whether this function is a constant.
Definition: Reflection.h:635
ReferenceCounter References
This system allows objects of automatic lifetime.
Definition: VirtualMachine.h:222
void MapConstructor(ParameterList params)
Definition: Embedding.h:1432
ParameterList parameters
Parameters that every event handler should accept.
Definition: Reflection.h:1530
bool reference
This instance member is a reference.
Definition: Reflection.h:503
virtual void deleteobject(const Data &obj) const override
This function should delete the given object.
Definition: Embedding.h:1894
std::enable_if<!std::is_pointer< T_ >::value, const typename std::remove_reference< T_ >::type & >::type GetValue() const
Returns the value of this data in the requested format.
Definition: Data.h:57
const Type * returntype
Return type of this function variant. If nullptr this function does not return a value.
Definition: Reflection.h:739
std::enable_if<!std::is_copy_constructible< O_ >::value, void >::type addcopyconst()
Definition: Embedding.h:1492
typename std::remove_const< typename std::remove_pointer< T_ >::type >::type normaltype
Definition: Embedding.h:846
decltype(std::declval< E_ >().Register(std::function< void()>())) TokenType
Definition: Embedding.h:1563
Data describes a piece of data.
Definition: Data.h:22
static std::enable_if< std::is_pointer< C2_ >::value, const C2_ >::type clstoptr(const C2_ val)
Definition: Embedding.h:886
Definition: Embedding.h:1153
T_ GetValue() const
Returns the value stored in this data.
Definition: Embedding.h:1192
virtual void typecheck(const Type *type) const override
Type checks the parent.
Definition: Embedding.h:1088
bool readonly
Marks this instance as read-only.
Definition: Reflection.h:506
MappedEventType(const std::string &name, const std::string &help, const ParameterList ¶meters={}, const Type *parenttype=nullptr, const Type *ret=nullptr)
Definition: Embedding.h:1705
std::vector< Parameter > ParameterList
Definition: Reflection.h:308
const Type & GetOwner() const
If this function is a member function, returns the owner object.
Definition: Reflection.h:874
R_: return type, P_: parameters, E_: event object type.
Definition: Embedding.h:1561
MappedStringEnum(const std::string &name, const std::string &help, const std::vector< std::pair< std::string, std::string >> &strings, E_ defval=E_(), bool binary=false)
strings parameter should contain, name and help of enum entries.
Definition: Embedding.h:1790
virtual bool compare(const Data &l, const Data &r) const
This function should compare two instances of the type.
Definition: Embedding.h:1890
bool constant
This instance member is a constant.
Definition: Reflection.h:500
MappedReferenceType(const std::string &name, const std::string &help)
Definition: Embedding.h:1414
virtual void deleteobject(const Gorgon::Scripting::Data &data) const override
This function should delete the given object.
Definition: Embedding.h:1770
virtual ~MappedROInstanceMember()
Definition: Embedding.h:912
bool IsMember() const
Returns if this function is a member function of a type.
Definition: Reflection.h:863
static VirtualMachine & Get()
Returns the current VM for this thread.
Definition: VirtualMachine.h:109
const Member * parent
Definition: Reflection.h:358
void AddInheritance(const Type &type, Inheritance::ConversionFunction from, Inheritance::ConversionFunction to)
Adds an inheritance parent.
Definition: Reflection.cpp:257
bool IsReferenceType() const
Returns whether this type is a reference type.
Definition: Reflection.h:1327
void AddConstructors(std::initializer_list< Function::Overload * > elements)
Adds the given constructors.
Definition: Reflection.h:1298
Scripting::Function::Overload * readerfn
Definition: Embedding.h:1042
InstanceMember * MapFunctionToInstanceMember(F_ reader, const std::string &name, const std::string &help, const Type *membertype, const Type *parenttype)
This function will map a const data returning function to a read-only, non-ref, const instance member...
Definition: Embedding.h:1147
Generates a sequence from 0 to the given value.
Definition: TMP.h:18
void ASSERT_FALSE(const std::string &message, int skip=1, int depth=4)
Definition: Assert.h:192
virtual std::string ToString(const Data &data) const override
Converts a data of this type to string.
Definition: Embedding.h:1420
const Type & GetType() const
Returns the type of the data.
Definition: Data.h:173
This class wraps a C++ function into an overload. It can be constructed using MapFunction.
Definition: Embedding.h:54
T_ classbase::* member
Definition: Embedding.h:944
This class allows a one to one mapping of a data member to a c++ data member.
Definition: Embedding.h:844
std::enable_if< std::is_copy_constructible< T2_ >::value, Data >::type getnonref(Data &data) const
Definition: Embedding.h:896
virtual std::string ToString(const Gorgon::Scripting::Data &) const override
Converts a data of this type to string.
Definition: Embedding.h:1760
static std::enable_if< istypeptr, typename std::remove_pointer< T2_ >::type >::type deref(const T2_ val)
Definition: Embedding.h:866
virtual void set(Data &source, Data &value) const override
This function should perform set operation.
Definition: Embedding.h:1092
This class makes working with operators easier.
Definition: Embedding.h:635
static std::enable_if< istypeptr, T2_ >::type toptr(T2_ val)
Definition: Embedding.h:876
Scripting::Function fn
Definition: Embedding.h:1041
typename std::remove_pointer< C_ >::type * classptr
Definition: Embedding.h:847
MappedOperator(const std::string &name, const std::string &help, const Type *parent, std::initializer_list< Function::Overload * > overloads)
Definition: Embedding.h:655
virtual void set(Data &source, Data &value) const override
This function should perform set operation.
Definition: Embedding.h:1138
This class stores information about types.
Definition: Reflection.h:1165
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
const Type * type
Type of the datamember.
Definition: Reflection.h:1056
Runtime type class, implements RTTH.
Definition: TMP.h:401
RTTS & NormalType
Definition: TMP.h:375
virtual void Assign(Data &l, const Data &r) const override
Definition: Embedding.h:1453
Data GetReference()
Definition: Data.cpp:148
@ istypeptr
Definition: Embedding.h:1159
static std::enable_if<!std::is_pointer< C2_ >::value, const C2_ * >::type clstoptr(const C2_ &val)
Definition: Embedding.h:891
RTTS & ConstRefType
Definition: TMP.h:375
bool IsReference() const
Returns if this data contains a reference.
Definition: Data.cpp:212
#define ASSERT(expression, message,...)
Replaces regular assert to allow messages and backtrace.
Definition: Assert.h:161
MappedFunction(F_ fn, const Scripting::Type *returntype, Scripting::ParameterList parameters, P_ ...tags)
Constructor.
Definition: Embedding.h:63
static Data Invalid()
Constructs an invalid data object.
Definition: Data.h:27
virtual void typecheck(const Scripting::Type *type) const override final
Type checks the parent.
Definition: Embedding.h:915
virtual void AddMember(StaticMember &member) override
Adds a static member to this type.
Definition: Reflection.h:1214
virtual void deleteobject(const Data &obj) const override
Definition: Embedding.h:1354
MappedReferenceType(const std::string &name, const std::string &help, T_ *def)
Definition: Embedding.h:1408
Function * parent
The parent function of this variant.
Definition: Reflection.h:763
MappedOperator(const std::string &name, const std::string &help, const Type *parent, const Type *returntype, const Type *rhs, F_ fn)
Constructor, returntype and parent could be nullptr, tags are optional.
Definition: Embedding.h:639
std::enable_if<!std::is_copy_constructible< O_ >::value, void >::type addcopyconst()
Definition: Embedding.h:1392
std::enable_if< std::is_copy_constructible< T2_ >::value, Data >::type getnonref()
Definition: Embedding.h:1170
std::vector< Any > OptionList
Definition: Reflection.h:114
virtual void set(Data &source, Data &value) const override
Definition: Embedding.h:1231
@ istypeptr
Definition: Embedding.h:852
virtual Data Call(bool ismethod, const std::vector< Data > ¶meters) const override
Class the stub for this function.
Definition: Embedding.h:67
@ ReferenceTag
Marks the object as a reference.
Definition: Reflection.h:61
virtual void Assign(Data &l, const Data &r) const override
Definition: Embedding.h:1336
void MapDynamicInheritance(Type *type, Type *inherited)
Definition: Embedding.h:1912
@ istypeconst
Definition: Embedding.h:851
void SetParent(const Data data)
Definition: Data.h:141
T_(*)(const std::string &) ParseFn
Definition: Embedding.h:27
T_ ParseThrow(const std::string &)
Definition: Embedding.h:35
Definition: Embedding.h:1238
Represents a function overload.
Definition: Reflection.h:588
std::enable_if< std::is_copy_constructible< O_ >::value, void >::type addcopyconst()
Definition: Embedding.h:1473
Scripting::Function::Overload * MapOperator(F_ fn, const Type *returntype, const Type *rhs)
Definition: Embedding.h:626
bool repeatlast
If true last parameter can be specified any number of times.
Definition: Reflection.h:747
@ ConstTag
Marks a parameter or a function constant.
Definition: Reflection.h:95
ParameterList parameters
Modifiable parameters of this overload.
Definition: Reflection.h:736
virtual Data get(Scripting::Data &data) const override
This function should return the value of this member.
Definition: Embedding.h:1095
This class allows a one to one mapping of a data member to a c++ data member.
Definition: Embedding.h:951
This class allows embedded types to become scripting types that are passed around as values.
Definition: Embedding.h:1300
virtual Data get(Scripting::Data &data) const override
This function should return the value of this member.
Definition: Embedding.h:924
E_ is an enumeration with defined strings.
Definition: Embedding.h:1786
std::enable_if<!std::is_pointer< T2_ >::value, T2_ >::type & getref(T2_ &value) const
Definition: Embedding.h:975
std::enable_if< std::is_pointer< T2_ >::value, typename std::remove_pointer< T2_ >::type >::type & getref()
Definition: Embedding.h:1257
MappedROInstanceMember_Function(F_ reader, const std::string &name, const std::string &help, const Type *type, const Type *parent, bool isconstfn, bool isreffn, bool constant, bool ref, bool readonly)
Definition: Embedding.h:1046
MappedStaticDataMember(T_ value, const std::string &name, const std::string &help, const Type *type, bool constant=false, bool ref=false)
If T_ is a non-pointer type or T_ is pointer and ref is set to true, the value would be used as initi...
Definition: Embedding.h:1243
MappedROInstanceMember(T_ classbase::*member, const std::string &name, const std::string &help, const Type *type, bool constant=false)
Constructor.
Definition: Embedding.h:907
@ istypeconst
Definition: Embedding.h:1158
bool returnsref
This function variant returns a reference.
Definition: Reflection.h:757
std::string Name() const
Returns human readable name of the type.
Definition: TMP.h:184
This class represents a function parameter description.
Definition: Reflection.h:137
const Type & GetType() const
Returns the type of this static member.
Definition: Reflection.h:464
virtual Data Parse(const std::string &str) const override
Parses a string into this data. This function is allowed to throw.
Definition: Embedding.h:1449
bool readonly
Marks this instance as read-only.
Definition: Reflection.h:1065
RTTS & ConstType
Definition: TMP.h:375
bool reference
This instance member is a reference.
Definition: Reflection.h:1062
Represents an enumeration type.
Definition: Reflection.h:1540
std::string name
The name of the datamember.
Definition: Reflection.h:353
Type
Definition: Shader.h:14
Scripting::Function::Overload * MapConstStaticcast(Type *from, Type *to, bool implicit=true)
Maps a constructor for type casting, works for const reference types.
Definition: Embedding.h:815
virtual Data Parse(const std::string &str) const override
Parses a string into this data. This function is allowed to throw.
Definition: Embedding.h:1332
MappedROInstanceMember(T_ classbase::*member, const std::string &name, const std::string &help, const Type *type, bool constant, bool ref, bool readonly)
Definition: Embedding.h:855
std::string help
Help string of the datamember.
Definition: Reflection.h:356
This class allows embedded types to become scripting types that are passed around as references.
Definition: Embedding.h:1406
virtual Data get() const override
This function should return the data. It is overloaded to enforce modifiers.
Definition: Embedding.h:1203
typename std::remove_const< typename std::remove_pointer< T_ >::type >::type normaltype
Definition: Embedding.h:1155
std::enable_if<!std::is_pointer< T2_ >::value, T2_ >::type & getref()
Definition: Embedding.h:1262
MappedInstanceMember_Function(F1_ reader, F2_ writer, const std::string &name, const std::string &help, const Type *type, const Type *parent, bool isconstfn, bool isreffn, bool ref, bool isgetconst, bool issetconst=false)
Constructs a new MappedInstanceMember_Function.
Definition: Embedding.h:1125
This namespace contains Gorgon Script parser and reflection facilities.
Definition: Scripting.h:21
bool IsConstant() const
Returns if this data is constant.
Definition: Data.h:160
virtual void set(Data &source, Data &value) const override
This function should perform set operation.
Definition: Embedding.h:921
Scripting::Function::Overload * MapFunction(F_ fn, const Type *returntype, ParameterList parameters, P_ ...tags)
Definition: Embedding.h:614
bool constant
This instance member is a constant.
Definition: Reflection.h:1059
virtual std::string ToString(const Data &d) const
Converts a data of this type to string.
Definition: Embedding.h:1864
virtual bool IsSameType(const std::type_info &) const =0
Compares the type stored with this service to the given type info.
Exceptions This file contains string related exceptions.
std::enable_if<!std::is_copy_constructible< T2_ >::value, Data >::type getnonref(Data &data) const
Definition: Embedding.h:901
bool returnsconst
This function variant returns a constant, useful with references.
Definition: Reflection.h:760
virtual void Assign(Data &l, const Data &r) const override
Assigns the value of the second parameter to the first, reference types can ignore this function.
Definition: Embedding.h:1872
virtual Data Parse(const std::string &s) const
Parses a string into this data. This function is allowed to throw.
Definition: Embedding.h:1868
RTTS & PtrType
Definition: TMP.h:375
MappedInstanceMember(T_ classbase::*member, const std::string &name, const std::string &help, const Type *type, bool constant=false, bool ref=false)
Constructor.
Definition: Embedding.h:955
const Scripting::Type & Function()
Definition: Reflection.h:589
Represents a function.
Definition: Reflection.h:557
#define MAP_COMPARE(opname, op, mappedtype, cpptype)
Creates a comparison function.
Definition: Embedding.h:692
virtual std::string ToString(const Data &data) const override
Converts a data of this type to string.
Definition: Embedding.h:1327
std::ostream & GetOutput() const
Returns the output stream.
Definition: VirtualMachine.h:145
This class allows mapping of a data member to c++ function data member.
Definition: Embedding.h:1039
Scripting::Function::Overload * MapTypecast(Type *from, Type *to, bool implicit=true)
Maps a constructor for type casting, works for value types.
Definition: Embedding.h:702
MappedStringEnum(const std::string &name, const std::string &help, E_ defval=E_(), bool binary=false)
This constructor adds all elements without any help.
Definition: Embedding.h:1857
@ EventType
An event type, which contains additional information about an event.
Definition: Reflection.h:373
typename std::remove_pointer< C_ >::type classbase
Definition: Embedding.h:848
std::string(*)(const T_ &) StringFromFn
Definition: Embedding.h:24
This class represents an instance data member.
Definition: Reflection.h:989
std::string ToEmptyString(const T_ &)
Definition: Embedding.h:30
MappedValueType(const std::string &name, const std::string &help, const T_ &def)
Definition: Embedding.h:1302
@ ImplicitTag
Makes a constructor implicit.
Definition: Reflection.h:105
const Type * type
Type of the datamember.
Definition: Reflection.h:497
Data ExecuteFunction(const Function *fn, const std::vector< Data > ¶ms, bool method)
Executes a function in the current scope.
Definition: VirtualMachine.cpp:1421
MappedROStaticDataMember(T_ value, const std::string &name, const std::string &help, const Type *type, bool isconstant=false)
If T_ is not a pointer, uses the value as initial value and stores the current value locally.
Definition: Embedding.h:1183
std::enable_if<!std::is_copy_constructible< T2_ >::value, Data >::type getnonref()
Definition: Embedding.h:1175
bool IsStatic() const
Returns if this function is static. Only meaningful when the function is a member function.
Definition: Reflection.h:858
Events allow an easy mechanism to program logic into actions instead of checking actions continuously...
Definition: Reflection.h:1491
Scripting::Function::Overload * MapConstDynamiccast(Type *from, Type *to, bool implicit=true)
Maps a constructor for type casting, works for polymorphic types.
Definition: Embedding.h:759
Definition: Reflection.h:421
std::string GetName() const
Returns the name of this member.
Definition: Reflection.h:325
virtual Data Parse(const std::string &) const override
Parses a string into this data. This function is allowed to throw.
Definition: Embedding.h:1764