Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:52:42

0001 //  (C) Copyright Gennadiy Rozental 2001.
0002 //  Distributed under the Boost Software License, Version 1.0.
0003 //  (See accompanying file LICENSE_1_0.txt or copy at
0004 //  http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 //  See http://www.boost.org/libs/test for the library home page.
0007 //
0008 //  File        : $RCSfile$
0009 //
0010 //  Version     : $Revision$
0011 //
0012 //  Description : defines runtime parameters setup error
0013 // ***************************************************************************
0014 
0015 #ifndef BOOST_TEST_UTILS_RUNTIME_INIT_ERROR_HPP
0016 #define BOOST_TEST_UTILS_RUNTIME_INIT_ERROR_HPP
0017 
0018 // Boost.Test Runtime parameters
0019 #include <boost/test/utils/runtime/fwd.hpp>
0020 
0021 // Boost.Test
0022 #include <boost/test/utils/string_cast.hpp>
0023 
0024 // Boost.Test
0025 #include <boost/config.hpp>
0026 
0027 // STL
0028 #include <exception>
0029 #include <vector>
0030 
0031 #include <boost/test/detail/suppress_warnings.hpp>
0032 
0033 namespace boost {
0034 namespace runtime {
0035 
0036 // ************************************************************************** //
0037 // **************             runtime::param_error             ************** //
0038 // ************************************************************************** //
0039 
0040 class BOOST_SYMBOL_VISIBLE param_error : public std::exception {
0041 public:
0042     BOOST_TEST_DEFAULTED_FUNCTION(~param_error() BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE, {})
0043 
0044     const char * what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE
0045     {
0046         return msg.c_str();
0047     }
0048 
0049     cstring     param_name;
0050     std::string msg;
0051 
0052 protected:
0053     explicit    param_error( cstring param_name_ ) : param_name( param_name_) {}
0054 };
0055 
0056 //____________________________________________________________________________//
0057 
0058 class BOOST_SYMBOL_VISIBLE init_error : public param_error {
0059 protected:
0060     explicit    init_error( cstring param_name ) : param_error( param_name ) {}
0061     BOOST_TEST_DEFAULTED_FUNCTION(~init_error() BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE, {})
0062 };
0063 
0064 class BOOST_SYMBOL_VISIBLE input_error : public param_error {
0065 protected:
0066     explicit    input_error( cstring param_name ) : param_error( param_name ) {}
0067     BOOST_TEST_DEFAULTED_FUNCTION(~input_error() BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE, {})
0068 };
0069 
0070 //____________________________________________________________________________//
0071 
0072 template<typename Derived, typename Base>
0073 class BOOST_SYMBOL_VISIBLE specific_param_error : public Base {
0074 protected:
0075     explicit    specific_param_error( cstring param_name ) : Base( param_name ) {}
0076     BOOST_TEST_DEFAULTED_FUNCTION(~specific_param_error() BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE, {})
0077 
0078 public:
0079 
0080 //____________________________________________________________________________//
0081 
0082 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
0083     !defined(BOOST_NO_CXX11_REF_QUALIFIERS)
0084 
0085     Derived operator<<(char const* val) &&
0086     {
0087         this->msg.append( val );
0088 
0089         return static_cast<Derived&&>(*this);
0090     }
0091 
0092     //____________________________________________________________________________//
0093 
0094     template<typename T>
0095     Derived operator<<(T const& val) &&
0096     {
0097         this->msg.append( unit_test::utils::string_cast( val ) );
0098 
0099         return static_cast<Derived&&>(*this);
0100     }
0101 
0102     //____________________________________________________________________________//
0103 
0104 #else
0105 
0106     Derived const& operator<<(char const* val) const
0107     {
0108         const_cast<specific_param_error<Derived, Base>&>(*this).msg.append( val );
0109 
0110         return static_cast<Derived const&>(*this);
0111     }
0112 
0113     //____________________________________________________________________________//
0114 
0115     template<typename T>
0116     Derived const& operator<<(T const& val) const
0117     {
0118         const_cast<specific_param_error<Derived, Base>&>(*this).msg.append( unit_test::utils::string_cast( val ) );
0119 
0120         return static_cast<Derived const&>(*this);
0121     }
0122 
0123     //____________________________________________________________________________//
0124 
0125 #endif
0126 
0127 };
0128 
0129 
0130 
0131 // ************************************************************************** //
0132 // **************           specific exception types           ************** //
0133 // ************************************************************************** //
0134 
0135 #define SPECIFIC_EX_TYPE( type, base )                  \
0136 class BOOST_SYMBOL_VISIBLE type : public specific_param_error<type,base> {   \
0137 public:                                                 \
0138     explicit type( cstring param_name = cstring() )     \
0139     : specific_param_error<type,base>( param_name )     \
0140     {}                                                  \
0141 }                                                       \
0142 /**/
0143 
0144 SPECIFIC_EX_TYPE( invalid_cla_id, init_error );
0145 SPECIFIC_EX_TYPE( duplicate_param, init_error );
0146 SPECIFIC_EX_TYPE( conflicting_param, init_error );
0147 SPECIFIC_EX_TYPE( unknown_param, init_error );
0148 SPECIFIC_EX_TYPE( access_to_missing_argument, init_error );
0149 SPECIFIC_EX_TYPE( arg_type_mismatch, init_error );
0150 SPECIFIC_EX_TYPE( invalid_param_spec, init_error );
0151 
0152 SPECIFIC_EX_TYPE( format_error, input_error );
0153 SPECIFIC_EX_TYPE( duplicate_arg, input_error );
0154 SPECIFIC_EX_TYPE( missing_req_arg, input_error );
0155 
0156 #undef SPECIFIC_EX_TYPE
0157 
0158 class BOOST_SYMBOL_VISIBLE ambiguous_param : public specific_param_error<ambiguous_param, input_error> {
0159 public:
0160 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
0161     explicit    ambiguous_param( std::vector<cstring>&& amb_candidates )
0162     : specific_param_error<ambiguous_param,input_error>( "" )
0163     , m_amb_candidates( std::move( amb_candidates ) ) {}
0164 #else
0165     explicit    ambiguous_param( std::vector<cstring> const& amb_candidates )
0166     : specific_param_error<ambiguous_param,input_error>( "" )
0167     , m_amb_candidates( amb_candidates ) {}
0168 #endif
0169     BOOST_TEST_DEFAULTED_FUNCTION(~ambiguous_param() BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE, {})
0170 
0171     std::vector<cstring> m_amb_candidates;
0172 };
0173 
0174 class BOOST_SYMBOL_VISIBLE unrecognized_param : public specific_param_error<unrecognized_param, input_error> {
0175 public:
0176 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
0177     explicit    unrecognized_param( std::vector<cstring>&& type_candidates )
0178     : specific_param_error<unrecognized_param,input_error>( "" )
0179     , m_typo_candidates( std::move( type_candidates ) ) {}
0180 #else
0181     explicit    unrecognized_param( std::vector<cstring> const& type_candidates )
0182     : specific_param_error<unrecognized_param,input_error>( "" )
0183     , m_typo_candidates( type_candidates ) {}
0184 #endif
0185     BOOST_TEST_DEFAULTED_FUNCTION(~unrecognized_param(), BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE {})
0186 
0187     std::vector<cstring> m_typo_candidates;
0188 };
0189 
0190 } // namespace runtime
0191 } // namespace boost
0192 
0193 #include <boost/test/detail/enable_warnings.hpp>
0194 
0195 #endif // BOOST_TEST_UTILS_RUNTIME_INIT_ERROR_HPP