$search
00001 // 00002 // error_code.hpp 00003 // ~~~~~~~~~~~~~~ 00004 // 00005 // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com) 00006 // 00007 // Distributed under the Boost Software License, Version 1.0. (See accompanying 00008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 00009 // 00010 00011 #ifndef ASIO_ERROR_CODE_HPP 00012 #define ASIO_ERROR_CODE_HPP 00013 00014 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 00015 # pragma once 00016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 00017 00018 #include "asio/detail/push_options.hpp" 00019 00020 #include "asio/detail/push_options.hpp" 00021 #include <boost/config.hpp> 00022 #include <string> 00023 #include "asio/detail/pop_options.hpp" 00024 00025 #if defined(GENERATING_DOCUMENTATION) 00026 # define ASIO_WIN_OR_POSIX(e_win, e_posix) implementation_defined 00027 #elif defined(BOOST_WINDOWS) || defined(__CYGWIN__) 00028 # define ASIO_WIN_OR_POSIX(e_win, e_posix) e_win 00029 #else 00030 # define ASIO_WIN_OR_POSIX(e_win, e_posix) e_posix 00031 #endif 00032 00033 namespace asio { 00034 00035 namespace error 00036 { 00038 enum error_category 00039 { 00041 system_category = ASIO_WIN_OR_POSIX(0, 0), 00042 00044 netdb_category = ASIO_WIN_OR_POSIX(system_category, 1), 00045 00047 addrinfo_category = ASIO_WIN_OR_POSIX(system_category, 2), 00048 00050 misc_category = ASIO_WIN_OR_POSIX(3, 3), 00051 00053 ssl_category = ASIO_WIN_OR_POSIX(4, 4) 00054 }; 00055 00056 // Category getters. 00057 inline error_category get_system_category() { return system_category; } 00058 inline error_category get_netdb_category() { return netdb_category; } 00059 inline error_category get_addrinfo_category() { return addrinfo_category; } 00060 inline error_category get_misc_category() { return misc_category; } 00061 inline error_category get_ssl_category() { return ssl_category; } 00062 00063 } // namespace error 00064 00066 typedef asio::error::error_category error_category; 00067 00069 class error_code 00070 { 00071 public: 00073 typedef int value_type; 00074 00076 error_code() 00077 : value_(0), 00078 category_(error::system_category) 00079 { 00080 } 00081 00083 error_code(value_type v, error_category c) 00084 : value_(v), 00085 category_(c) 00086 { 00087 } 00088 00090 template <typename ErrorEnum> 00091 error_code(ErrorEnum e) 00092 { 00093 *this = make_error_code(e); 00094 } 00095 00097 value_type value() const 00098 { 00099 return value_; 00100 } 00101 00103 error_category category() const 00104 { 00105 return category_; 00106 } 00107 00109 std::string message() const; 00110 00111 struct unspecified_bool_type_t 00112 { 00113 }; 00114 00115 typedef void (*unspecified_bool_type)(unspecified_bool_type_t); 00116 00117 static void unspecified_bool_true(unspecified_bool_type_t) 00118 { 00119 } 00120 00122 operator unspecified_bool_type() const 00123 { 00124 if (value_ == 0) 00125 return 0; 00126 else 00127 return &error_code::unspecified_bool_true; 00128 } 00129 00131 bool operator!() const 00132 { 00133 return value_ == 0; 00134 } 00135 00137 friend bool operator==(const error_code& e1, const error_code& e2) 00138 { 00139 return e1.value_ == e2.value_ && e1.category_ == e2.category_; 00140 } 00141 00143 friend bool operator!=(const error_code& e1, const error_code& e2) 00144 { 00145 return e1.value_ != e2.value_ || e1.category_ != e2.category_; 00146 } 00147 00148 private: 00149 // The value associated with the error code. 00150 value_type value_; 00151 00152 // The category associated with the error code. 00153 error_category category_; 00154 }; 00155 00156 } // namespace asio 00157 00158 #undef ASIO_WIN_OR_POSIX 00159 00160 #include "asio/error.hpp" 00161 00162 #include "asio/detail/pop_options.hpp" 00163 00164 #endif // ASIO_ERROR_CODE_HPP