Main Page | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages

ClassType.hh

Go to the documentation of this file.
00001 #ifndef RFL_CLASSTYPE_HH
00002 #define RFL_CLASSTYPE_HH
00003 /* C++ Reflection & Serice Library
00004  * Copyright (C) 2003  Marcus Perlick
00005  * mailto: riffraff@users.sf.net
00006  * 
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  * 
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00020  * USA
00021  *
00022  * This file is part of the "C++ Reflection & Serice Library" */
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 } // namespace rfl
00130 #endif // RFL_CLASSTYPE_HH

Generated on Thu Dec 18 11:32:54 2003 for Reflection&ServiceLibrary by doxygen 1.3.2