serialize.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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/serialize_options.hpp>
  13. #include <boost/json/value.hpp>
  14. #include <string>
  15. namespace boost {
  16. namespace json {
  17. /** Return a string representing a serialized element.
  18. This function serializes `t` as JSON and returns it as a `std::string`.
  19. @par Complexity
  20. Linear in the size of `t`.
  21. @par Exception Safety
  22. Strong guarantee. Calls to allocate may throw.
  23. @return The serialized string.
  24. @param t The value to serialize
  25. @param opts The options for the serializer. If this parameter is omitted,
  26. the serializer will output only standard JSON.
  27. @{
  28. */
  29. BOOST_JSON_DECL
  30. std::string
  31. serialize(value const& t, serialize_options const& opts = {});
  32. BOOST_JSON_DECL
  33. std::string
  34. serialize(array const& t, serialize_options const& opts = {});
  35. BOOST_JSON_DECL
  36. std::string
  37. serialize(object const& t, serialize_options const& opts = {});
  38. BOOST_JSON_DECL
  39. std::string
  40. serialize(string const& t, serialize_options const& opts = {});
  41. template<class T>
  42. std::string
  43. serialize(T const& t, serialize_options const& opts = {});
  44. BOOST_JSON_DECL
  45. std::string
  46. serialize(string_view t, serialize_options const& opts = {});
  47. /// @}
  48. } // namespace json
  49. } // namespace boost
  50. #include <boost/json/impl/serialize.hpp>
  51. #endif