123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- #ifndef ASIO_ERROR_CODE_HPP
- #define ASIO_ERROR_CODE_HPP
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- # pragma once
- #endif
- #include "asio/detail/config.hpp"
- #include <string>
- #if defined(GENERATING_DOCUMENTATION)
- # define ASIO_WIN_OR_POSIX(e_win, e_posix) implementation_defined
- #elif defined(BOOST_WINDOWS) || defined(__CYGWIN__)
- # define ASIO_WIN_OR_POSIX(e_win, e_posix) e_win
- #else
- # define ASIO_WIN_OR_POSIX(e_win, e_posix) e_posix
- #endif
- #include "asio/detail/push_options.hpp"
- namespace asio {
- namespace error
- {
-
- enum error_category
- {
-
- system_category = ASIO_WIN_OR_POSIX(0, 0),
-
- netdb_category = ASIO_WIN_OR_POSIX(system_category, 1),
-
- addrinfo_category = ASIO_WIN_OR_POSIX(system_category, 2),
-
- misc_category = ASIO_WIN_OR_POSIX(3, 3),
-
- ssl_category = ASIO_WIN_OR_POSIX(4, 4)
- };
-
- inline error_category get_system_category() { return system_category; }
- inline error_category get_netdb_category() { return netdb_category; }
- inline error_category get_addrinfo_category() { return addrinfo_category; }
- inline error_category get_misc_category() { return misc_category; }
- inline error_category get_ssl_category() { return ssl_category; }
- }
- typedef asio::error::error_category error_category;
- class error_code
- {
- public:
-
- typedef int value_type;
-
- error_code()
- : value_(0),
- category_(error::system_category)
- {
- }
-
- error_code(value_type v, error_category c)
- : value_(v),
- category_(c)
- {
- }
-
- template <typename ErrorEnum>
- error_code(ErrorEnum e)
- {
- *this = make_error_code(e);
- }
-
- value_type value() const
- {
- return value_;
- }
-
- error_category category() const
- {
- return category_;
- }
-
- ASIO_DECL std::string message() const;
- struct unspecified_bool_type_t
- {
- };
- typedef void (*unspecified_bool_type)(unspecified_bool_type_t);
- static void unspecified_bool_true(unspecified_bool_type_t) {}
-
- operator unspecified_bool_type() const
- {
- if (!value_)
- return 0;
- else
- return &error_code::unspecified_bool_true;
- }
-
- bool operator!() const
- {
- return !value_;
- }
-
- friend bool operator==(const error_code& e1, const error_code& e2)
- {
- return e1.value_ == e2.value_ && e1.category_ == e2.category_;
- }
-
- friend bool operator!=(const error_code& e1, const error_code& e2)
- {
- return e1.value_ != e2.value_ || e1.category_ != e2.category_;
- }
- private:
-
- value_type value_;
-
- error_category category_;
- };
- }
- #include "asio/detail/pop_options.hpp"
- #undef ASIO_WIN_OR_POSIX
- #if defined(ASIO_HEADER_ONLY)
- # include "asio/impl/error_code.ipp"
- #endif
- #endif
|