kind.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/json
  8. //
  9. #ifndef BOOST_JSON_KIND_HPP
  10. #define BOOST_JSON_KIND_HPP
  11. #include <boost/json/detail/config.hpp>
  12. #include <boost/json/string_view.hpp>
  13. #include <iosfwd>
  14. BOOST_JSON_NS_BEGIN
  15. /** Constants for identifying the type of a value
  16. These values are returned from @ref value::kind
  17. */
  18. // Order matters
  19. enum class kind : unsigned char
  20. {
  21. /// The null value.
  22. null,
  23. /// A `bool`.
  24. bool_,
  25. /// A `std::int64_t`
  26. int64,
  27. /// A `std::uint64_t`
  28. uint64,
  29. /// A `double`.
  30. double_,
  31. /// A @ref string.
  32. string,
  33. /// An @ref array.
  34. array,
  35. /// An @ref object.
  36. object
  37. };
  38. /** Return a string representing a kind.
  39. This provides a human-readable string
  40. representing a @ref kind. This may be
  41. useful for diagnostics.
  42. @returns The string.
  43. @param k The kind.
  44. */
  45. BOOST_JSON_DECL
  46. string_view
  47. to_string(kind k) noexcept;
  48. /** Format a kind to an output stream.
  49. This allows a @ref kind to be formatted as
  50. a string, typically for diagnostics.
  51. @returns The output stream.
  52. @param os The output stream to format to.
  53. @param k The kind to format.
  54. */
  55. BOOST_JSON_DECL
  56. std::ostream&
  57. operator<<(std::ostream& os, kind k);
  58. /** A tag type used to select a @ref value constructor overload.
  59. The library provides the constant @ref array_kind
  60. which may be used to select the @ref value constructor
  61. that creates an empty @ref array.
  62. @see @ref array_kind
  63. */
  64. struct array_kind_t
  65. {
  66. };
  67. /** A tag type used to select a @ref value constructor overload.
  68. The library provides the constant @ref object_kind
  69. which may be used to select the @ref value constructor
  70. that creates an empty @ref object.
  71. @see @ref object_kind
  72. */
  73. struct object_kind_t
  74. {
  75. };
  76. /** A tag type used to select a @ref value constructor overload.
  77. The library provides the constant @ref string_kind
  78. which may be used to select the @ref value constructor
  79. that creates an empty @ref string.
  80. @see @ref string_kind
  81. */
  82. struct string_kind_t
  83. {
  84. };
  85. /** A constant used to select a @ref value constructor overload.
  86. The library provides this constant to allow efficient
  87. construction of a @ref value containing an empty @ref array.
  88. @par Example
  89. @code
  90. storage_ptr sp;
  91. value jv( array_kind, sp ); // sp is an optional parameter
  92. @endcode
  93. @see @ref array_kind_t
  94. */
  95. BOOST_JSON_INLINE_VARIABLE(array_kind, array_kind_t);
  96. /** A constant used to select a @ref value constructor overload.
  97. The library provides this constant to allow efficient
  98. construction of a @ref value containing an empty @ref object.
  99. @par Example
  100. @code
  101. storage_ptr sp;
  102. value jv( object_kind, sp ); // sp is an optional parameter
  103. @endcode
  104. @see @ref object_kind_t
  105. */
  106. BOOST_JSON_INLINE_VARIABLE(object_kind, object_kind_t);
  107. /** A constant used to select a @ref value constructor overload.
  108. The library provides this constant to allow efficient
  109. construction of a @ref value containing an empty @ref string.
  110. @par Example
  111. @code
  112. storage_ptr sp;
  113. value jv( string_kind, sp ); // sp is an optional parameter
  114. @endcode
  115. @see @ref string_kind_t
  116. */
  117. BOOST_JSON_INLINE_VARIABLE(string_kind, string_kind_t);
  118. BOOST_JSON_NS_END
  119. #endif