serialize.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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_SERIALIZE_HPP
  10. #define BOOST_JSON_SERIALIZE_HPP
  11. #include <boost/json/detail/config.hpp>
  12. #include <boost/json/value.hpp>
  13. #include <iosfwd>
  14. #include <string>
  15. BOOST_JSON_NS_BEGIN
  16. /** Return a string representing a serialized element.
  17. This function serializes `t` as JSON and returns
  18. it as a `std::string`.
  19. @par Complexity
  20. Constant or linear in the size of `t`.
  21. @par Exception Safety
  22. Strong guarantee.
  23. Calls to allocate may throw.
  24. @return The serialized string
  25. @param t The value to serialize
  26. */
  27. /** @{ */
  28. BOOST_JSON_DECL
  29. std::string
  30. serialize(value const& t);
  31. BOOST_JSON_DECL
  32. std::string
  33. serialize(array const& t);
  34. BOOST_JSON_DECL
  35. std::string
  36. serialize(object const& t);
  37. BOOST_JSON_DECL
  38. std::string
  39. serialize(string const& t);
  40. BOOST_JSON_DECL
  41. std::string
  42. serialize(string_view t);
  43. /** @} */
  44. /** Serialize an element to an output stream.
  45. This function serializes the specified element
  46. as JSON into the output stream.
  47. @return `os`.
  48. @par Complexity
  49. Constant or linear in the size of `t`.
  50. @par Exception Safety
  51. Strong guarantee.
  52. Calls to `memory_resource::allocate` may throw.
  53. @param os The output stream to serialize to.
  54. @param t The value to serialize
  55. */
  56. /** @{ */
  57. BOOST_JSON_DECL
  58. std::ostream&
  59. operator<<(
  60. std::ostream& os,
  61. value const& t);
  62. BOOST_JSON_DECL
  63. std::ostream&
  64. operator<<(
  65. std::ostream& os,
  66. array const& t);
  67. BOOST_JSON_DECL
  68. std::ostream&
  69. operator<<(
  70. std::ostream& os,
  71. object const& t);
  72. BOOST_JSON_DECL
  73. std::ostream&
  74. operator<<(
  75. std::ostream& os,
  76. string const& t);
  77. /** @} */
  78. BOOST_JSON_NS_END
  79. #endif