1c5f01b2fSopenharmony_ci// __ _____ _____ _____ 2c5f01b2fSopenharmony_ci// __| | __| | | | JSON for Modern C++ 3c5f01b2fSopenharmony_ci// | | |__ | | | | | | version 3.11.2 4c5f01b2fSopenharmony_ci// |_____|_____|_____|_|___| https://github.com/nlohmann/json 5c5f01b2fSopenharmony_ci// 6c5f01b2fSopenharmony_ci// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> 7c5f01b2fSopenharmony_ci// SPDX-License-Identifier: MIT 8c5f01b2fSopenharmony_ci 9c5f01b2fSopenharmony_ci#pragma once 10c5f01b2fSopenharmony_ci 11c5f01b2fSopenharmony_ci#include <initializer_list> 12c5f01b2fSopenharmony_ci#include <utility> 13c5f01b2fSopenharmony_ci 14c5f01b2fSopenharmony_ci#include <nlohmann/detail/abi_macros.hpp> 15c5f01b2fSopenharmony_ci#include <nlohmann/detail/meta/type_traits.hpp> 16c5f01b2fSopenharmony_ci 17c5f01b2fSopenharmony_ciNLOHMANN_JSON_NAMESPACE_BEGIN 18c5f01b2fSopenharmony_cinamespace detail 19c5f01b2fSopenharmony_ci{ 20c5f01b2fSopenharmony_ci 21c5f01b2fSopenharmony_citemplate<typename BasicJsonType> 22c5f01b2fSopenharmony_ciclass json_ref 23c5f01b2fSopenharmony_ci{ 24c5f01b2fSopenharmony_ci public: 25c5f01b2fSopenharmony_ci using value_type = BasicJsonType; 26c5f01b2fSopenharmony_ci 27c5f01b2fSopenharmony_ci json_ref(value_type&& value) 28c5f01b2fSopenharmony_ci : owned_value(std::move(value)) 29c5f01b2fSopenharmony_ci {} 30c5f01b2fSopenharmony_ci 31c5f01b2fSopenharmony_ci json_ref(const value_type& value) 32c5f01b2fSopenharmony_ci : value_ref(&value) 33c5f01b2fSopenharmony_ci {} 34c5f01b2fSopenharmony_ci 35c5f01b2fSopenharmony_ci json_ref(std::initializer_list<json_ref> init) 36c5f01b2fSopenharmony_ci : owned_value(init) 37c5f01b2fSopenharmony_ci {} 38c5f01b2fSopenharmony_ci 39c5f01b2fSopenharmony_ci template < 40c5f01b2fSopenharmony_ci class... Args, 41c5f01b2fSopenharmony_ci enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0 > 42c5f01b2fSopenharmony_ci json_ref(Args && ... args) 43c5f01b2fSopenharmony_ci : owned_value(std::forward<Args>(args)...) 44c5f01b2fSopenharmony_ci {} 45c5f01b2fSopenharmony_ci 46c5f01b2fSopenharmony_ci // class should be movable only 47c5f01b2fSopenharmony_ci json_ref(json_ref&&) noexcept = default; 48c5f01b2fSopenharmony_ci json_ref(const json_ref&) = delete; 49c5f01b2fSopenharmony_ci json_ref& operator=(const json_ref&) = delete; 50c5f01b2fSopenharmony_ci json_ref& operator=(json_ref&&) = delete; 51c5f01b2fSopenharmony_ci ~json_ref() = default; 52c5f01b2fSopenharmony_ci 53c5f01b2fSopenharmony_ci value_type moved_or_copied() const 54c5f01b2fSopenharmony_ci { 55c5f01b2fSopenharmony_ci if (value_ref == nullptr) 56c5f01b2fSopenharmony_ci { 57c5f01b2fSopenharmony_ci return std::move(owned_value); 58c5f01b2fSopenharmony_ci } 59c5f01b2fSopenharmony_ci return *value_ref; 60c5f01b2fSopenharmony_ci } 61c5f01b2fSopenharmony_ci 62c5f01b2fSopenharmony_ci value_type const& operator*() const 63c5f01b2fSopenharmony_ci { 64c5f01b2fSopenharmony_ci return value_ref ? *value_ref : owned_value; 65c5f01b2fSopenharmony_ci } 66c5f01b2fSopenharmony_ci 67c5f01b2fSopenharmony_ci value_type const* operator->() const 68c5f01b2fSopenharmony_ci { 69c5f01b2fSopenharmony_ci return &** this; 70c5f01b2fSopenharmony_ci } 71c5f01b2fSopenharmony_ci 72c5f01b2fSopenharmony_ci private: 73c5f01b2fSopenharmony_ci mutable value_type owned_value = nullptr; 74c5f01b2fSopenharmony_ci value_type const* value_ref = nullptr; 75c5f01b2fSopenharmony_ci}; 76c5f01b2fSopenharmony_ci 77c5f01b2fSopenharmony_ci} // namespace detail 78c5f01b2fSopenharmony_ciNLOHMANN_JSON_NAMESPACE_END 79