📄 type.hh
字号:
#ifndef RFL_TYPE_HH#define RFL_TYPE_HH/* C++ Reflection & Serice Library * Copyright (C) 2003 Marcus Perlick * mailto: riffraff@users.sf.net * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * * This file is part of the "C++ Reflection & Serice Library" */#include <mpu/String.hh>#include <avcall.h>#include "AspectVector.hh"#include "Aspect.hh"namespace rfl { /** This is the central class of the reflection system. A \c Type object * describes the structure of arbitrary objects. Theses types can be * subdivided into the following kinds: * * - The void type, which is the type anything that has not type. * - Several fundamental types representing the C++ builtin types. * - Pointer types, ... pointers! * - Array types representing C/C++ arrays with fixed length. * - Class types representing any structured type. * - Function Types representing C/C++ functions (including member * functions). * * \sa FundamentalType, PointerType, ArrayType, ClassType, FunctionType. */ class Type { public: enum Id { ID_VOID = 0, // Funadmental Types ID_BOOL, ID_CHAR, ID_UCHAR, ID_SHORT, ID_USHORT, ID_INT, ID_UINT, ID_LONG, ID_ULONG, ID_FLOAT, ID_DOUBLE, // Use this to detect fundamental types ID_FUNDAMENTAL_END, // Ths first non-fundamental type ID_PTR = ID_FUNDAMENTAL_END, ID_ARRAY, ID_CLASS, ID_FUNCTION }; Type( Id id, const ::mpu::String& name, std::size_t size, std::size_t alignment, std::size_t elementNum, void(*create)(const Type*,void*), void(*cCreate)(const Type*,void*,const void*), void(*destroy)(const Type*,void*), void(*assign)(const Type*,void*,const void*), void*(*newObj)(const Type*), void*(*newCopy)(const Type*,const void*), void(*delObj)(const Type*,void*) ) : elmNo_( elementNum ), name_( name ), create_( create ), cCreate_(cCreate), destroy_( destroy ), assign_( assign ), newObj_( newObj ), newCopy_( newCopy ), delObj_( delObj ), size_( size ), align_( alignment ), id_( id ) {} virtual ~Type( void ) {} Id getId( void ) const { return id_; } const mpu::String& getName( void ) const { return name_; } std::size_t getSize( void ) const { return size_; } std::size_t getAlignment( void ) const { return align_; } void create( void* addr ) const; void create( void* addr, const void* obj ) const; void destroy( void* obj ) const; void assign( void* dst, const void* src ) const; void* newObj( void ) const; void* newObj( const void* obj ) const; void delObj( void* obj ) const; virtual void avStartCall( av_alist& avList, void* fnPtr, void *retVal ) const = 0; virtual void avPutArg( av_alist& avList, void* arg ) const = 0; std::size_t getElmNo( void ) const { return elmNo_; } virtual const Type& getElmType( std::size_t idx ) const = 0; virtual void* getElmAddr( void* obj, std::size_t idx ) const = 0; const void* getElmAddr( const void* obj, std::size_t idx ) const; /** This is a little helper to identify types with equal structure */ virtual unsigned long hash( void ) const = 0; virtual bool operator==( const Type& type ) const = 0; bool operator!=( const Type& type ) const { return !operator==( type ); } mpu::any::Any& aspect( Aspect::Id id ); const mpu::any::Any& aspect( Aspect::Id id ) const; protected: static void updateHash( unsigned long& h, unsigned long id ) { h = 5 * h + id; } std::size_t elmNo_; mpu::String name_; void (*create_)( const Type*, void* ); void (*cCreate_)( const Type*, void*, const void* ); void (*destroy_)( const Type*, void* ); void (*assign_)( const Type*, void*, const void* ); void* (*newObj_)( const Type* ); void* (*newCopy_)( const Type*, const void* ); void (*delObj_)( const Type*, void* ); private: std::size_t size_; std::size_t align_; Id id_; AspectVector aspects_; Type( const Type& ); Type& operator=( const Type& ); }; inline const void* Type::getElmAddr( const void* obj, std::size_t idx ) const { return getElmAddr( const_cast<void*>(obj), idx ); } inline mpu::any::Any& Type::aspect( Aspect::Id id ) { return aspects_[ id ]; } inline const mpu::any::Any& Type::aspect( Aspect::Id id ) const { return aspects_[ id ]; } extern const Type& TypeVoid;} // namespace rfl#endif // RFL_TYPE_HH
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -