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

📄 ncbiexpt.hpp

📁 ncbi源码
💻 HPP
📖 第 1 页 / 共 3 页
字号:
    };    /// Translate from the error code value to its string representation.    virtual const char* GetErrCodeString(void) const;    // Standard exception boilerplate code.    NCBI_EXCEPTION_DEFAULT(CCoreException, CException);};// Some implementations return char*, so strict compilers may refuse// to let them satisfy TStrerror without a wrapper.  However, they// don't all agree on what form the wrapper should take. :-/#ifdef NCBI_COMPILER_GCCinlineconst char* NcbiStrerror(int errnum) { return ::strerror(errnum); }#  define NCBI_STRERROR_WRAPPER NCBI_NS_NCBI::NcbiStrerror#elseclass CStrErrAdapt{public:    static const char* strerror(int errnum) { return ::strerror(errnum); }};#  define NCBI_STRERROR_WRAPPER NCBI_NS_NCBI::CStrErrAdapt::strerror#endif/////////////////////////////////////////////////////////////////////////////// Auxiliary exception classes://   CErrnoException//   CParseException///// Define function type for "strerror" function.typedef const char* (*TStrerror)(int errnum);/////////////////////////////////////////////////////////////////////////////////// CErrnoTemplExceptionEx --////// Define template class for easy generation of Errno-like exception classes.template <class TBase, TStrerror PErrstr=NCBI_STRERROR_WRAPPER >class CErrnoTemplExceptionEx : EXCEPTION_VIRTUAL_BASE public TBase{public:    /// Error type that an application can generate.    enum EErrCode {        eErrno          ///< Error code    };    /// Translate from the error code value to its string representation.    virtual const char* GetErrCodeString(void) const    {        switch (GetErrCode()) {        case eErrno: return "eErrno";        default:     return CException::GetErrCodeString();        }    }    /// Constructor.    CErrnoTemplExceptionEx(const char* file, int line,        const CException* prev_exception,        EErrCode err_code, const string& message) throw()          : TBase(file, line, prev_exception,            (typename TBase::EErrCode)(CException::eInvalid),            message)    {        m_Errno = errno;        this->x_Init(file, line, message + ": " + PErrstr(m_Errno),                     prev_exception);        this->x_InitErrCode((CException::EErrCode) err_code);    }    /// Constructor.    CErrnoTemplExceptionEx(const char* file,int line,        const CException* prev_exception,        EErrCode err_code, const string& message,         int errnum        ) throw()          : TBase(file, line, prev_exception,            (typename TBase::EErrCode)(CException::eInvalid),            message),            m_Errno(errnum)    {        this->x_Init(file, line, message + ": " + PErrstr(m_Errno),                     prev_exception);        this->x_InitErrCode((CException::EErrCode) err_code);    }    /// Copy constructor.    CErrnoTemplExceptionEx(const CErrnoTemplExceptionEx<TBase, PErrstr>& other)        throw()        : TBase( other)    {        m_Errno = other.m_Errno;        x_Assign(other);    }    /// Destructor.    virtual ~CErrnoTemplExceptionEx(void) throw() {}    /// Report error number on stream.    virtual void ReportExtra(ostream& out) const    {        out << "m_Errno = " << m_Errno;    }    // Attributes.    /// Get type of class.    virtual const char* GetType(void) const { return "CErrnoTemplException"; }    typedef int TErrCode;    /// Get error code.    TErrCode GetErrCode(void) const    {        return typeid(*this) ==             typeid(CErrnoTemplExceptionEx<TBase, PErrstr>) ?               (TErrCode) this->x_GetErrCode() :               (TErrCode) CException::eInvalid;    }    /// Get error number.    int GetErrno(void) const throw() { return m_Errno; }protected:    /// Constructor.    CErrnoTemplExceptionEx(void) throw() { m_Errno = errno; }    /// Helper clone method.    virtual const CException* x_Clone(void) const    {        return new CErrnoTemplExceptionEx<TBase, PErrstr>(*this);    }private:    int m_Errno;        ///< Error number};/////////////////////////////////////////////////////////////////////////////////// CErrnoTemplException --////// Define template class for easy generation of Errno-like exception classes.template<class TBase> class CErrnoTemplException :                        public CErrnoTemplExceptionEx<TBase, NCBI_STRERROR_WRAPPER>{public:    /// Parent class type.    typedef CErrnoTemplExceptionEx<TBase, NCBI_STRERROR_WRAPPER> CParent;    /// Constructor.    CErrnoTemplException<TBase>(const char* file,int line,        const CException* prev_exception,        typename CParent::EErrCode err_code,const string& message) throw()        : CParent(file, line, prev_exception,                 (typename CParent::EErrCode) CException::eInvalid, message)    NCBI_EXCEPTION_DEFAULT_IMPLEMENTATION_TEMPL(CErrnoTemplException<TBase>,                                                CParent)};/// Throw exception with extra parameter.////// Required to throw exceptions with one additional parameter/// (e.g. positional information for CParseException).#define NCBI_THROW2(exception_class, err_code, message, extra) \    throw exception_class(__FILE__, __LINE__, \        0,exception_class::err_code, (message), (extra))/// Re-throw exception with extra parameter.////// Required to re-throw exceptions with one additional parameter/// (e.g. positional information for CParseException).#define NCBI_RETHROW2(prev_exception,exception_class,err_code,message,extra) \    throw exception_class(__FILE__, __LINE__, \        &(prev_exception), exception_class::err_code, (message), (extra))/// Define exception default with one additional parameter.////// Required to define exception default with one additional parameter/// (e.g. derived from CParseException).#define NCBI_EXCEPTION_DEFAULT2(exception_class, base_class, extra_type) \public: \    exception_class(const char* file,int line, \        const CException* prev_exception, \        EErrCode err_code,const string& message, \        extra_type extra_param) throw() \        : base_class(file, line, prev_exception, \            (base_class::EErrCode) CException::eInvalid, \            (message), extra_param) \    NCBI_EXCEPTION_DEFAULT_IMPLEMENTATION(exception_class, base_class)END_NCBI_SCOPE/* @} *//* * =========================================================================== * $Log: ncbiexpt.hpp,v $ * Revision 1000.3  2004/06/01 19:08:02  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.54 * * Revision 1.54  2004/05/11 15:55:47  gouriano * Change GetErrCode method prototype to return TErrCode - to be able to * safely cast EErrCode to an eInvalid * * Revision 1.53  2004/04/30 11:26:06  kuznets * THROW spec macro disabled for MSVC (fixed some compiler warnings) * * Revision 1.52  2004/04/26 19:17:06  ucko * Some compilers specifically preferred wrapping strerror with a class, * so conditionalize use of a simple function on NCBI_COMPILER_GCC. * * Revision 1.51  2004/04/26 14:43:56  ucko * Handle GCC 3.4's stricter treatment of templates: * - Wrap strerror with an ordinary function rather than a static method. * - Qualify dependent names with "this->" as needed. * - Move CParseTemplException to ncbistr.hpp. * * Revision 1.50  2004/03/10 19:57:40  gorelenk * Added NCBI_XNCBI_EXPORT prefix to function DoThrowTraceAbort. * * Revision 1.49  2003/12/22 20:20:12  ivanov * Made all CException protected methods virtual * * Revision 1.48  2003/10/24 13:24:54  vasilche * Moved body of virtual method to *.cpp file. * * Revision 1.47  2003/08/01 15:17:21  siyan * Documentation changes. Removed superfluous (extra) * "public" keyword in CErrnoTemplException. * * Revision 1.46  2003/05/27 15:19:55  kuznets * Included <string.h> (declaration of 'strerror') * * Revision 1.45  2003/04/29 19:47:02  ucko * KLUDGE: avoid inlining CStrErrAdapt::strerror with GCC 2.95 on OSF/1, * due to a weird, apparently platform-specific, bug. * * Revision 1.44  2003/04/25 20:53:53  lavr * Add eInvalidArg type of CCoreException * * Revision 1.43  2003/04/24 16:25:32  kuznets * Farther templatefication of CErrnoTemplException, * added CErrnoTemplExceptionEx. * This will allow easy creation of Errno-like exception classes. * Added NCBI_EXCEPTION_DEFAULT_IMPLEMENTATION_TEMPL macro * (fixes some warning with templates compilation (gcc 3.2.2)). * * Revision 1.42  2003/03/31 16:40:21  siyan * Added doxygen support * * Revision 1.41  2003/02/24 19:54:52  gouriano * use template-based exceptions instead of errno and parse exceptions * * Revision 1.40  2003/02/14 19:31:23  gouriano * added definition of templates for errno and parse exceptions * * Revision 1.39  2002/12/18 22:53:21  dicuccio * Added export specifier for building DLLs in windows.  Added global list of * all such specifiers in mswin_exports.hpp, included through ncbistl.hpp * * Revision 1.38  2002/08/20 19:13:47  gouriano * added DiagPostFlags into CException reporting functions * * Revision 1.37  2002/08/06 14:08:30  gouriano * introduced EXCEPTION_VIRTUAL_BASE macro to make doc++ happy * * Revision 1.36  2002/07/31 18:32:04  gouriano * fix for virtual base classes * * Revision 1.35  2002/07/29 19:30:43  gouriano * changes to allow multiple inheritance in CException classes * * Revision 1.33  2002/07/15 18:17:51  gouriano * renamed CNcbiException and its descendents * * Revision 1.32  2002/07/11 19:33:11  gouriano * minor fix in NCBI_EXCEPTION_DEFAULT definition * * Revision 1.31  2002/07/11 14:17:54  gouriano * exceptions replaced by CNcbiException-type ones * * Revision 1.30  2002/06/27 18:55:32  gouriano * added "title" parameter to report functions * * Revision 1.29  2002/06/27 18:26:23  vakatov * Explicitly qualify "exception" with "std::" to avoid a silly name conflict * with <math.h> for SUN Forte6u2 compiler * * Revision 1.28  2002/06/26 18:36:36  gouriano * added CNcbiException class * * Revision 1.27  2002/04/11 20:39:17  ivanov * CVS log moved to end of the file * * Revision 1.26  2001/12/03 22:24:14  vakatov * Rollback R1.25 * * Revision 1.25  2001/12/03 22:03:37  juran * #include <corelib/ncbistl.hpp> * * Revision 1.24  2001/07/30 14:40:57  lavr * eDiag_Trace and eDiag_Fatal always print as much as possible * * Revision 1.23  2001/05/21 21:44:43  vakatov * SIZE_TYPE --> string::size_type * * Revision 1.22  2001/05/17 14:53:41  lavr * Typos corrected * * Revision 1.21  2000/04/04 22:30:25  vakatov * SetThrowTraceAbort() -- auto-set basing on the application * environment and/or registry * * Revision 1.20  1999/12/29 13:58:37  vasilche * Added THROWS_NONE. * * Revision 1.19  1999/12/28 21:04:14  vasilche * Removed three more implicit virtual destructors. * * Revision 1.18  1999/12/28 18:55:25  vasilche * Reduced size of compiled object files: * 1. avoid inline or implicit virtual methods (especially destructors). * 2. avoid std::string's methods usage in inline methods. * 3. avoid string literals ("xxx") in inline methods. * * Revision 1.17  1999/11/18 20:12:40  vakatov * DoDbgPrint() -- prototyped in both _DEBUG and NDEBUG * * Revision 1.16  1999/10/04 16:20:56  vasilche * Added full set of macros THROW*_TRACE * * Revision 1.15  1999/09/27 16:23:20  vasilche * Changed implementation of debugging macros (_TRACE, _THROW*, _ASSERT etc), * so that they will be much easier for compilers to eat. * * Revision 1.14  1999/09/23 21:15:48  vasilche * Added namespace modifiers. * * Revision 1.13  1999/06/11 16:33:10  vasilche * Fixed THROWx_TRACE * * Revision 1.12  1999/06/11 16:20:22  vasilche * THROW_TRACE fixed for not very smart compiler like Sunpro * * Revision 1.11  1999/06/11 02:48:03  vakatov * [_DEBUG] Refined the output from THROW*_TRACE macro * * Revision 1.10  1999/05/04 00:03:07  vakatov * Removed the redundant severity arg from macro ERR_POST() * * Revision 1.9  1999/01/07 16:15:09  vakatov * Explicitly specify "NCBI_NS_NCBI::" in the preprocessor macros * * Revision 1.8  1999/01/04 22:41:41  vakatov * Do not use so-called "hardware-exceptions" as these are not supported * (on the signal level) by UNIX * Do not "set_unexpected()" as it works differently on UNIX and MSVC++ * * Revision 1.7  1998/12/28 17:56:27  vakatov * New CVS and development tree structure for the NCBI C++ projects * * Revision 1.6  1998/12/01 01:19:47  vakatov * Moved <string> and <stdexcept> after the <ncbidiag.hpp> to avoid weird * conflicts under MSVC++ 6.0 * * Revision 1.5  1998/11/24 17:51:26  vakatov * + CParseException * Removed "Ncbi" sub-prefix from the NCBI exception class names * * Revision 1.4  1998/11/10 01:17:36  vakatov * Cleaned, adopted to the standard NCBI C++ framework and incorporated * the "hardware exceptions" code and tests(originally written by * V.Sandomirskiy). * Only tested for MSVC++ compiler yet -- to be continued for SunPro... * * Revision 1.3  1998/11/06 22:42:38  vakatov * Introduced BEGIN_, END_ and USING_ NCBI_SCOPE macros to put NCBI C++ * API to namespace "ncbi::" and to use it by default, respectively * Introduced THROWS_NONE and THROWS(x) macros for the exception * specifications * Other fixes and rearrangements throughout the most of "corelib" code * * ========================================================================== */#endif  /* NCBIEXPT__HPP */

⌨️ 快捷键说明

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