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

📄 cpp_exceptions.hpp

📁 support vector clustering for vc++
💻 HPP
📖 第 1 页 / 共 2 页
字号:
/*=============================================================================
    Boost.Wave: A Standard compliant C++ preprocessor library

    http://www.boost.org/

    Copyright (c) 2001-2007 Hartmut Kaiser. Distributed under the Boost
    Software License, Version 1.0. (See accompanying file
    LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/

#if !defined(CPP_EXCEPTIONS_HPP_5190E447_A781_4521_A275_5134FF9917D7_INCLUDED)
#define CPP_EXCEPTIONS_HPP_5190E447_A781_4521_A275_5134FF9917D7_INCLUDED

#include <exception>
#include <string>
#include <limits>

#include <boost/assert.hpp>
#include <boost/config.hpp>
#include <boost/throw_exception.hpp>
#include <boost/wave/wave_config.hpp>
#include <boost/wave/cpp_throw.hpp>

// this must occur after all of the includes and before any code appears
#ifdef BOOST_HAS_ABI_HEADERS
#include BOOST_ABI_PREFIX
#endif

///////////////////////////////////////////////////////////////////////////////
namespace boost {
namespace wave {

///////////////////////////////////////////////////////////////////////////////
// exception severity
namespace util {

    enum severity {
        severity_remark = 0,
        severity_warning,
        severity_error,
        severity_fatal,
        severity_commandline_error,
        last_severity_code = severity_commandline_error
    };
    
    inline char const *
    get_severity(int level) 
    {
        static char const *severity_text[] = 
        {
            "remark",               // severity_remark
            "warning",              // severity_warning
            "error",                // severity_error
            "fatal error",          // severity_fatal
            "command line error"    // severity_commandline_error
        };
        BOOST_ASSERT(severity_remark <= level && 
            level <= last_severity_code);
        return severity_text[level];
    }
}

///////////////////////////////////////////////////////////////////////////////
//  cpp_exception, the base class for all specific C preprocessor exceptions 
class cpp_exception
:   public std::exception
{
public:
    cpp_exception(int line_, int column_, char const *filename_) throw() 
    :   line(line_), column(column_) 
    {
        unsigned int off = 0;
        while (off < sizeof(filename)-1 && *filename_)
            filename[off++] = *filename_++;
        filename[off] = 0;
    }
    ~cpp_exception() throw() {}
    
    virtual char const *what() const throw() = 0;           // to be overloaded
    virtual char const *description() const throw() = 0;
    virtual int get_errorcode() const throw() = 0;
    virtual int get_severity() const throw() = 0;
    virtual char const* get_related_name() const throw() = 0;
    virtual bool is_recoverable() const throw() = 0;
    
    int line_no() const throw() { return line; }
    int column_no() const throw() { return column; }
    char const *file_name() const throw() { return filename; }
    
protected:
    char filename[512];
    int line;
    int column;
};

///////////////////////////////////////////////////////////////////////////////
// preprocessor error
class preprocess_exception :
    public cpp_exception
{
public:
    enum error_code {
        no_error = 0,
        unexpected_error,
        macro_redefinition,
        macro_insertion_error,
        bad_include_file,
        bad_include_statement,
        ill_formed_directive,
        error_directive,
        warning_directive,
        ill_formed_expression,
        missing_matching_if,
        missing_matching_endif,
        ill_formed_operator,
        bad_define_statement,
        bad_define_statement_va_args,
        too_few_macroarguments,
        too_many_macroarguments,
        empty_macroarguments,
        improperly_terminated_macro,
        bad_line_statement,
        bad_line_number,
        bad_line_filename,
        bad_undefine_statement,
        bad_macro_definition,
        illegal_redefinition,
        duplicate_parameter_name,
        invalid_concat,
        last_line_not_terminated,
        ill_formed_pragma_option,
        include_nesting_too_deep,
        misplaced_operator,
        alreadydefined_name,
        undefined_macroname,
        invalid_macroname,
        unexpected_qualified_name,
        division_by_zero,
        integer_overflow,
        illegal_operator_redefinition,
        ill_formed_integer_literal,
        ill_formed_character_literal,
        unbalanced_if_endif,
        character_literal_out_of_range,
        could_not_open_output_file,
        incompatible_config,
        ill_formed_pragma_message,
        pragma_message_directive,
        last_error_number = pragma_message_directive
    };

    preprocess_exception(char const *what_, error_code code, int line_, 
        int column_, char const *filename_) throw() 
    :   cpp_exception(line_, column_, filename_), 
        code(code)
    {
        unsigned int off = 0;
        while (off < sizeof(buffer) && *what_)
            buffer[off++] = *what_++;
        buffer[off] = 0;
    }
    ~preprocess_exception() throw() {}
    
    virtual char const *what() const throw()
    {
        return "boost::wave::preprocess_exception";
    }
    virtual char const *description() const throw()
    {
        return buffer;
    }
    virtual int get_severity() const throw()
    {
        return severity_level(code);
    }
    virtual int get_errorcode() const throw()
    {
        return code;
    }
    virtual char const* get_related_name() const throw()
    {
        return "<unknown>";
    }
    virtual bool is_recoverable() const throw()
    {
        switch (get_errorcode()) {
        // these are the exceptions thrown during processing not supposed to 
        // produce any tokens on the context::iterator level
        case preprocess_exception::no_error:        // just a placeholder
        case preprocess_exception::macro_redefinition:
        case preprocess_exception::macro_insertion_error:
        case preprocess_exception::bad_macro_definition:
        case preprocess_exception::illegal_redefinition:
        case preprocess_exception::duplicate_parameter_name:
        case preprocess_exception::invalid_macroname:
        case preprocess_exception::bad_include_file:
        case preprocess_exception::bad_include_statement:
        case preprocess_exception::ill_formed_directive:
        case preprocess_exception::error_directive:
        case preprocess_exception::warning_directive:
        case preprocess_exception::ill_formed_expression:
        case preprocess_exception::missing_matching_if:
        case preprocess_exception::missing_matching_endif:
        case preprocess_exception::unbalanced_if_endif:
        case preprocess_exception::bad_define_statement:
        case preprocess_exception::bad_define_statement_va_args:
        case preprocess_exception::bad_line_statement:
        case preprocess_exception::bad_line_number:
        case preprocess_exception::bad_line_filename:
        case preprocess_exception::bad_undefine_statement:
        case preprocess_exception::division_by_zero:

⌨️ 快捷键说明

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