00001 #ifndef RFL_CLASSTYPE_HH
00002 #define RFL_CLASSTYPE_HH
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <cassert>
00025 #include <vector>
00026
00027 #include "Type.hh"
00028
00029 namespace rfl {
00030
00031 class ClassType : public Type {
00032 public:
00033
00034 virtual void avStartCall( av_alist& avList,
00035 void* fnPtr,
00036 void *retVal ) const;
00037
00038 virtual void avPutArg( av_alist& avList, void* arg ) const;
00039
00040 int getElmIdx( const mpu::String& name ) const;
00041 virtual const Type& getElmType( std::size_t idx ) const;
00042 virtual void* getElmAddr( void* obj, std::size_t idx ) const;
00043 const mpu::String& getElmName( std::size_t idx ) const;
00044
00045 std::size_t getBaseClassNo( void ) const { return bases_.size(); }
00046 const ClassType& getBaseClass( std::size_t idx ) const;
00047 void* toBaseClass( void* obj, std::size_t idx ) const;
00048
00049 virtual unsigned long hash( void ) const;
00050 virtual bool operator==( const Type& type ) const;
00051
00052 AspectValue& getElmAspect( std::size_t idx, Aspect::Id aspectId );
00053 const AspectValue& getElmAspect( std::size_t idx,
00054 Aspect::Id aspectId ) const;
00055
00056 protected:
00057
00058 struct BaseClass {
00059 const ClassType* type_;
00060 std::size_t offset_;
00061 };
00062
00063 typedef std::vector<BaseClass> BaseClassList;
00064
00065 struct Member {
00066 mpu::String name_;
00067 const Type* type_;
00068 std::size_t offset_;
00069 AspectVector aspcts_;
00070 };
00071
00072 typedef std::vector<Member> MemberList;
00073
00074 BaseClassList bases_;
00075 MemberList mbrs_;
00076
00077 ClassType( const mpu::String& name,
00078 std::size_t size,
00079 std::size_t alignment,
00080 std::size_t elementNum,
00081 const std::type_info* typeId,
00082 void(*create)(const Type*,void*),
00083 void(*cCreate)(const Type*,void*,const void*),
00084 void(*destroy)(const Type*,void*),
00085 void(*assign)(const Type*,void*,const void*),
00086 void*(*newObj)(const Type*),
00087 void*(*newCopy)(const Type*,const void*),
00088 void(*delObj)(const Type*,void*) ) :
00089 Type( ID_CLASS, name, size, alignment, elementNum, typeId,
00090 create, cCreate, destroy, assign, newObj, newCopy, delObj )
00091 {}
00092 };
00093
00094 inline const mpu::String&
00095 ClassType::getElmName( std::size_t idx ) const
00096 {
00097 assert( idx < mbrs_.size() );
00098 return mbrs_[ idx ].name_;
00099 }
00100
00101 inline const ClassType&
00102 ClassType::getBaseClass( std::size_t idx ) const
00103 {
00104 assert( idx < bases_.size() );
00105 return *(bases_[ idx ].type_);
00106 }
00107
00108 inline AspectValue&
00109 ClassType::getElmAspect( std::size_t idx, Aspect::Id aspectId )
00110 {
00111 assert( idx < bases_.size() );
00112 return mbrs_[ idx ].aspcts_.data( aspectId );
00113 }
00114
00115 inline const AspectValue&
00116 ClassType::getElmAspect( std::size_t idx, Aspect::Id aspectId ) const
00117 {
00118 assert( idx < bases_.size() );
00119 return mbrs_[ idx ].aspcts_.data( aspectId );
00120 }
00121
00122 inline void*
00123 ClassType::toBaseClass( void* obj, std::size_t idx ) const
00124 {
00125 assert( idx < bases_.size() );
00126 return ((char*)obj) + bases_[ idx ].offset_;
00127 }
00128
00129 }
00130 #endif // RFL_CLASSTYPE_HH