diff --git a/README.org b/README.org index 80ccd66..46a096f 100644 --- a/README.org +++ b/README.org @@ -105,7 +105,6 @@ manafiles will make sure that the contents of the block are commented. - (make) ~cmake~ - (make) ~git~ - (make) ~gzip~ -- (make) ~nlohmann-json~ [[https://archlinux.org/packages/community/any/nlohmann-json/][arch]], [[https://packages.debian.org/search?keywords=nlohmann-json][debian]], [[https://packages.ubuntu.com/search?keywords=nlohmann-json][ubuntu]] - (optional) ~grep~ - (optional) ~pacman~ + ~pacman-contrib~ - (optional) ~apt~ + ~dpkg~ diff --git a/doc/manafiles.json b/doc/manafiles.json index 05d075e..1f92091 100644 --- a/doc/manafiles.json +++ b/doc/manafiles.json @@ -1,5 +1,5 @@ { - "ignorePatterns" : [ + "ignorePatterns": [ ".git/", "*.md", "manafiles.json", diff --git a/src/config.cpp b/src/config.cpp index 5fa0d78..9274977 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: MIT */ +#include // assert #include // raise #include // fprintf #include // current_path, recursive_directory @@ -11,9 +12,8 @@ #include #include -#include - #include "config.h" +#include "util/json/value.h" Config::Config(s) : m_workingDirectory(std::filesystem::current_path()) @@ -51,7 +51,7 @@ void Config::parseConfigFile() return; } - nlohmann::json json; + Json::Value json; std::ifstream file(m_config); if (!file.is_open()) { @@ -72,21 +72,23 @@ void Config::parseConfigFile() // ----------------------------------------- -void to_json(nlohmann::json& object, const Settings& settings) +void toJson(Json::Value& json, const Settings& settings) { - object = nlohmann::json { + json = Json::Value { { "ignorePatterns", settings.ignorePatterns }, { "systemPatterns", settings.systemPatterns } }; } -void from_json(const nlohmann::json& object, Settings& settings) +void fromJson(const Json::Value& json, Settings& settings) { - if (object.find("ignorePatterns") != object.end()) { - object.at("ignorePatterns").get_to(settings.ignorePatterns); + assert(json.type() == Json::Value::Type::Object); + + if (json.exists("ignorePatterns")) { + json.at("ignorePatterns").getTo(settings.ignorePatterns); } - if (object.find("systemPatterns") != object.end()) { - object.at("systemPatterns").get_to(settings.systemPatterns); + if (json.exists("systemPatterns")) { + json.at("systemPatterns").getTo(settings.systemPatterns); } } diff --git a/src/config.h b/src/config.h index e64c3ae..33563a9 100644 --- a/src/config.h +++ b/src/config.h @@ -12,9 +12,8 @@ #include #include -#include "nlohmann/json.hpp" - #include "util/singleton.h" +#include "util/json/value.h" struct Settings { std::vector ignorePatterns { @@ -64,9 +63,9 @@ private: // ----------------------------------------- -// nlohmann::json arbitrary type conversion functions +// Json arbitrary type conversion functions -void to_json(nlohmann::json& object, const Settings& settings); -void from_json(const nlohmann::json& object, Settings& settings); +void toJson(Json::Value& object, const Settings& settings); +void fromJson(const Json::Value& object, Settings& settings); #endif // CONFIG_H