Browse Source

Manager: Switch to own JSON parser, remove nlohmann/json

master
Riyyi 2 years ago
parent
commit
4ea1242247
  1. 1
      README.org
  2. 2
      doc/manafiles.json
  3. 22
      src/config.cpp
  4. 9
      src/config.h

1
README.org

@ -105,7 +105,6 @@ manafiles will make sure that the contents of the block are commented.
- (make) ~cmake~ - (make) ~cmake~
- (make) ~git~ - (make) ~git~
- (make) ~gzip~ - (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) ~grep~
- (optional) ~pacman~ + ~pacman-contrib~ - (optional) ~pacman~ + ~pacman-contrib~
- (optional) ~apt~ + ~dpkg~ - (optional) ~apt~ + ~dpkg~

2
doc/manafiles.json

@ -1,5 +1,5 @@
{ {
"ignorePatterns" : [ "ignorePatterns": [
".git/", ".git/",
"*.md", "*.md",
"manafiles.json", "manafiles.json",

22
src/config.cpp

@ -4,6 +4,7 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include <cassert> // assert
#include <csignal> // raise #include <csignal> // raise
#include <cstdio> // fprintf #include <cstdio> // fprintf
#include <filesystem> // current_path, recursive_directory #include <filesystem> // current_path, recursive_directory
@ -11,9 +12,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <nlohmann/json.hpp>
#include "config.h" #include "config.h"
#include "util/json/value.h"
Config::Config(s) Config::Config(s)
: m_workingDirectory(std::filesystem::current_path()) : m_workingDirectory(std::filesystem::current_path())
@ -51,7 +51,7 @@ void Config::parseConfigFile()
return; return;
} }
nlohmann::json json; Json::Value json;
std::ifstream file(m_config); std::ifstream file(m_config);
if (!file.is_open()) { 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 }, { "ignorePatterns", settings.ignorePatterns },
{ "systemPatterns", settings.systemPatterns } { "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()) { assert(json.type() == Json::Value::Type::Object);
object.at("ignorePatterns").get_to(settings.ignorePatterns);
if (json.exists("ignorePatterns")) {
json.at("ignorePatterns").getTo(settings.ignorePatterns);
} }
if (object.find("systemPatterns") != object.end()) { if (json.exists("systemPatterns")) {
object.at("systemPatterns").get_to(settings.systemPatterns); json.at("systemPatterns").getTo(settings.systemPatterns);
} }
} }

9
src/config.h

@ -12,9 +12,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "nlohmann/json.hpp"
#include "util/singleton.h" #include "util/singleton.h"
#include "util/json/value.h"
struct Settings { struct Settings {
std::vector<std::string> ignorePatterns { std::vector<std::string> 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 toJson(Json::Value& object, const Settings& settings);
void from_json(const nlohmann::json& object, Settings& settings); void fromJson(const Json::Value& object, Settings& settings);
#endif // CONFIG_H #endif // CONFIG_H

Loading…
Cancel
Save