diff options
author | regnat <rg@regnat.ovh> | 2020-09-16 09:06:35 +0200 |
---|---|---|
committer | regnat <rg@regnat.ovh> | 2020-09-16 13:53:09 +0200 |
commit | e0817cbcdcdbec81d7ce2f5141b4f99bbc2bece7 (patch) | |
tree | d0eaeba8b40c8cf77caeaea49ab4effcf250925b /src/libutil | |
parent | 93c0e14a308d513cf61daa7a003417e42a7dc2f8 (diff) |
Don't include nlohmann/json.hpp in config.hh
Instead make a separate header with the template implementation of
`BaseSetting<T>::toJSONObj` that can be included where needed
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/abstractsettingtojson.hh | 15 | ||||
-rw-r--r-- | src/libutil/config.cc | 1 | ||||
-rw-r--r-- | src/libutil/config.hh | 10 |
3 files changed, 18 insertions, 8 deletions
diff --git a/src/libutil/abstractsettingtojson.hh b/src/libutil/abstractsettingtojson.hh new file mode 100644 index 000000000..b3fbc84f7 --- /dev/null +++ b/src/libutil/abstractsettingtojson.hh @@ -0,0 +1,15 @@ +#pragma once + +#include <nlohmann/json.hpp> +#include "config.hh" + +namespace nix { +template<typename T> +std::map<std::string, nlohmann::json> BaseSetting<T>::toJSONObject() +{ + auto obj = AbstractSetting::toJSONObject(); + obj.emplace("value", value); + obj.emplace("defaultValue", defaultValue); + return obj; +} +} diff --git a/src/libutil/config.cc b/src/libutil/config.cc index faa5cdbeb..309d23b40 100644 --- a/src/libutil/config.cc +++ b/src/libutil/config.cc @@ -1,5 +1,6 @@ #include "config.hh" #include "args.hh" +#include "abstractsettingtojson.hh" #include <nlohmann/json.hpp> diff --git a/src/libutil/config.hh b/src/libutil/config.hh index 18fa9dea8..1f5f4e7b9 100644 --- a/src/libutil/config.hh +++ b/src/libutil/config.hh @@ -4,7 +4,7 @@ #include "types.hh" -#include <nlohmann/json.hpp> +#include <nlohmann/json_fwd.hpp> #pragma once @@ -255,13 +255,7 @@ public: void convertToArg(Args & args, const std::string & category) override; - std::map<std::string, nlohmann::json> toJSONObject() override - { - auto obj = AbstractSetting::toJSONObject(); - obj.emplace("value", value); - obj.emplace("defaultValue", defaultValue); - return obj; - } + std::map<std::string, nlohmann::json> toJSONObject() override; }; template<typename T> |