00001 // ///////////////////////////////////////////////////////////////////////////// 00002 // 00003 // Name: asScriptHelper.h 00004 // Author: Michael Bartsch (ZCCdark203) 00005 // 00006 // Desc : Contains various convenience functions which can be used 00007 // for binding to AngelScript. 00008 // 00009 // License: Copyright (C) 2009 Michael Bartsch and Contributors 00010 // 00011 // This program is free software: you can redistribute it 00012 // and/or modify it under the terms of the zlib/libpng License. 00013 // See main.cpp for conditions of distribution and use. 00014 // 00015 // ///////////////////////////////////////////////////////////////////////////// 00016 00017 #ifndef __SCRIPTHELPER_H__ 00018 #define __SCRIPTHELPER_H__ 00019 00020 #include "../config.h" 00021 00022 #ifdef __COMPILE_WITH_ANGELSCRIPT__ 00023 00025 template<typename T> 00026 T& assignT(const T ©) 00027 { 00028 T *t = new T(copy); 00029 return *t; 00030 } 00031 00034 template<typename A, typename B> 00035 B* asRefCast(A* a) 00036 { 00037 // If the handle already is a null handle, then just return the null handle 00038 if( !a ) return 0; 00039 00040 // Now try to dynamically cast the pointer to the wanted type 00041 B* b = dynamic_cast<B*>(a); 00042 if( b == 0 ) 00043 { 00044 // Since the cast couldn't be made, we need to release the handle we received 00045 a->drop(); 00046 } 00047 return b; 00048 } 00049 00050 #endif // __COMPILE_WITH_ANGELSCRIPT__ 00051 00052 #endif