/*************************************************************************/ /* method_ptrcall.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ /* "Software"), to deal in the Software without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, sublicense, and/or sell copies of the Software, and to */ /* permit persons to whom the Software is furnished to do so, subject to */ /* the following conditions: */ /* */ /* The above copyright notice and this permission notice shall be */ /* included in all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #ifndef METHOD_PTRCALL_H #define METHOD_PTRCALL_H #include "typedefs.h" #include "math_2d.h" #include "variant.h" #ifdef PTRCALL_ENABLED template struct PtrToArg { }; #define MAKE_PTRARG(m_type) \ template<>\ struct PtrToArg {\ _FORCE_INLINE_ static m_type convert(const void* p_ptr) {\ return *reinterpret_cast(p_ptr);\ }\ _FORCE_INLINE_ static void encode(m_type p_val, void* p_ptr) {\ *((m_type*)p_ptr)=p_val;\ }\ };\ template<>\ struct PtrToArg {\ _FORCE_INLINE_ static m_type convert(const void* p_ptr) {\ return *reinterpret_cast(p_ptr);\ }\ _FORCE_INLINE_ static void encode(m_type p_val, void* p_ptr) {\ *((m_type*)p_ptr)=p_val;\ }\ } #define MAKE_PTRARGR(m_type,m_ret) \ template<>\ struct PtrToArg {\ _FORCE_INLINE_ static m_type convert(const void* p_ptr) {\ return *reinterpret_cast(p_ptr);\ }\ _FORCE_INLINE_ static void encode(m_type p_val, void* p_ptr) {\ *((m_ret*)p_ptr)=p_val;\ }\ };\ template<>\ struct PtrToArg {\ _FORCE_INLINE_ static m_type convert(const void* p_ptr) {\ return *reinterpret_cast(p_ptr);\ }\ _FORCE_INLINE_ static void encode(m_type p_val, void* p_ptr) {\ *((m_ret*)p_ptr)=p_val;\ }\ } MAKE_PTRARG(bool); MAKE_PTRARGR(uint8_t,int); MAKE_PTRARGR(int8_t,int); MAKE_PTRARGR(uint16_t,int); MAKE_PTRARGR(int16_t,int); MAKE_PTRARGR(uint32_t,int); MAKE_PTRARGR(int32_t,int); MAKE_PTRARGR(int64_t,int); MAKE_PTRARGR(uint64_t,int); MAKE_PTRARG(float); MAKE_PTRARGR(double,float); MAKE_PTRARG(String); MAKE_PTRARG(Vector2); MAKE_PTRARG(Rect2); MAKE_PTRARG(Vector3); MAKE_PTRARG(Transform2D); MAKE_PTRARG(Plane); MAKE_PTRARG(Quat); MAKE_PTRARG(Rect3); MAKE_PTRARG(Basis); MAKE_PTRARG(Transform); MAKE_PTRARG(Color); MAKE_PTRARG(Image); MAKE_PTRARG(NodePath); MAKE_PTRARG(RID); MAKE_PTRARG(InputEvent); MAKE_PTRARG(Dictionary); MAKE_PTRARG(Array); MAKE_PTRARG(PoolByteArray); MAKE_PTRARG(PoolIntArray); MAKE_PTRARG(PoolRealArray); MAKE_PTRARG(PoolStringArray); MAKE_PTRARG(PoolVector2Array); MAKE_PTRARG(PoolVector3Array); MAKE_PTRARG(PoolColorArray); MAKE_PTRARG(Variant); //this is for Object template struct PtrToArg< T* > { _FORCE_INLINE_ static T* convert(const void* p_ptr) { return const_cast(reinterpret_cast(p_ptr)); } _FORCE_INLINE_ static void encode(T* p_var, void* p_ptr) { *((T**)p_ptr)=p_var; } }; template struct PtrToArg< const T* > { _FORCE_INLINE_ static const T* convert(const void* p_ptr) { return reinterpret_cast(p_ptr); } _FORCE_INLINE_ static void encode(T* p_var, void* p_ptr) { *((T**)p_ptr)=p_var; } }; //this is for the special cases used by Variant #define MAKE_VECARG(m_type) \ template<>\ struct PtrToArg > {\ _FORCE_INLINE_ static Vector convert(const void* p_ptr) {\ const PoolVector *dvs = reinterpret_cast *>(p_ptr);\ Vector ret;\ int len = dvs->size();\ ret.resize(len);\ {\ PoolVector::Read r=dvs->read();\ for(int i=0;i p_vec, void* p_ptr) {\ PoolVector *dv = reinterpret_cast *>(p_ptr);\ int len=p_vec.size();\ dv->resize(len);\ {\ PoolVector::Write w=dv->write();\ for(int i=0;i\ struct PtrToArg& > {\ _FORCE_INLINE_ static Vector convert(const void* p_ptr) {\ const PoolVector *dvs = reinterpret_cast *>(p_ptr);\ Vector ret;\ int len = dvs->size();\ ret.resize(len);\ {\ PoolVector::Read r=dvs->read();\ for(int i=0;i\ struct PtrToArg > {\ _FORCE_INLINE_ static Vector convert(const void* p_ptr) {\ const Array *arr = reinterpret_cast(p_ptr);\ Vector ret;\ int len = arr->size();\ ret.resize(len);\ for(int i=0;i p_vec, void* p_ptr) {\ Array *arr = reinterpret_cast(p_ptr);\ int len = p_vec.size();\ arr->resize(len);\ for(int i=0;i\ struct PtrToArg& > {\ _FORCE_INLINE_ static Vector convert(const void* p_ptr) {\ const Array *arr = reinterpret_cast(p_ptr);\ Vector ret;\ int len = arr->size();\ ret.resize(len);\ for(int i=0;i\ struct PtrToArg > {\ _FORCE_INLINE_ static PoolVector convert(const void* p_ptr) {\ const Array *arr = reinterpret_cast(p_ptr);\ PoolVector ret;\ int len = arr->size();\ ret.resize(len);\ {\ PoolVector::Write w=ret.write();\ for(int i=0;i p_vec, void* p_ptr) {\ Array *arr = reinterpret_cast(p_ptr);\ int len = p_vec.size();\ arr->resize(len);\ {\ PoolVector::Read r=p_vec.read();\ for(int i=0;i\ struct PtrToArg& > {\ _FORCE_INLINE_ static PoolVector convert(const void* p_ptr) {\ const Array *arr = reinterpret_cast(p_ptr);\ PoolVector ret;\ int len = arr->size();\ ret.resize(len);\ {\ PoolVector::Write w=ret.write();\ for(int i=0;i\ struct PtrToArg {\ _FORCE_INLINE_ static m_type convert(const void* p_ptr) {\ m_type s = *reinterpret_cast(p_ptr);\ return s;\ }\ _FORCE_INLINE_ static void encode(m_type p_vec, void* p_ptr) {\ String *arr = reinterpret_cast(p_ptr);\ *arr=p_vec;\ }\ };\ \ template<>\ struct PtrToArg {\ _FORCE_INLINE_ static m_type convert(const void* p_ptr) {\ m_type s = *reinterpret_cast(p_ptr);\ return s;\ }\ } MAKE_STRINGCONV(StringName); MAKE_STRINGCONV(IP_Address); template<> struct PtrToArg > { _FORCE_INLINE_ static PoolVector convert(const void* p_ptr) { const PoolVector *dvs = reinterpret_cast *>(p_ptr); PoolVector ret; int len = dvs->size()/3; ret.resize(len); { PoolVector::Read r=dvs->read(); PoolVector::Write w=ret.write(); for(int i=0;i p_vec, void* p_ptr) {\ PoolVector *arr = reinterpret_cast *>(p_ptr);\ int len = p_vec.size();\ arr->resize(len*3);\ {\ PoolVector::Read r=p_vec.read();\ PoolVector::Write w=arr->write();\ for(int i=0;i struct PtrToArg& > { _FORCE_INLINE_ static PoolVector convert(const void* p_ptr) { const PoolVector *dvs = reinterpret_cast *>(p_ptr); PoolVector ret; int len = dvs->size()/3; ret.resize(len); { PoolVector::Read r=dvs->read(); PoolVector::Write w=ret.write(); for(int i=0;i