class.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2004-2005 by Reality Rift Studios                       *
00003  *   http://www.realityrift.com  -  mattias@realityrift.com                *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #ifndef neo_script_lua_class_h
00022 #define neo_script_lua_class_h
00023 
00029 #include "../../core/platform.h"
00030 
00031 #if NEO_ENABLE_SCRIPT_LUA
00032 
00033 #include "../../core/hashtable.h"
00034 #include "../../core/type.h"
00035 #include "classrep.h"
00036 #include "scope.h"
00037 #include "method.h"
00038 
00039 extern "C" { struct lua_State; }
00040 
00041 namespace neo {
00042 namespace script {
00043 namespace lua {
00044 
00045 
00046 template< class T, class X1 = core::NullType, class X2 = core::NullType, class X3 = core::NullType, class X4 = core::NullType > class Class;
00047 class ClassRep;
00048 class ClassRegstry;
00049 
00050 
00051 template < class T > struct ClassDestructor
00052 {
00053     static void deleteT( void* p_ptr )
00054     {
00055         delete static_cast< T* >( p_ptr );
00056     }
00057 };
00058 
00059 struct SingletonDestructor
00060 {
00061     static void deleteT( void* ) {}
00062 };
00063 
00064 typedef void ( *Destructor )( void* );
00065 
00066 template < class T > class VirtualClass {};
00067 
00068 class ClassBase : public ScopedObject
00069 {
00070     public:
00071 
00073 
00076                                                             ClassBase( const char* p_name, const std::type_info* p_type, Destructor dtor );
00077 
00079     virtual                                                ~ClassBase();
00080 
00082 
00083     inline const char*                                      getName() const;
00084 
00086 
00087     virtual void                                            commit( lua_State* p_state );
00088 
00090 
00091     virtual ScopedObject*                                   clone();
00092     
00093     protected:
00094 
00096 
00097     void                                                    addBase( const BaseClassDesc& base );
00098 
00100 
00103     void                                                    addMethod( const char* p_name, MethodRep::Overload& method );
00104 
00106 
00109     void                                                    addStaticMethod( const char* p_name, MethodRep::Overload& method );
00110 
00112 
00114     void                                                    addConstructor( const ConstructorRep::Overload& ctor );
00115 
00117 
00120     void                                                    addOperator( int opid, MethodRep::Overload& method );
00121 
00123 
00127     void                                                    addProperty( const char* p_name, GetSetBase* p_getter, GetSetBase* p_setter );
00128 
00130 
00133     void                                                    addEnum( const char* p_name, int value );
00134 
00136 
00139     void                                                    addStaticProperty( const char* p_name, GetSetBase* p_getter );
00140     
00141     private:
00142 
00144     const char*                                             _p_name;
00145 
00147     const std::type_info*                                   _p_type;
00148 
00150     core::HashTable< const char*, MethodRep >               _methods;
00151 
00153     core::HashTable< const char*, MethodRep >               _methodsStatic;
00154 
00156     ConstructorRep                                          _ctor;
00157 
00159     core::Array< MethodRep >                                _operators;
00160 
00162     core::HashTable< const char*, GetSetBase* >             _getters;
00163 
00165     core::HashTable< const char*, GetSetBase* >             _setters;
00166 
00168     core::HashTable< const char*, int >                     _enums;
00169 
00171     core::HashTable< const char*, GetSetBase* >             _statics;
00172     
00174     Destructor                                              _dtor;
00175 
00177     core::Array< BaseClassDesc >                            _bases;
00178 };
00179 
00180 
00181 template < class T, class X1, class X2, class X3, class X4 > class Class : public ClassBase
00182 {
00183     public:
00184 
00186 
00187     inline                                                  Class( const char* p_name );
00188 
00190 
00192     inline                                                  Class( const char* p_name, Destructor p_dtor );
00193     
00195     virtual                                                ~Class();
00196 
00198 
00201     template < class F >
00202     inline Class&                                           staticmethod( const char* p_name, F method );
00203 
00205 
00209     template < class F, class ReturnPolicy >
00210     inline Class&                                           staticmethod( const char* p_name, F method, const ReturnPolicy& policy );
00211 
00213 
00216     template < class F >
00217     inline Class&                                           method( const char* p_name, F method );
00218 
00220 
00224     template < class F, class ReturnPolicy >
00225     inline Class&                                           method( const char* p_name, F method, const ReturnPolicy& policy );
00226 
00228 
00230     template < class A0, class A1, class A2, class A3 >
00231     inline Class&                                           method( const Constructor< A0, A1, A2, A3 >& ctor );
00232     
00234 
00237     template < class F >
00238     inline Class&                                           op( int opid, F method );
00239     
00241 
00244     template < class F >
00245     inline Class&                                           globalop( int opid, F method );
00246 
00248 
00251     template < class D >
00252     inline Class&                                           property( const char* p_name, D T::*p_property, bool readonly = false );
00253 
00255 
00257     inline Class&                                           enumerate( const char* p_name, int value );
00258 
00260 
00262     template < class D >
00263     inline Class&                                           staticproperty( const char* p_name, D* p_property );
00264     
00265     private:
00266 
00267     template < class To > inline void                       genBaseDesc( core::TypeHolder< To > );
00268     template < class To > inline void                       genBaseDesc( core::TypeHolder< VirtualClass< To > > );
00269     inline void                                             genBaseDesc( core::TypeHolder< core::NullType > );
00270 };
00271 
00272 #include "class.inl"
00273 
00274 }
00275 }
00276 }
00277 
00278 #endif
00279 
00280 #endif

Generated on Sat Feb 17 20:50:48 2007 for NeoEngine 2 - Evolution by  doxygen 1.5.1