00001
00002
00003
00004
00005
00006
00007
00008
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
00036 enum error_category
00037 {
00039 native_ecat = ASIO_WIN_OR_POSIX(0, 0),
00040
00042 netdb_ecat = ASIO_WIN_OR_POSIX(native_ecat, 1),
00043
00045 addrinfo_ecat = ASIO_WIN_OR_POSIX(native_ecat, 2),
00046
00048 misc_ecat = ASIO_WIN_OR_POSIX(3, 3),
00049
00051 ssl_ecat = ASIO_WIN_OR_POSIX(4, 4)
00052 };
00053
00055 class error_code
00056 {
00057 public:
00059 typedef int value_type;
00060
00062 error_code()
00063 : value_(0),
00064 category_(native_ecat)
00065 {
00066 }
00067
00069 error_code(value_type v, error_category c)
00070 : value_(v),
00071 category_(c)
00072 {
00073 }
00074
00076 value_type value() const
00077 {
00078 return value_;
00079 }
00080
00082 error_category category() const
00083 {
00084 return category_;
00085 }
00086
00088 std::string message() const;
00089
00090 struct unspecified_bool_type_t
00091 {
00092 };
00093
00094 typedef unspecified_bool_type_t* unspecified_bool_type;
00095
00097 operator unspecified_bool_type() const
00098 {
00099 if (value_ == 0)
00100 return 0;
00101 else
00102 return reinterpret_cast<unspecified_bool_type>(1);
00103 }
00104
00106 bool operator!() const
00107 {
00108 return value_ == 0;
00109 }
00110
00112 friend bool operator==(const error_code& e1, const error_code& e2)
00113 {
00114 return e1.value_ == e2.value_ && e1.category_ == e2.category_;
00115 }
00116
00118 friend bool operator!=(const error_code& e1, const error_code& e2)
00119 {
00120 return e1.value_ != e2.value_ || e1.category_ != e2.category_;
00121 }
00122
00123 private:
00124
00125 value_type value_;
00126
00127
00128 error_category category_;
00129 };
00130
00131 }
00132
00133 #undef ASIO_WIN_OR_POSIX
00134
00135 #include "asio/error.hpp"
00136
00137 #include "asio/detail/pop_options.hpp"
00138
00139 #endif // ASIO_ERROR_CODE_HPP