⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arraytype.cc

📁 C++ Reflection & Service Library
💻 CC
字号:
/* 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 "ArrayType.hh"#include <cstdlib>#include <cassert>#include <sstream>#include "PointerType.hh"namespace rfl {    static mpu::String mkArrayName( const Type& elementType,				  std::size_t elementNum )  {    std::ostringstream tmp;    tmp << elementType.getName() << '[' << elementNum << ']';    return tmp.str();  }  ArrayType::ArrayType( const Type& elementType, std::size_t elementNum ) :    Type( ID_ARRAY,	  mkArrayName( elementType, elementNum ),	  elementNum * elementType.getSize(),	  elementType.getAlignment(),	  elementNum,	  ArrayType::fCreate,	  ArrayType::fCCreate,	  ArrayType::fDestroy,	  ArrayType::fAssign,	  ArrayType::fNewObj,	  ArrayType::fNewCopy,	  ArrayType::fDelObj ),    elmType_( &elementType )  {}    void  ArrayType::avStartCall( av_alist& avList,			  void* fnPtr,			  void *retVal ) const  {    assert( elmType_ != 0 );        PointerType ptr( *elmType_ );    ptr.avStartCall( avList, fnPtr, &retVal );  }  void  ArrayType::avPutArg( av_alist& avList, void* arg ) const  {    assert( elmType_ != 0 );        PointerType ptr( *elmType_ );    ptr.avPutArg( avList, &arg );  }  void ArrayType::fCreate( const Type* at, void* addr )  {    assert( ((ArrayType*)at)->elmType_ != 0 );    char* it = (char*)addr;    char* end = it + ((ArrayType*)at)->getSize();    while ( it < end ) {      ((ArrayType*)at)->elmType_->create( it );      it += ((ArrayType*)at)->elmType_->getSize();    };  }  void ArrayType::fCCreate( const Type* at, void* addr, const void* obj )  {    assert( ((ArrayType*)at)->elmType_ != 0 );    char* s = (char*)obj;    char* d = (char*)addr;    char* end = d + ((ArrayType*)at)->getSize();    while ( d < end ) {      ((ArrayType*)at)->elmType_->create( d, s );      d += ((ArrayType*)at)->elmType_->getSize();      s += ((ArrayType*)at)->elmType_->getSize();    }  }  void ArrayType::fDestroy( const Type* at, void* obj )  {    assert( ((ArrayType*)at)->elmType_ != 0 );    char* it = (char*)obj;    char* end = it + ((ArrayType*)at)->getSize();        while ( it < end ) {      ((ArrayType*)at)->elmType_->destroy( it );      it += ((ArrayType*)at)->elmType_->getSize();    }  }  void ArrayType::fAssign( const Type* at, void* dst, const void* src )  {    assert( ((ArrayType*)at)->elmType_ != 0 );    char* s = (char*)src;    char* d = (char*)dst;    char* end = d + ((ArrayType*)at)->getSize();    while ( d < end ) {      ((ArrayType*)at)->elmType_->assign( d, s );      d += ((ArrayType*)at)->elmType_->getSize();      s += ((ArrayType*)at)->elmType_->getSize();    }  }  void* ArrayType::fNewObj( const Type* at )  {    assert( ((ArrayType*)at)->elmType_ != 0 );    void* ret = std::malloc( ((ArrayType*)at)->getSize() );    ((ArrayType*)at)->fCreate( at, ret );    return ret;  }  void* ArrayType::fNewCopy( const Type* at, const void* obj )  {    assert( ((ArrayType*)at)->elmType_ != 0 );    void* ret = std::malloc( ((ArrayType*)at)->getSize() );    ((ArrayType*)at)->fCCreate( at, ret, obj );    return ret;  }  void ArrayType::fDelObj( const Type* at, void* obj )  {    ((ArrayType*)at)->fDestroy( at, obj );    std::free( obj );  }  const Type&  ArrayType::getElmType( std::size_t idx ) const  {    assert( elmType_ != 0 );    return *elmType_;  }  void*  ArrayType::getElmAddr( void* obj, std::size_t idx ) const  {    assert( elmType_ != 0 );    assert( idx < getElmNo() );    return ((char*)obj) + idx * elmType_->getSize();  }  unsigned long  ArrayType::hash( void ) const  {    unsigned long ret = ID_ARRAY;    updateHash( ret, getElmNo() );    assert( elmType_ != 0 );    updateHash( ret, elmType_->hash() );    return ret;  }  bool  ArrayType::operator==( const Type& type ) const  {    if ( type.getId() != ID_ARRAY )      return false;    assert( elmType_ != 0 );    assert( static_cast<const ArrayType&>(type).elmType_ != 0 );    if ( getElmNo() != type.getElmNo() )      return false;    return *elmType_ == *static_cast<const ArrayType&>(type).elmType_;  }} // namespace rfl

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -