resolver_query_base.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // resolver_query_base.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2010 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_IP_RESOLVER_QUERY_BASE_HPP
  11. #define ASIO_IP_RESOLVER_QUERY_BASE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/push_options.hpp"
  16. #include "asio/detail/push_options.hpp"
  17. #include <boost/config.hpp>
  18. #include <boost/detail/workaround.hpp>
  19. #include "asio/detail/pop_options.hpp"
  20. #include "asio/detail/socket_types.hpp"
  21. namespace asio {
  22. namespace ip {
  23. /// The resolver_query_base class is used as a base for the
  24. /// basic_resolver_query class templates to provide a common place to define
  25. /// the flag constants.
  26. class resolver_query_base
  27. {
  28. public:
  29. #if defined(GENERATING_DOCUMENTATION)
  30. /// A bitmask type (C++ Std [lib.bitmask.types]).
  31. typedef unspecified flags;
  32. /// Determine the canonical name of the host specified in the query.
  33. static const flags canonical_name = implementation_defined;
  34. /// Indicate that returned endpoint is intended for use as a locally bound
  35. /// socket endpoint.
  36. static const flags passive = implementation_defined;
  37. /// Host name should be treated as a numeric string defining an IPv4 or IPv6
  38. /// address and no name resolution should be attempted.
  39. static const flags numeric_host = implementation_defined;
  40. /// Service name should be treated as a numeric string defining a port number
  41. /// and no name resolution should be attempted.
  42. static const flags numeric_service = implementation_defined;
  43. /// If the query protocol family is specified as IPv6, return IPv4-mapped
  44. /// IPv6 addresses on finding no IPv6 addresses.
  45. static const flags v4_mapped = implementation_defined;
  46. /// If used with v4_mapped, return all matching IPv6 and IPv4 addresses.
  47. static const flags all_matching = implementation_defined;
  48. /// Only return IPv4 addresses if a non-loopback IPv4 address is configured
  49. /// for the system. Only return IPv6 addresses if a non-loopback IPv6 address
  50. /// is configured for the system.
  51. static const flags address_configured = implementation_defined;
  52. #else
  53. enum flags
  54. {
  55. canonical_name = AI_CANONNAME,
  56. passive = AI_PASSIVE,
  57. numeric_host = AI_NUMERICHOST,
  58. # if defined(AI_NUMERICSERV)
  59. numeric_service = AI_NUMERICSERV,
  60. # else
  61. numeric_service = 0,
  62. # endif
  63. // Note: QNX Neutrino 6.3 defines AI_V4MAPPED, AI_ALL and AI_ADDRCONFIG but
  64. // does not implement them. Therefore they are specifically excluded here.
  65. # if defined(AI_V4MAPPED) && !defined(__QNXNTO__)
  66. v4_mapped = AI_V4MAPPED,
  67. # else
  68. v4_mapped = 0,
  69. # endif
  70. # if defined(AI_ALL) && !defined(__QNXNTO__)
  71. all_matching = AI_ALL,
  72. # else
  73. all_matching = 0,
  74. # endif
  75. # if defined(AI_ADDRCONFIG) && !defined(__QNXNTO__)
  76. address_configured = AI_ADDRCONFIG
  77. # else
  78. address_configured = 0
  79. # endif
  80. };
  81. // Implement bitmask operations as shown in C++ Std [lib.bitmask.types].
  82. friend flags operator&(flags x, flags y)
  83. {
  84. return static_cast<flags>(
  85. static_cast<unsigned int>(x) & static_cast<unsigned int>(y));
  86. }
  87. friend flags operator|(flags x, flags y)
  88. {
  89. return static_cast<flags>(
  90. static_cast<unsigned int>(x) | static_cast<unsigned int>(y));
  91. }
  92. friend flags operator^(flags x, flags y)
  93. {
  94. return static_cast<flags>(
  95. static_cast<unsigned int>(x) ^ static_cast<unsigned int>(y));
  96. }
  97. friend flags operator~(flags x)
  98. {
  99. return static_cast<flags>(static_cast<unsigned int>(~x));
  100. }
  101. friend flags& operator&=(flags& x, flags y)
  102. {
  103. x = x & y;
  104. return x;
  105. }
  106. friend flags& operator|=(flags& x, flags y)
  107. {
  108. x = x | y;
  109. return x;
  110. }
  111. friend flags& operator^=(flags& x, flags y)
  112. {
  113. x = x ^ y;
  114. return x;
  115. }
  116. #endif
  117. protected:
  118. /// Protected destructor to prevent deletion through this type.
  119. ~resolver_query_base()
  120. {
  121. }
  122. #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
  123. private:
  124. // Workaround to enable the empty base optimisation with Borland C++.
  125. char dummy_;
  126. #endif
  127. };
  128. } // namespace ip
  129. } // namespace asio
  130. #include "asio/detail/pop_options.hpp"
  131. #endif // ASIO_IP_RESOLVER_QUERY_BASE_HPP