📄 dclasstype.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 "DClassType.hh"#include "align.hh"namespace rfl { struct Dummy { double d; }; DClassType::DClassType( const char* name ) : ClassType( name, 0, AlignmentOf<Dummy>::is(), 0, &DClassType::fCreate, &DClassType::fCCreate, &DClassType::fDestroy, &DClassType::fAssign, &DClassType::fNewObj, &DClassType::fNewCopy, &DClassType::fDelObj ) {} void DClassType::fCreate( const Type* ct, void* addr ) { assert( ct != 0 ); const DClassType& dc = *static_cast<const DClassType*>(ct); BaseClassList::const_iterator bEnd = dc.bases_.end(); for ( BaseClassList::const_iterator it = dc.bases_.begin(); it != bEnd; ++it ) { it->type_->create( ((char*)addr) + it->offset_ ); } MemberList::const_iterator mEnd = dc.mbrs_.end(); for ( MemberList::const_iterator it = dc.mbrs_.begin(); it != mEnd; ++it ) { it->type_->create( ((char*)addr) + it->offset_ ); } } void DClassType::fCCreate( const Type* ct, void* addr, const void* obj ) { assert( ct != 0 ); const DClassType& dc = *static_cast<const DClassType*>(ct); BaseClassList::const_iterator bEnd = dc.bases_.end(); for ( BaseClassList::const_iterator it = dc.bases_.begin(); it != bEnd; ++it ) { it->type_->create( ((char*)addr) + it->offset_, ((char*)obj) + it->offset_ ); } MemberList::const_iterator mEnd = dc.mbrs_.end(); for ( MemberList::const_iterator it = dc.mbrs_.begin(); it != mEnd; ++it ) { it->type_->create( ((char*)addr) + it->offset_, ((char*)obj) + it->offset_ ); } } void DClassType::fDestroy( const Type* ct, void* obj ) { assert( ct != 0 ); const DClassType& dc = *static_cast<const DClassType*>(ct); BaseClassList::const_iterator bEnd = dc.bases_.end(); for ( BaseClassList::const_iterator it = dc.bases_.begin(); it != bEnd; ++it ) { it->type_->destroy( ((char*)obj) + it->offset_ ); } MemberList::const_iterator mEnd = dc.mbrs_.end(); for ( MemberList::const_iterator it = dc.mbrs_.begin(); it != mEnd; ++it ) { it->type_->destroy( ((char*)obj) + it->offset_ ); } } void DClassType::fAssign( const Type* ct, void* dst, const void* src ) { assert( ct != 0 ); const DClassType& dc = *static_cast<const DClassType*>(ct); BaseClassList::const_iterator bEnd = dc.bases_.end(); for ( BaseClassList::const_iterator it = dc.bases_.begin(); it != bEnd; ++it ) { it->type_->create( ((char*)dst) + it->offset_, ((char*)src) + it->offset_ ); } MemberList::const_iterator mEnd = dc.mbrs_.end(); for ( MemberList::const_iterator it = dc.mbrs_.begin(); it != mEnd; ++it ) { it->type_->create( ((char*)dst) + it->offset_, ((char*)src) + it->offset_ ); } } void* DClassType::fNewObj( const Type* ct ) { assert( ct != 0 ); void* ret = std::malloc( ct->getSize() ); if ( ret ) { fCreate( ct, ret ); } return ret; } void* DClassType::fNewCopy( const Type* ct, const void* obj ) { assert( ct != 0 ); void* ret = std::malloc( ct->getSize() ); if ( ret ) { fCCreate( ct, ret, obj ); } return ret; } void DClassType::fDelObj( const Type* ct, void* obj ) { assert( ct != 0 ); if ( obj ) { fDestroy( ct, obj ); std::free( obj ); } }} // namespace rfl
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -