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

📄 warerror.h

📁 ftpserver very good sample
💻 H
字号:
/** @name Error handling *//*@{ */#ifndef WAR_ERROR_H#define WAR_ERROR_H/* SYSTEM INCLUDES */#ifdef __cplusplus#  include <string>#endif#if WAR_CRYPTO && !defined(WAR_OPENSSL_ERR_H_INCLUDED)#   define WAR_OPENSSL_ERR_H_INCLUDED#   include <openssl/err.h>#endif/* PROJECT INCLUDES *//* LOCAL INCLUDES */#include "WarErrorCodes.h"/* FORWARD REFERENCES */#ifdef __cplusplusextern "C"{#endif/****************** BEGIN OLD STYLE C spesific ********//** Basetype for error values */struct war_error_def{    /** The library spesific error code */    int mLocalError;        /** The system error (errno) */    int mSystemError;        /** The source file where the error occured or was trapped */    war_ccstr_t mpSourceFile;            /** The line in the source file where the error occured or was trapped */    int mSourceLine;};    /** C error type */typedef struct war_error_def war_error_t;/** strerror() substitute    #include "WarErrorCodes.h"    @memo This implementation will try to explain          errors which lacks an explanation in the          standard C library (like Winsock errors).    @param err_no The error to decode    @param pBuffer to store the error message.           If no text is available, the buffer is clered.    @param BufferLength length of the text buffer,           including 1 byte for trailing NUL     @return pointer to a error string, or an empth string*/war_ccstr_t war_get_system_error_text(const int err_no, 				      war_cstr_t buffer, 				      const size_t buffer_length);/** strerror() substitute for jgaa library and     application spesific error codes         #include "WarErrorCodes.h"    @param err_no The error to decode         @return pointer to a error string, or an empth string*/war_ccstr_t war_get_local_error_text(const int err_no);/****************** END OLD STYLE C spesific **********/#ifdef __cplusplus}#endif/****************** BEGIN C++ spesific ****************/#ifdef __cplusplus/** Error state container class  *   * #include "WarErrorCodes.h"  */class WarError{public:    // LIFECYCLE    /**     * Default constructor.     * @param system_error, Default is 0     * @param local_error, Default is no error     * @param source_file the source code file setting     the error. This buffer must be static whithin     the application.     * @param source_line the line in the source file        setting the error     */    WarError(const war_error_definitions local_error = WAR_ERR_OK,             const int system_error = 0,             war_ccstr_t source_file = __FILE__,             const int source_line = __LINE__);    /**     * Copy constructor.     *     * @param from The value to copy to this object.     */    inline WarError(const WarError& from)        : mpSpecialExplanation(NULL)    {        operator=(from);    }    /**     * Destructor.     */    virtual ~WarError() throw();    // OPERATORS    /**     * Assignment operator.     *     * @param from The value to assign to this object.     *     * @return A reference to this object.     */    WarError& operator=(const WarError& from);    /**     * Assignment operator.     *     * @param from The value to assign to this object.     *     * @return A reference to this object.     */    WarError& operator=(const int system_error);    /**     * Assignment operator.     *     * @param from The value to assign to this object.     *     * @return A reference to this object.     */    WarError& operator=(const war_error_t& from);    /**     * Assignment operator.     *     * @param from The value to assign to this object.     *     * @return A reference to this object.     */    WarError& operator=        (const war_error_definitions local_error);    /**     * Equal operator.     *     * @param local_error The value to compare to this object.     *     * @return true if local_error equals the local error,     *	 else false.     */    inline bool operator==(        const war_error_definitions local_error) const    {        return mLocalError == local_error;    };    /**     * Equal operator.     *     * @param local_error The value to compare to this object.     *     * @return true if local_error equals the local error,     *	 else false.     */    inline bool operator!=(        const war_error_definitions local_error) const    {        return mLocalError != local_error;    };    // OPERATIONS    /** Capture the current system error      *       * The syste error is not reset by this      * operation.      *      * Note that the local error is set by default anyway,      * in case a system error occures without giving      * nonzero error value.      *      * Also note that system-errors can relay from      * previous error-conditions!      *      * @param local_error Set the local error.       *  This is requiered, as the local error is tested      *  to check the error state of the object.      *  The default is WAR_ERR_SYSTEM_ERROR      * @return A reference to this object.      */    const WarError& Capture(        const war_error_definitions local_error = WAR_ERR_SYSTEM_ERROR);    /**      * Explain an error      *      * @return a string with an explanation of the error in the format:      *   \begin{verbatim}Error local#/system# [Library error text] [optional System error text]\end{verbatim}      */    virtual const std::string& Explain() const;    // CALLBACK    virtual void OnExplainSystemError(std::string& appendExplanation) const;    // ACCESS    /**     * Gets the system error code (errno)     *     * @return the system error code     */    inline int SystemError() const    {        return mSystemError;    } ;    /**     * Gets the local error code     *     * @return the error code     */    inline war_error_definitions LocalError() const    {        return mLocalError;    };    /**     * Gets the source file where the error was created     *     * @return the error code     */    inline war_ccstr_t GetFile() const    {        return mpSourceFile;    };    /**     * Gets the local error code     *     * @return the error code     */    inline int GetLine() const    {        return mSourceLine;    };    /** Return true if there is an error-state */    inline operator bool() const    {        return mLocalError != WAR_ERR_OK;    } ;    /** Reset to no error */    void Reset()    {        mLocalError = WAR_ERR_OK;        mSystemError = 0;        mpSourceFile = "";        mSourceLine = 0;        if (mpSpecialExplanation)            delete mpSpecialExplanation;        mpSpecialExplanation = NULL;    }    // INQUIRYprotected:    char *mpSpecialExplanation;    /** Stored error message (after calling Explain() */    std::string mMessageBuf;private:    /** The library spesific error code */    war_error_definitions mLocalError;        /** The system error (errno) */    int mSystemError;        /** The source file where the error occured    or was trapped */    war_ccstr_t mpSourceFile;        /** The line in the source file where the    error occured or was trapped */    int mSourceLine;};class WarSystemError : public WarError{public:    WarSystemError(const war_error_definitions local_error = WAR_ERR_SYSTEM_ERROR)    {        Capture(local_error);    }};#if WAR_CRYPTOclass WarOpenSslError :public WarError{public:    WarOpenSslError(const war_error_definitions local_error = WAR_ERR_SYSTEM_ERROR)        : WarError(local_error, ERR_get_error())    {        std::string expl;        OnExplainSystemError(expl);        mpSpecialExplanation = new char[expl.size() +1];        strcpy(mpSpecialExplanation, expl.c_str());    }        virtual void OnExplainSystemError(std::string& appendExplanation) const    {        appendExplanation += " [";        appendExplanation += ERR_error_string(SystemError(), NULL);        appendExplanation += " ]";    }};#endif // WAR_CRYPTO// INLINE METHODS//// EXTERNAL REFERENCES//#endif // __cplusplus/****************** END C++ spesific ******************/#endif  /* WAR_ERROR_H *//*@}*/

⌨️ 快捷键说明

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