ezconfig
Create C++ Objects from Yaml and Json
Loading...
Searching...
No Matches
json_fwd.hpp
Go to the documentation of this file.
1// Copyright (c) 2023 Petter Nilsson. MIT License. https://github.com/pettni/ezconfig
2
10#pragma once
11
12#include <nlohmann/json_fwd.hpp>
13
14#include "factory.hpp"
15#include "macro.hpp"
16
17namespace ezconfig::json {
18
19template<typename T>
20concept Constructible = ::ezconfig::Constructible<T, const nlohmann::json &>;
21
33template<typename Base>
34std::unique_ptr<Base> Create(const nlohmann::json & j);
35
36} // namespace ezconfig::json
37
50#define EZ_JSON_DECLARE(Base) EZ_FACTORY_DECLARE(Base, const nlohmann::json &)
51
55template<ezconfig::json::Constructible Base>
56struct nlohmann::adl_serializer<std::shared_ptr<Base>>
57{
58 static void from_json(const json & j, std::shared_ptr<Base> & ptr);
59};
60
64template<ezconfig::json::Constructible Base>
65struct nlohmann::adl_serializer<std::unique_ptr<Base>>
66{
67 static void from_json(const json & j, std::unique_ptr<Base> & ptr);
68};
Factory base class.
std::unique_ptr< Base > Create(const nlohmann::json &json)
Create an object using the factory.
Definition json.hpp:89