📄 xdr.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 "Xdr.hh"#include "../rfl/ClassType.hh"#include "Exception.hh"namespace rfl {namespace ser { bool Xdr::classType( const rfl::Type& type, void* obj ) { const ClassType& clsTy = static_cast<const ClassType&>(type); for ( std::size_t i = 0; i < clsTy.getElmNo(); i++ ) { if ( !(*this)( clsTy.getElmType( i ), clsTy.getElmAddr( obj, i ) ) ) { return false; } } return true; } bool Xdr::operator()( const rfl::Type& type, void* obj ) { if ( !obj ) { Exception x( X_NULLPTR, _("XDR called with NULL object pointer to type %s."), type.getName().c_str() ); throw x; } switch ( type.getId() ) { case Type::ID_VOID: return true; case Type::ID_CHAR: return xdr_char( xdrs_, static_cast<char*>(obj) ); case Type::ID_UCHAR: return xdr_u_char( xdrs_, static_cast<unsigned char*>(obj) ); case Type::ID_SHORT: return xdr_short( xdrs_, static_cast<short*>(obj) ); case Type::ID_USHORT: return xdr_u_short( xdrs_, static_cast<unsigned short*>(obj) ); case Type::ID_INT: return xdr_int( xdrs_, static_cast<int*>(obj) ); case Type::ID_UINT: return xdr_u_int( xdrs_, static_cast<unsigned int*>(obj) ); case Type::ID_LONG: return xdr_long( xdrs_, static_cast<long*>(obj) ); case Type::ID_ULONG: return xdr_u_long( xdrs_, static_cast<unsigned long*>(obj) ); case Type::ID_FLOAT: return xdr_float( xdrs_, static_cast<float*>(obj) ); case Type::ID_DOUBLE: return xdr_double( xdrs_, static_cast<double*>(obj) ); case Type::ID_CLASS: return classType( type, obj ); default: { Exception x( X_TYNOSUPP, _("XDR not supported for type %s."), type.getName().c_str() ); throw x; } } return false; } } } // namespace rfl::ser
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -