kind.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. namespace boost {
  15. namespace json {
  16. /** Constants for identifying the type of a value
  17. These values are returned from @ref value::kind
  18. */
  19. // Order matters
  20. enum class kind : unsigned char
  21. {
  22. /// The null value.
  23. null,
  24. /// A `bool`.
  25. bool_,
  26. /// A `std::int64_t`
  27. int64,
  28. /// A `std::uint64_t`
  29. uint64,
  30. /// A `double`.
  31. double_,
  32. /// A @ref string.
  33. string,
  34. /// An @ref array.
  35. array,
  36. /// An @ref object.
  37. object
  38. };
  39. /** Return a string representing a kind.
  40. This provides a human-readable string
  41. representing a @ref kind. This may be
  42. useful for diagnostics.
  43. @returns The string.
  44. @param k The kind.
  45. */
  46. BOOST_JSON_DECL
  47. string_view
  48. to_string(kind k) noexcept;
  49. /** Format a kind to an output stream.
  50. This allows a @ref kind to be formatted as
  51. a string, typically for diagnostics.
  52. @returns The output stream.
  53. @param os The output stream to format to.
  54. @param k The kind to format.
  55. */
  56. BOOST_JSON_DECL
  57. std::ostream&
  58. operator<<(std::ostream& os, kind k);
  59. /** A tag type used to select a @ref value constructor overload.
  60. The library provides the constant @ref array_kind
  61. which may be used to select the @ref value constructor
  62. that creates an empty @ref array.
  63. @see @ref array_kind
  64. */
  65. struct array_kind_t
  66. {
  67. };
  68. /** A tag type used to select a @ref value constructor overload.
  69. The library provides the constant @ref object_kind
  70. which may be used to select the @ref value constructor
  71. that creates an empty @ref object.
  72. @see @ref object_kind
  73. */
  74. struct object_kind_t
  75. {
  76. };
  77. /** A tag type used to select a @ref value constructor overload.
  78. The library provides the constant @ref string_kind
  79. which may be used to select the @ref value constructor
  80. that creates an empty @ref string.
  81. @see @ref string_kind
  82. */
  83. struct string_kind_t
  84. {
  85. };
  86. /** A constant used to select a @ref value constructor overload.
  87. The library provides this constant to allow efficient
  88. construction of a @ref value containing an empty @ref array.
  89. @par Example
  90. @code
  91. storage_ptr sp;
  92. value jv( array_kind, sp ); // sp is an optional parameter
  93. @endcode
  94. @see @ref array_kind_t
  95. */
  96. BOOST_JSON_INLINE_VARIABLE(array_kind, array_kind_t);
  97. /** A constant used to select a @ref value constructor overload.
  98. The library provides this constant to allow efficient
  99. construction of a @ref value containing an empty @ref object.
  100. @par Example
  101. @code
  102. storage_ptr sp;
  103. value jv( object_kind, sp ); // sp is an optional parameter
  104. @endcode
  105. @see @ref object_kind_t
  106. */
  107. BOOST_JSON_INLINE_VARIABLE(object_kind, object_kind_t);
  108. /** A constant used to select a @ref value constructor overload.
  109. The library provides this constant to allow efficient
  110. construction of a @ref value containing an empty @ref string.
  111. @par Example
  112. @code
  113. storage_ptr sp;
  114. value jv( string_kind, sp ); // sp is an optional parameter
  115. @endcode
  116. @see @ref string_kind_t
  117. */
  118. BOOST_JSON_INLINE_VARIABLE(string_kind, string_kind_t);
  119. } // namespace json
  120. } // namespace boost
  121. #endif