Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:21

0001 //     __ _____ _____ _____
0002 //  __|  |   __|     |   | |  JSON for Modern C++
0003 // |  |  |__   |  |  | | | |  version 3.11.2
0004 // |_____|_____|_____|_|___|  https://github.com/nlohmann/json
0005 //
0006 // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
0007 // SPDX-License-Identifier: MIT
0008 
0009 #pragma once
0010 
0011 #include <initializer_list>
0012 #include <utility>
0013 
0014 #include <nlohmann/detail/abi_macros.hpp>
0015 #include <nlohmann/detail/meta/type_traits.hpp>
0016 
0017 NLOHMANN_JSON_NAMESPACE_BEGIN
0018 namespace detail
0019 {
0020 
0021 template<typename BasicJsonType>
0022 class json_ref
0023 {
0024   public:
0025     using value_type = BasicJsonType;
0026 
0027     json_ref(value_type&& value)
0028         : owned_value(std::move(value))
0029     {}
0030 
0031     json_ref(const value_type& value)
0032         : value_ref(&value)
0033     {}
0034 
0035     json_ref(std::initializer_list<json_ref> init)
0036         : owned_value(init)
0037     {}
0038 
0039     template <
0040         class... Args,
0041         enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0 >
0042     json_ref(Args && ... args)
0043         : owned_value(std::forward<Args>(args)...)
0044     {}
0045 
0046     // class should be movable only
0047     json_ref(json_ref&&) noexcept = default;
0048     json_ref(const json_ref&) = delete;
0049     json_ref& operator=(const json_ref&) = delete;
0050     json_ref& operator=(json_ref&&) = delete;
0051     ~json_ref() = default;
0052 
0053     value_type moved_or_copied() const
0054     {
0055         if (value_ref == nullptr)
0056         {
0057             return std::move(owned_value);
0058         }
0059         return *value_ref;
0060     }
0061 
0062     value_type const& operator*() const
0063     {
0064         return value_ref ? *value_ref : owned_value;
0065     }
0066 
0067     value_type const* operator->() const
0068     {
0069         return &** this;
0070     }
0071 
0072   private:
0073     mutable value_type owned_value = nullptr;
0074     value_type const* value_ref = nullptr;
0075 };
0076 
0077 }  // namespace detail
0078 NLOHMANN_JSON_NAMESPACE_END