1 // (C) Copyright Gennadiy Rozental 2001.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/test for the library home page.
10 // Version : $Revision$
12 // Description : defines runtime parameters setup error
13 // ***************************************************************************
15 #ifndef BOOST_TEST_UTILS_RUNTIME_INIT_ERROR_HPP
16 #define BOOST_TEST_UTILS_RUNTIME_INIT_ERROR_HPP
18 // Boost.Test Runtime parameters
19 #include <boost/test/utils/runtime/fwd.hpp>
22 #include <boost/test/utils/string_cast.hpp>
25 #include <boost/config.hpp>
31 #include <boost/test/detail/suppress_warnings.hpp>
36 // ************************************************************************** //
37 // ************** runtime::param_error ************** //
38 // ************************************************************************** //
40 class BOOST_SYMBOL_VISIBLE param_error : public std::exception {
42 ~param_error() BOOST_NOEXCEPT_OR_NOTHROW {}
44 virtual const char * what() const BOOST_NOEXCEPT_OR_NOTHROW
53 explicit param_error( cstring param_name_ ) : param_name( param_name_) {}
56 //____________________________________________________________________________//
58 class BOOST_SYMBOL_VISIBLE init_error : public param_error {
60 explicit init_error( cstring param_name ) : param_error( param_name ) {}
61 ~init_error() BOOST_NOEXCEPT_OR_NOTHROW {}
64 class BOOST_SYMBOL_VISIBLE input_error : public param_error {
66 explicit input_error( cstring param_name ) : param_error( param_name ) {}
67 ~input_error() BOOST_NOEXCEPT_OR_NOTHROW {}
70 //____________________________________________________________________________//
72 template<typename Derived, typename Base>
73 class BOOST_SYMBOL_VISIBLE specific_param_error : public Base {
75 explicit specific_param_error( cstring param_name ) : Base( param_name ) {}
76 ~specific_param_error() BOOST_NOEXCEPT_OR_NOTHROW {}
80 //____________________________________________________________________________//
82 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
83 !defined(BOOST_NO_CXX11_REF_QUALIFIERS)
85 Derived operator<<(char const* val) &&
87 this->msg.append( val );
89 return static_cast<Derived&&>(*this);
92 //____________________________________________________________________________//
95 Derived operator<<(T const& val) &&
97 this->msg.append( unit_test::utils::string_cast( val ) );
99 return static_cast<Derived&&>(*this);
102 //____________________________________________________________________________//
106 Derived const& operator<<(char const* val) const
108 const_cast<specific_param_error<Derived, Base>&>(*this).msg.append( val );
110 return static_cast<Derived const&>(*this);
113 //____________________________________________________________________________//
116 Derived const& operator<<(T const& val) const
118 const_cast<specific_param_error<Derived, Base>&>(*this).msg.append( unit_test::utils::string_cast( val ) );
120 return static_cast<Derived const&>(*this);
123 //____________________________________________________________________________//
131 // ************************************************************************** //
132 // ************** specific exception types ************** //
133 // ************************************************************************** //
135 #define SPECIFIC_EX_TYPE( type, base ) \
136 class BOOST_SYMBOL_VISIBLE type : public specific_param_error<type,base> { \
138 explicit type( cstring param_name = cstring() ) \
139 : specific_param_error<type,base>( param_name ) \
144 SPECIFIC_EX_TYPE( invalid_cla_id, init_error );
145 SPECIFIC_EX_TYPE( duplicate_param, init_error );
146 SPECIFIC_EX_TYPE( conflicting_param, init_error );
147 SPECIFIC_EX_TYPE( unknown_param, init_error );
148 SPECIFIC_EX_TYPE( access_to_missing_argument, init_error );
149 SPECIFIC_EX_TYPE( arg_type_mismatch, init_error );
150 SPECIFIC_EX_TYPE( invalid_param_spec, init_error );
152 SPECIFIC_EX_TYPE( format_error, input_error );
153 SPECIFIC_EX_TYPE( duplicate_arg, input_error );
154 SPECIFIC_EX_TYPE( missing_req_arg, input_error );
156 #undef SPECIFIC_EX_TYPE
158 class BOOST_SYMBOL_VISIBLE ambiguous_param : public specific_param_error<ambiguous_param, input_error> {
160 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
161 explicit ambiguous_param( std::vector<cstring>&& amb_candidates )
162 : specific_param_error<ambiguous_param,input_error>( "" )
163 , m_amb_candidates( std::move( amb_candidates ) ) {}
165 explicit ambiguous_param( std::vector<cstring> const& amb_candidates )
166 : specific_param_error<ambiguous_param,input_error>( "" )
167 , m_amb_candidates( amb_candidates ) {}
169 ~ambiguous_param() BOOST_NOEXCEPT_OR_NOTHROW {}
171 std::vector<cstring> m_amb_candidates;
174 class BOOST_SYMBOL_VISIBLE unrecognized_param : public specific_param_error<unrecognized_param, input_error> {
176 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
177 explicit unrecognized_param( std::vector<cstring>&& type_candidates )
178 : specific_param_error<unrecognized_param,input_error>( "" )
179 , m_typo_candidates( std::move( type_candidates ) ) {}
181 explicit unrecognized_param( std::vector<cstring> const& type_candidates )
182 : specific_param_error<unrecognized_param,input_error>( "" )
183 , m_typo_candidates( type_candidates ) {}
185 ~unrecognized_param() BOOST_NOEXCEPT_OR_NOTHROW {}
187 std::vector<cstring> m_typo_candidates;
190 } // namespace runtime
193 #include <boost/test/detail/enable_warnings.hpp>
195 #endif // BOOST_TEST_UTILS_RUNTIME_INIT_ERROR_HPP