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) ~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~

2
doc/manafiles.json

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

22
src/config.cpp

@ -4,6 +4,7 @@
* SPDX-License-Identifier: MIT
*/
#include <cassert> // assert
#include <csignal> // raise
#include <cstdio> // fprintf
#include <filesystem> // current_path, recursive_directory
@ -11,9 +12,8 @@
#include <string>
#include <vector>
#include <nlohmann/json.hpp>
#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);
}
}

9
src/config.h

@ -12,9 +12,8 @@
#include <string>
#include <vector>
#include "nlohmann/json.hpp"
#include "util/singleton.h"
#include "util/json/value.h"
struct Settings {
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 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

Loading…
Cancel
Save