// // error_handler.hpp // ~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2006 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // 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) // #ifndef BOOST_ASIO_ERROR_HANDLER_HPP #define BOOST_ASIO_ERROR_HANDLER_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include #include #include #include namespace boost { namespace asio { namespace detail { class ignore_error_t { public: typedef void result_type; template void operator()(const Error&) const { } }; class throw_error_t { public: typedef void result_type; template void operator()(const Error& err) const { if (err) boost::throw_exception(err); } }; template class assign_error_t { public: typedef void result_type; assign_error_t(Target& target) : target_(&target) { } template void operator()(const Error& err) const { *target_ = err; } private: Target* target_; }; } // namespace detail /** * @defgroup error_handler Error Handler Function Objects * * Function objects for custom error handling. */ /*@{*/ /// Return a function object that always ignores the error. #if defined(GENERATING_DOCUMENTATION) unspecified ignore_error(); #else inline detail::ignore_error_t ignore_error() { return detail::ignore_error_t(); } #endif /// Return a function object that always throws the error. #if defined(GENERATING_DOCUMENTATION) unspecified throw_error(); #else inline detail::throw_error_t throw_error() { return detail::throw_error_t(); } #endif /// Return a function object that assigns the error to a variable. #if defined(GENERATING_DOCUMENTATION) template unspecified assign_error(Target& target); #else template inline detail::assign_error_t assign_error(Target& target) { return detail::assign_error_t(target); } #endif /*@}*/ } // namespace asio } // namespace boost #include #endif // BOOST_ASIO_ERROR_HANDLER_HPP