object.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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_DETAIL_OBJECT_HPP
  10. #define BOOST_JSON_DETAIL_OBJECT_HPP
  11. #include <boost/json/storage_ptr.hpp>
  12. #include <cstdlib>
  13. BOOST_JSON_NS_BEGIN
  14. class value;
  15. class key_value_pair;
  16. namespace detail {
  17. class unchecked_object
  18. {
  19. // each element is two values,
  20. // first one is a string key,
  21. // second one is the value.
  22. value* data_;
  23. std::size_t size_;
  24. storage_ptr const& sp_;
  25. public:
  26. inline
  27. ~unchecked_object();
  28. unchecked_object(
  29. value* data,
  30. std::size_t size, // # of kv-pairs
  31. storage_ptr const& sp) noexcept
  32. : data_(data)
  33. , size_(size)
  34. , sp_(sp)
  35. {
  36. }
  37. unchecked_object(
  38. unchecked_object&& other) noexcept
  39. : data_(other.data_)
  40. , size_(other.size_)
  41. , sp_(other.sp_)
  42. {
  43. other.data_ = nullptr;
  44. }
  45. storage_ptr const&
  46. storage() const noexcept
  47. {
  48. return sp_;
  49. }
  50. std::size_t
  51. size() const noexcept
  52. {
  53. return size_;
  54. }
  55. value*
  56. release() noexcept
  57. {
  58. auto const data = data_;
  59. data_ = nullptr;
  60. return data;
  61. }
  62. };
  63. } // detail
  64. BOOST_JSON_NS_END
  65. #endif