kind.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 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 a string. This can be useful for
  50. diagnostics.
  51. @returns A reference to `os`.
  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 which may be used to
  60. select the @ref value constructor that creates an empty @ref array.
  61. @see @ref array_kind
  62. */
  63. struct array_kind_t
  64. {
  65. };
  66. /** A tag type used to select a @ref value constructor overload.
  67. The library provides the constant @ref object_kind which may be used to
  68. select the @ref value constructor that creates an empty @ref object.
  69. @see @ref object_kind
  70. */
  71. struct object_kind_t
  72. {
  73. };
  74. /** A tag type used to select a @ref value constructor overload.
  75. The library provides the constant @ref string_kind which may be used to
  76. select the @ref value constructor that creates an empty @ref string.
  77. @see @ref string_kind
  78. */
  79. struct string_kind_t
  80. {
  81. };
  82. /** A constant used to select a @ref value constructor overload.
  83. The library provides this constant to allow efficient
  84. construction of a @ref value containing an empty @ref array.
  85. @par Example
  86. @code
  87. storage_ptr sp;
  88. value jv( array_kind, sp ); // sp is an optional parameter
  89. @endcode
  90. @see @ref value::value(array_kind_t, storage_ptr).
  91. */
  92. BOOST_JSON_INLINE_VARIABLE(array_kind, array_kind_t);
  93. /** A constant used to select a @ref value constructor overload.
  94. The library provides this constant to allow efficient construction of
  95. a @ref value containing an empty @ref object.
  96. @par Example
  97. @code
  98. storage_ptr sp;
  99. value jv( object_kind, sp ); // sp is an optional parameter
  100. @endcode
  101. @see @ref value::value(object_kind_t, storage_ptr).
  102. */
  103. BOOST_JSON_INLINE_VARIABLE(object_kind, object_kind_t);
  104. /** A constant used to select a @ref value constructor overload.
  105. The library provides this constant to allow efficient construction of
  106. a @ref value containing an empty @ref string.
  107. @par Example
  108. @code
  109. storage_ptr sp;
  110. value jv( string_kind, sp ); // sp is an optional parameter
  111. @endcode
  112. @see @ref value::value(string_kind_t, storage_ptr).
  113. */
  114. BOOST_JSON_INLINE_VARIABLE(string_kind, string_kind_t);
  115. } // namespace json
  116. } // namespace boost
  117. #endif