📄 exception.hh
字号:
/* Reflection & Service Library * Copyright (C) 2003 Marcus Perlick * mailto: riffraff@users.sf.net * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307, USA. */#ifndef MPU_EXCEPTION_H#define MPU_EXCEPTION_H#ifndef MPU_NO_IOSTREAM# include <iosfwd>#endif#include <vector>#include <cstdarg>#include "String.hh"namespace mpu { class RootException { public: static const char CLASS_PATH_SEP; static const char DOMAIN_NAME[]; RootException( int id ); RootException( int id, const char* ftm, ... ); virtual ~RootException( void ) {} void setMsg( const char* fmt, va_list ap ); void setMsg( const char* fmt, ... ); const char* getDomain( void ) const; int getId( void ) const; const char* what( void ) const; String getClassPath( void ) const; protected: virtual void makePath( String& path ) const; private: enum { MSG_BUFFER_SIZE = 1024 }; int id_; /** \note In one Process, there will be only one exception at the * same time. So the message buffer is static, to avoid memory * allocation. * * \todo Make sure that this will work in MT environments, * too. */ static char msg_[]; };#ifndef MPU_NO_IOSTREAM std::ostream& operator<<( std::ostream& os, const RootException& x );#endif inline RootException::RootException( int id ) : id_( id ) {} inline const char* RootException::getDomain( void ) const { return DOMAIN_NAME; } inline int RootException::getId( void ) const { return id_; } inline String RootException::getClassPath( void ) const { String tmp; makePath( tmp ); return tmp; } inline const char* RootException::what( void ) const { return msg_; } template<typename Base, const char domain[]> class ExceptionDomain : public Base { public: static const char *const DOMAIN_NAME; ExceptionDomain( int id ) : Base( id ) {} ExceptionDomain( int id, const char* fmt, ... ); const char* getDomain( void ) const; protected: ExceptionDomain( const char* dom, int id ) : Base( dom, id ) {} virtual void makePath( String& path ) const; }; template<typename Base, const char domain[]> const char *const ExceptionDomain<Base, domain>::DOMAIN_NAME = domain; template<typename Base, const char domain[]> ExceptionDomain<Base, domain>::ExceptionDomain( int id, const char* fmt, ... ) : Base( id ) { va_list ap; va_start( ap, fmt ); this->setMsg( fmt, ap ); va_end( ap ); } template<typename Base, const char domain[]> const char* ExceptionDomain<Base, domain>::getDomain( void ) const { return DOMAIN_NAME; } template<typename Base, const char domain[]> void ExceptionDomain<Base, domain>::makePath( String& path ) const { this->Base::makePath( path ); path += getDomain(); path += CLASS_PATH_SEP; } extern const char MPU_EXCEPTION_DOMAIN[]; typedef ExceptionDomain<RootException, MPU_EXCEPTION_DOMAIN> Exception;} // namespace mpu#endif // MPU_EXCEPTION_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -