Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

error_code.hpp 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. //
  2. // error_code.hpp
  3. // ~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef ASIO_ERROR_CODE_HPP
  11. #define ASIO_ERROR_CODE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #if defined(ASIO_HAS_STD_SYSTEM_ERROR)
  17. # include <system_error>
  18. #else // defined(ASIO_HAS_STD_SYSTEM_ERROR)
  19. # include <string>
  20. # include "asio/detail/noncopyable.hpp"
  21. # if !defined(ASIO_NO_IOSTREAM)
  22. # include <iosfwd>
  23. # endif // !defined(ASIO_NO_IOSTREAM)
  24. #endif // defined(ASIO_HAS_STD_SYSTEM_ERROR)
  25. #include "asio/detail/push_options.hpp"
  26. namespace asio {
  27. #if defined(ASIO_HAS_STD_SYSTEM_ERROR)
  28. typedef std::error_category error_category;
  29. #else // defined(ASIO_HAS_STD_SYSTEM_ERROR)
  30. /// Base class for all error categories.
  31. class error_category : private noncopyable
  32. {
  33. public:
  34. /// Destructor.
  35. virtual ~error_category()
  36. {
  37. }
  38. /// Returns a string naming the error gategory.
  39. virtual const char* name() const = 0;
  40. /// Returns a string describing the error denoted by @c value.
  41. virtual std::string message(int value) const = 0;
  42. /// Equality operator to compare two error categories.
  43. bool operator==(const error_category& rhs) const
  44. {
  45. return this == &rhs;
  46. }
  47. /// Inequality operator to compare two error categories.
  48. bool operator!=(const error_category& rhs) const
  49. {
  50. return !(*this == rhs);
  51. }
  52. };
  53. #endif // defined(ASIO_HAS_STD_SYSTEM_ERROR)
  54. /// Returns the error category used for the system errors produced by asio.
  55. extern ASIO_DECL const error_category& system_category();
  56. #if defined(ASIO_HAS_STD_SYSTEM_ERROR)
  57. typedef std::error_code error_code;
  58. #else // defined(ASIO_HAS_STD_SYSTEM_ERROR)
  59. /// Class to represent an error code value.
  60. class error_code
  61. {
  62. public:
  63. /// Default constructor.
  64. error_code()
  65. : value_(0),
  66. category_(&system_category())
  67. {
  68. }
  69. /// Construct with specific error code and category.
  70. error_code(int v, const error_category& c)
  71. : value_(v),
  72. category_(&c)
  73. {
  74. }
  75. /// Construct from an error code enum.
  76. template <typename ErrorEnum>
  77. error_code(ErrorEnum e)
  78. {
  79. *this = make_error_code(e);
  80. }
  81. /// Get the error value.
  82. int value() const
  83. {
  84. return value_;
  85. }
  86. /// Get the error category.
  87. const error_category& category() const
  88. {
  89. return *category_;
  90. }
  91. /// Get the message associated with the error.
  92. std::string message() const
  93. {
  94. return category_->message(value_);
  95. }
  96. struct unspecified_bool_type_t
  97. {
  98. };
  99. typedef void (*unspecified_bool_type)(unspecified_bool_type_t);
  100. static void unspecified_bool_true(unspecified_bool_type_t) {}
  101. /// Operator returns non-null if there is a non-success error code.
  102. operator unspecified_bool_type() const
  103. {
  104. if (value_ == 0)
  105. return 0;
  106. else
  107. return &error_code::unspecified_bool_true;
  108. }
  109. /// Operator to test if the error represents success.
  110. bool operator!() const
  111. {
  112. return value_ == 0;
  113. }
  114. /// Equality operator to compare two error objects.
  115. friend bool operator==(const error_code& e1, const error_code& e2)
  116. {
  117. return e1.value_ == e2.value_ && e1.category_ == e2.category_;
  118. }
  119. /// Inequality operator to compare two error objects.
  120. friend bool operator!=(const error_code& e1, const error_code& e2)
  121. {
  122. return e1.value_ != e2.value_ || e1.category_ != e2.category_;
  123. }
  124. private:
  125. // The value associated with the error code.
  126. int value_;
  127. // The category associated with the error code.
  128. const error_category* category_;
  129. };
  130. # if !defined(ASIO_NO_IOSTREAM)
  131. /// Output an error code.
  132. template <typename Elem, typename Traits>
  133. std::basic_ostream<Elem, Traits>& operator<<(
  134. std::basic_ostream<Elem, Traits>& os, const error_code& ec)
  135. {
  136. os << ec.category().name() << ':' << ec.value();
  137. return os;
  138. }
  139. # endif // !defined(ASIO_NO_IOSTREAM)
  140. #endif // defined(ASIO_HAS_STD_SYSTEM_ERROR)
  141. } // namespace asio
  142. #include "asio/detail/pop_options.hpp"
  143. #if defined(ASIO_HEADER_ONLY)
  144. # include "asio/impl/error_code.ipp"
  145. #endif // defined(ASIO_HEADER_ONLY)
  146. #endif // ASIO_ERROR_CODE_HPP