object.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // Copyright (c) 2019 Vinnie Falco ([email protected])
  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 <boost/json/string_view.hpp>
  13. #include <cstdlib>
  14. namespace boost {
  15. namespace json {
  16. class object;
  17. class value;
  18. class key_value_pair;
  19. namespace detail {
  20. class unchecked_object
  21. {
  22. // each element is two values,
  23. // first one is a string key,
  24. // second one is the value.
  25. value* data_;
  26. std::size_t size_;
  27. storage_ptr const& sp_;
  28. public:
  29. inline
  30. ~unchecked_object();
  31. unchecked_object(
  32. value* data,
  33. std::size_t size, // # of kv-pairs
  34. storage_ptr const& sp) noexcept
  35. : data_(data)
  36. , size_(size)
  37. , sp_(sp)
  38. {
  39. }
  40. unchecked_object(
  41. unchecked_object&& other) noexcept
  42. : data_(other.data_)
  43. , size_(other.size_)
  44. , sp_(other.sp_)
  45. {
  46. other.data_ = nullptr;
  47. }
  48. storage_ptr const&
  49. storage() const noexcept
  50. {
  51. return sp_;
  52. }
  53. std::size_t
  54. size() const noexcept
  55. {
  56. return size_;
  57. }
  58. value*
  59. release() noexcept
  60. {
  61. auto const data = data_;
  62. data_ = nullptr;
  63. return data;
  64. }
  65. };
  66. template<class CharRange>
  67. std::pair<key_value_pair*, std::size_t>
  68. find_in_object(
  69. object const& obj,
  70. CharRange key) noexcept;
  71. extern template
  72. BOOST_JSON_DECL
  73. std::pair<key_value_pair*, std::size_t>
  74. find_in_object<string_view>(
  75. object const&,
  76. string_view key) noexcept;
  77. } // detail
  78. } // namespace json
  79. } // namespace boost
  80. #endif