classrep.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_classrep_h
00022 #define neo_script_lua_classrep_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 "constructor.h"
00036 
00037 extern "C" { struct lua_State; }
00038 
00039 namespace neo {
00040 namespace script {
00041 namespace lua {
00042 
00043 class ClassBase;
00044 class Object;
00045 class ClassRegistry;
00046 class GetSetBase;
00047 class MethodRep;
00048 
00049 typedef void ( *Destructor )( void* );
00050 
00051 class RuntimeTypeCast
00052 {
00053     public:
00054     inline virtual ~RuntimeTypeCast() {};
00055     virtual ptrdiff_t castPointerOffset( char* p_ptr ) = 0;
00056     virtual RuntimeTypeCast* clone() = 0;
00057 };
00058 
00059 template < class Derived, class Base > class RuntimeTypeCastImpl : public RuntimeTypeCast
00060 {
00061     public:
00062     inline virtual ptrdiff_t castPointerOffset( char* p_ptr ) { return core::castPointerOffset< Derived, Base >( reinterpret_cast< Derived* >( p_ptr ) ); }
00063     virtual RuntimeTypeCast* clone() { return new RuntimeTypeCastImpl; }
00064 };
00065 
00066 class BaseClassDesc
00067 {
00068     public:
00069 
00070     const std::type_info*                                   _p_type;
00071     int                                                     _offset;
00072     RuntimeTypeCast*                                        _p_caster;
00073     ClassRep*                                               _p_crep;
00074     inline                                                  BaseClassDesc( const std::type_info* p_type = 0, int offset = 0, RuntimeTypeCast* p_caster = 0, ClassRep* p_crep = 0 );
00075     inline                                                  BaseClassDesc( const BaseClassDesc& desc );
00076     inline                                                 ~BaseClassDesc();
00077 };
00078 
00079 class ClassRep
00080 {
00081     public:
00082 
00084 
00090                                                             ClassRep( lua_State* p_state, const std::type_info* p_type, const char* p_name, Destructor destructor );
00091 
00093                                                            ~ClassRep();
00094 
00096 
00099     int                                                     isOfType( const std::type_info* p_type ) const;
00100 
00102 
00106     int                                                     getConversionOffset( const std::type_info* p_type, char* p_ptr ) const;
00107 
00108     int                                                     getTable( lua_State* p_state );
00109 
00110     bool                                                    setTable( lua_State* p_state );
00111 
00112     inline const char*                                      getName() const { return _p_name; }
00113     
00114     static int                                              dispatchGetTable( lua_State* p_state );
00115 
00116     static int                                              dispatchSetTable( lua_State* p_state );
00117 
00118     static int                                              dispatchOperator( lua_State* p_state );
00119 
00120     static int                                              dispatchConstructor( lua_State* p_state );
00121 
00122     static int                                              dispatchMethod( lua_State* p_state );
00123 
00124     static int                                              getTableStatic( lua_State* p_state );
00125     int                                                     getTableStaticClass( lua_State* p_state );
00126 
00127     static ClassRep*                                        isClass( lua_State* p_state, int index );
00128     
00129     private:
00130 
00132     int                                                     _refSelf;
00133 
00135     const char*                                             _p_name;
00136 
00138     const std::type_info*                                   _p_type;
00139 
00141     core::HashTable< const char*, MethodRep >               _methods;
00142 
00144     core::HashTable< const char*, MethodRep >               _methodsStatic;
00145 
00147     ConstructorRep                                          _ctor;
00148 
00150     core::Array< MethodRep >                                _operators;
00151 
00153     core::HashTable< const char*, GetSetBase* >             _getters;
00154 
00156     core::HashTable< const char*, GetSetBase* >             _setters;
00157 
00159     core::HashTable< const char*, int >                     _enums;
00160 
00162     core::HashTable< const char*, GetSetBase* >             _statics;
00163     
00165     core::Array< BaseClassDesc >                            _bases;
00166 
00168     Destructor                                              _dtor;
00169 
00170     friend class ClassBase;
00171     friend class Object;
00172     friend class ClassRegistry;
00173 };
00174 
00175 #include "classrep.inl"
00176 
00177 }
00178 }
00179 }
00180 
00181 #endif
00182 
00183 #endif

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