mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-02 17:23:20 +00:00
Replace nlohmann with rei-json
This commit is contained in:
parent
72b004b7b0
commit
ef56efd314
8 changed files with 51 additions and 24801 deletions
4
external/mirai-core/CMakeLists.txt
vendored
4
external/mirai-core/CMakeLists.txt
vendored
|
@ -21,3 +21,7 @@ add_library(mirai-core
|
|||
|
||||
target_include_directories(mirai-core PRIVATE "external")
|
||||
target_include_directories(mirai-core PRIVATE "include/mirai-core")
|
||||
|
||||
add_subdirectory(external/rei-json)
|
||||
target_include_directories(mirai-core PRIVATE "external/rei-json/include")
|
||||
target_link_libraries(mirai-core PRIVATE rei-json)
|
||||
|
|
24767
external/mirai-core/external/nlohmann/json.hpp
vendored
24767
external/mirai-core/external/nlohmann/json.hpp
vendored
File diff suppressed because it is too large
Load diff
1
external/mirai-core/external/rei-json
vendored
Submodule
1
external/mirai-core/external/rei-json
vendored
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 63e7986b0901449657c3874ed7b19618315e9f01
|
69
external/mirai-core/src/Mirai.cpp
vendored
69
external/mirai-core/src/Mirai.cpp
vendored
|
@ -8,8 +8,11 @@
|
|||
#include "DataProvider.h"
|
||||
#include "MarkdownDataProvider.h"
|
||||
#include "Source.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "rei-json/Array.h"
|
||||
#include "rei-json/Object.h"
|
||||
#include "rei-json/json.h"
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <print>
|
||||
|
@ -21,31 +24,32 @@ namespace mirai
|
|||
|
||||
void Mirai::loadConfig(const std::string &path)
|
||||
{
|
||||
auto configJson = nlohmann::json::parse(R"(
|
||||
{
|
||||
"files": []
|
||||
}
|
||||
)");
|
||||
std::ifstream file(path);
|
||||
if (!file) {
|
||||
|
||||
return;
|
||||
}
|
||||
configJson = nlohmann::json::parse(file);
|
||||
std::stringstream buffer;
|
||||
buffer << file.rdbuf();
|
||||
auto jsonStr = buffer.str();
|
||||
|
||||
assert(configJson.is_object());
|
||||
assert(configJson["files"].is_array());
|
||||
auto jsonSources = configJson["files"];
|
||||
for (const auto &filePath : jsonSources) {
|
||||
assert(filePath.is_object());
|
||||
const auto name = filePath["name"].get<std::string>();
|
||||
const auto path = filePath["path"].get<std::string>();
|
||||
auto configJson = rei::json::parse(jsonStr);
|
||||
|
||||
assert(configJson.isObject());
|
||||
assert(configJson.asObject()["files"].isArray());
|
||||
auto jsonSources = configJson.asObject()["files"].asArray();
|
||||
for (int i = 0; i < jsonSources.count(); ++i) {
|
||||
auto &filePath = jsonSources[i];
|
||||
assert(filePath.isObject());
|
||||
const auto name = filePath.asObject().getString("name");
|
||||
const auto path = filePath.asObject().getString("path");
|
||||
std::unique_ptr<DataProvider> file = std::make_unique<MarkdownDataProvider>(path);
|
||||
DataProvider *sourceDataProvider = file.release();
|
||||
sourceDataProvider->load();
|
||||
sources_.push_back(std::make_unique<Source>(
|
||||
SourceConstructor{.name = name, .sourceDataProvider = sourceDataProvider}
|
||||
));
|
||||
sources_.push_back(
|
||||
std::make_unique<Source>(
|
||||
SourceConstructor{.name = name, .sourceDataProvider = sourceDataProvider}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,20 +60,19 @@ void Mirai::saveConfig()
|
|||
std::print(std::cerr, "Can't save config to {}", configPath_);
|
||||
return;
|
||||
}
|
||||
auto configJson = nlohmann::json::parse(R"(
|
||||
{
|
||||
"files": []
|
||||
}
|
||||
)");
|
||||
auto files = rei::json::JsonArray{};
|
||||
auto configJson = rei::json::JsonObject{};
|
||||
configJson.set("files", files);
|
||||
for (auto &source : sources_) {
|
||||
nlohmann::json jsonSource;
|
||||
jsonSource["name"] = source->name();
|
||||
|
||||
rei::json::JsonObject jsonSource;
|
||||
jsonSource.set("name", source->name());
|
||||
auto dataProvider = dynamic_cast<MarkdownDataProvider *>(source->dataProvider());
|
||||
jsonSource["path"] = dataProvider->path();
|
||||
jsonSource["type"] = "FileSystemMarkdown";
|
||||
configJson["files"].push_back(jsonSource);
|
||||
jsonSource.set("path", dataProvider->path());
|
||||
jsonSource.set("type", "FileSystemMarkdown");
|
||||
configJson.getArray("files").push(jsonSource);
|
||||
}
|
||||
file << configJson.dump(4);
|
||||
file << rei::json::toString(configJson);
|
||||
file.close();
|
||||
}
|
||||
|
||||
|
@ -84,9 +87,11 @@ void Mirai::addSource(
|
|||
{
|
||||
DataProvider *sourceDataProvider = source.release();
|
||||
sourceDataProvider->load();
|
||||
sources_.push_back(std::make_unique<Source>(
|
||||
SourceConstructor{.name = name, .sourceDataProvider = sourceDataProvider}
|
||||
));
|
||||
sources_.push_back(
|
||||
std::make_unique<Source>(
|
||||
SourceConstructor{.name = name, .sourceDataProvider = sourceDataProvider}
|
||||
)
|
||||
);
|
||||
saveConfig();
|
||||
sourceAdded.emit(nullptr);
|
||||
};
|
||||
|
|
2
external/rei-json
vendored
2
external/rei-json
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 2639dba60a990f9dbc79b5204a925a101ecf24ba
|
||||
Subproject commit 63e7986b0901449657c3874ed7b19618315e9f01
|
2
external/selenite
vendored
2
external/selenite
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 810607c01fa659f31bd11bd41a9ee5611e5db8ea
|
||||
Subproject commit 6ff7dd8ea890bec8f4f61304e64bbfeabd61e7a8
|
Loading…
Add table
Add a link
Reference in a new issue