mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-03 01:33:19 +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
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -13,3 +13,6 @@
|
||||||
[submodule "external/rei-json"]
|
[submodule "external/rei-json"]
|
||||||
path = external/rei-json
|
path = external/rei-json
|
||||||
url = https://codeberg.org/vyn/rei-json.git
|
url = https://codeberg.org/vyn/rei-json.git
|
||||||
|
[submodule "external/mirai-core/external/rei-json"]
|
||||||
|
path = external/mirai-core/external/rei-json
|
||||||
|
url = https://codeberg.org/vyn/rei-json.git
|
||||||
|
|
|
@ -48,6 +48,10 @@ target_link_libraries(mirai PRIVATE evalyte-cpp-common)
|
||||||
target_include_directories(mirai PRIVATE "external")
|
target_include_directories(mirai PRIVATE "external")
|
||||||
target_link_libraries(mirai PRIVATE mirai-core)
|
target_link_libraries(mirai PRIVATE mirai-core)
|
||||||
|
|
||||||
|
add_subdirectory(external/rei-json)
|
||||||
|
target_include_directories(mirai PRIVATE "external/rei-json/include")
|
||||||
|
target_link_libraries(mirai PRIVATE rei-json)
|
||||||
|
|
||||||
slint_target_sources(
|
slint_target_sources(
|
||||||
mirai src/ui.slint
|
mirai src/ui.slint
|
||||||
NAMESPACE ui
|
NAMESPACE ui
|
||||||
|
|
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 "external")
|
||||||
target_include_directories(mirai-core PRIVATE "include/mirai-core")
|
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
|
65
external/mirai-core/src/Mirai.cpp
vendored
65
external/mirai-core/src/Mirai.cpp
vendored
|
@ -8,8 +8,11 @@
|
||||||
#include "DataProvider.h"
|
#include "DataProvider.h"
|
||||||
#include "MarkdownDataProvider.h"
|
#include "MarkdownDataProvider.h"
|
||||||
#include "Source.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 <algorithm>
|
||||||
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <print>
|
#include <print>
|
||||||
|
@ -21,31 +24,32 @@ namespace mirai
|
||||||
|
|
||||||
void Mirai::loadConfig(const std::string &path)
|
void Mirai::loadConfig(const std::string &path)
|
||||||
{
|
{
|
||||||
auto configJson = nlohmann::json::parse(R"(
|
|
||||||
{
|
|
||||||
"files": []
|
|
||||||
}
|
|
||||||
)");
|
|
||||||
std::ifstream file(path);
|
std::ifstream file(path);
|
||||||
if (!file) {
|
if (!file) {
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
configJson = nlohmann::json::parse(file);
|
std::stringstream buffer;
|
||||||
|
buffer << file.rdbuf();
|
||||||
|
auto jsonStr = buffer.str();
|
||||||
|
|
||||||
assert(configJson.is_object());
|
auto configJson = rei::json::parse(jsonStr);
|
||||||
assert(configJson["files"].is_array());
|
|
||||||
auto jsonSources = configJson["files"];
|
assert(configJson.isObject());
|
||||||
for (const auto &filePath : jsonSources) {
|
assert(configJson.asObject()["files"].isArray());
|
||||||
assert(filePath.is_object());
|
auto jsonSources = configJson.asObject()["files"].asArray();
|
||||||
const auto name = filePath["name"].get<std::string>();
|
for (int i = 0; i < jsonSources.count(); ++i) {
|
||||||
const auto path = filePath["path"].get<std::string>();
|
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);
|
std::unique_ptr<DataProvider> file = std::make_unique<MarkdownDataProvider>(path);
|
||||||
DataProvider *sourceDataProvider = file.release();
|
DataProvider *sourceDataProvider = file.release();
|
||||||
sourceDataProvider->load();
|
sourceDataProvider->load();
|
||||||
sources_.push_back(std::make_unique<Source>(
|
sources_.push_back(
|
||||||
|
std::make_unique<Source>(
|
||||||
SourceConstructor{.name = name, .sourceDataProvider = sourceDataProvider}
|
SourceConstructor{.name = name, .sourceDataProvider = sourceDataProvider}
|
||||||
));
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,20 +60,19 @@ void Mirai::saveConfig()
|
||||||
std::print(std::cerr, "Can't save config to {}", configPath_);
|
std::print(std::cerr, "Can't save config to {}", configPath_);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto configJson = nlohmann::json::parse(R"(
|
auto files = rei::json::JsonArray{};
|
||||||
{
|
auto configJson = rei::json::JsonObject{};
|
||||||
"files": []
|
configJson.set("files", files);
|
||||||
}
|
|
||||||
)");
|
|
||||||
for (auto &source : sources_) {
|
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());
|
auto dataProvider = dynamic_cast<MarkdownDataProvider *>(source->dataProvider());
|
||||||
jsonSource["path"] = dataProvider->path();
|
jsonSource.set("path", dataProvider->path());
|
||||||
jsonSource["type"] = "FileSystemMarkdown";
|
jsonSource.set("type", "FileSystemMarkdown");
|
||||||
configJson["files"].push_back(jsonSource);
|
configJson.getArray("files").push(jsonSource);
|
||||||
}
|
}
|
||||||
file << configJson.dump(4);
|
file << rei::json::toString(configJson);
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,9 +87,11 @@ void Mirai::addSource(
|
||||||
{
|
{
|
||||||
DataProvider *sourceDataProvider = source.release();
|
DataProvider *sourceDataProvider = source.release();
|
||||||
sourceDataProvider->load();
|
sourceDataProvider->load();
|
||||||
sources_.push_back(std::make_unique<Source>(
|
sources_.push_back(
|
||||||
|
std::make_unique<Source>(
|
||||||
SourceConstructor{.name = name, .sourceDataProvider = sourceDataProvider}
|
SourceConstructor{.name = name, .sourceDataProvider = sourceDataProvider}
|
||||||
));
|
)
|
||||||
|
);
|
||||||
saveConfig();
|
saveConfig();
|
||||||
sourceAdded.emit(nullptr);
|
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