Update nlohmann repository (#3609)

* Remove old non-submodule version of nlohmann in favor of submodule
* Update nlohmann from 3.9.1 to 3.12.0
- Already disable implicit conversions in preparation for next major version
This commit is contained in:
Alexander Bock
2025-04-16 14:13:20 +02:00
committed by GitHub
parent 151d3f37b6
commit 125f54aa0a
24 changed files with 99 additions and 25509 deletions
+3
View File
@@ -45,3 +45,6 @@
[submodule "modules/audio/ext/soloud"]
path = modules/audio/ext/soloud
url = https://github.com/jarikomppa/soloud
[submodule "ext/json"]
path = ext/json
url = https://github.com/nlohmann/json
+1
View File
@@ -113,6 +113,7 @@ begin_header("Dependency: SGCT")
set(SGCT_TEXT OFF CACHE BOOL "" FORCE)
set(SGCT_DEP_INCLUDE_FREETYPE OFF CACHE BOOL "" FORCE)
set(SGCT_DEP_INCLUDE_FMT OFF CACHE BOOL "" FORCE)
set(SGCT_DEP_INCLUDE_JSON OFF CACHE BOOL "" FORCE)
set(SGCT_DEP_INCLUDE_SCN OFF CACHE BOOL "" FORCE)
set(SGCT_DEP_INCLUDE_CATCH2 OFF CACHE BOOL "" FORCE)
@@ -917,7 +917,7 @@ openspace::HorizonsFile HorizonsDialog::handleAnswer(nlohmann::json& answer) {
}
// Return a new file with the result
return openspace::HorizonsFile(filePath, *result);
return openspace::HorizonsFile(filePath, result->get<std::string>());
}
bool HorizonsDialog::handleResult(openspace::HorizonsResultCode& result) {
+5
View File
@@ -62,6 +62,11 @@ target_compile_features(spice PUBLIC cxx_std_20)
set_target_properties(spice PROPERTIES FOLDER "External")
end_dependency()
# nlohmann
begin_dependency("nlohmann")
add_subdirectory(json)
end_dependency()
# Curl
begin_dependency("CURL")
if (WIN32)
Submodule
+1
Submodule ext/json added at 96c1b52f1c
-25447
View File
File diff suppressed because it is too large Load Diff
+6 -1
View File
@@ -36,7 +36,12 @@
#pragma GCC diagnostic ignored "-Wuseless-cast"
#endif // __GNUC__
#include <json/json.hpp>
#define JSON_HAS_CPP_11
#define JSON_HAS_CPP_14
#define JSON_HAS_CPP_17
#define JSON_HAS_CPP_20
#define JSON_USE_IMPLICIT_CONVERSIONS 0
#include <nlohmann/json.hpp>
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
@@ -157,7 +157,7 @@ bool FieldlinesState::loadStateFromJson(const std::string& pathToJsonFile,
{
const char* sTime = "time";
const json& jTmp = *(jFile.begin()); // First field line in the file
_triggerTime = Time::convertTime(jTmp[sTime]);
_triggerTime = Time::convertTime(jTmp[sTime].get<std::string>());
const char* sColumns = "columns";
const json::value_type& variableNameVec = jTmp[sTrace][sColumns];
@@ -173,7 +173,7 @@ bool FieldlinesState::loadStateFromJson(const std::string& pathToJsonFile,
}
for (size_t i = nPosComponents; i < nVariables; i++) {
_extraQuantityNames.push_back(variableNameVec[i]);
_extraQuantityNames.push_back(variableNameVec[i].get<std::string>());
}
}
@@ -185,7 +185,8 @@ bool FieldlinesState::loadStateFromJson(const std::string& pathToJsonFile,
for (json::iterator lineIter = jFile.begin(); lineIter != jFile.end(); ++lineIter) {
// The 'data' field in the 'trace' variable contains all vertex positions and the
// extra quantities. Each element is an array related to one vertex point.
const std::vector<std::vector<float>>& jData = (*lineIter)[sTrace][sData];
const std::vector<std::vector<float>>& jData =
(*lineIter)[sTrace][sData].get<std::vector<std::vector<float>>>();
const size_t nPoints = jData.size();
for (size_t j = 0; j < nPoints; j++) {
+1 -1
View File
@@ -123,7 +123,7 @@ void IswaKameleonGroup::readFieldlinePaths(const std::filesystem::path& indexFil
_fieldlines.addOption(it.key());
_fieldlineState[i] = std::make_tuple<std::string, std::string, bool>(
identifier() + "/" + it.key(),
it.value(),
it->get<std::string>(),
false
);
i++;
+1 -1
View File
@@ -342,7 +342,7 @@ void KameleonPlane::readFieldlinePaths(const std::filesystem::path& indexFile) {
_fieldlines.addOption(it.key());
_fieldlineState[i] = std::make_tuple<std::string, std::string, bool>(
partName + "/" + it.key(),
it.value(),
it->get<std::string>(),
false
);
i++;
+2 -2
View File
@@ -84,7 +84,7 @@ void DataProcessorJson::addDataValues(const std::string& data,
const int colsize = static_cast<int>(col.size());
for (int x = 0; x < colsize; ++x) {
const float value = col.at(x);
const float value = col.at(x).get<float>();
optionValues[i].push_back(value);
_min[i] = std::min(_min[i], value);
_max[i] = std::max(_max[i], value);
@@ -131,7 +131,7 @@ std::vector<float*> DataProcessorJson::processData(const std::string& data,
const int colsize = static_cast<int>(col.size());
for (int x = 0; x < colsize; ++x) {
const float value = col.at(x);
const float value = col.at(x).get<float>();
const int i = x + y * colsize;
dataOptions[option][i] = processDataPoint(value, option);
+31 -23
View File
@@ -356,16 +356,24 @@ std::string IswaManager::jsonPlaneToLuaTable(MetadataFuture& data) {
}
nlohmann::json j = nlohmann::json::parse(data.json);
std::string parent = j["Central Body"];
std::string frame = j["Coordinates"];
std::string coordinateType = j["Coordinate Type"];
int updateTime = j["ISWA_UPDATE_SECONDS"];
std::string parent = j["Central Body"].get<std::string>();
std::string frame = j["Coordinates"].get<std::string>();
std::string coordinateType = j["Coordinate Type"].get<std::string>();
int updateTime = j["ISWA_UPDATE_SECONDS"].get<int>();
glm::vec3 max(j["Plot XMAX"], j["Plot YMAX"], j["Plot ZMAX"]);
glm::vec3 min(j["Plot XMIN"], j["Plot YMIN"], j["Plot ZMIN"]);
glm::vec3 max = glm::vec3(
j["Plot XMAX"].get<float>(),
j["Plot YMAX"].get<float>(),
j["Plot ZMAX"].get<float>()
);
glm::vec3 min = glm::vec3(
j["Plot XMIN"].get<float>(),
j["Plot YMIN"].get<float>(),
j["Plot ZMIN"].get<float>()
);
glm::vec4 spatialScale(1.f, 1.f, 1.f, 10.f);
std::string spatial = j["Spatial Scale (Custom)"];
std::string spatial = j["Spatial Scale (Custom)"].get<std::string>();
if (spatial == "R_E") {
spatialScale.x = 6.371f;
spatialScale.y = 6.371f;
@@ -472,12 +480,12 @@ std::string IswaManager::jsonSphereToLuaTable(MetadataFuture& data) {
nlohmann::json j = nlohmann::json::parse(data.json);
j = j["metadata"];
std::string parent = j["central_body"];
std::string parent = j["central_body"].get<std::string>();
parent[0] = static_cast<char>(toupper(static_cast<int>(parent[0])));
std::string frame = j["standard_grid_target"];
std::string coordinateType = j["grid_1_type"];
float updateTime = j["output_time_interval"];
float radius = j["radius"];
std::string frame = j["standard_grid_target"].get<std::string>();
std::string coordinateType = j["grid_1_type"].get<std::string>();
float updateTime = j["output_time_interval"].get<float>();
float radius = j["radius"].get<float>();
glm::vec3 max(
j["x"]["actual_max"],
@@ -667,18 +675,17 @@ void IswaManager::fillCygnetInfo(std::string jsonString) {
for (size_t i = 0; i < jsonList.size(); i++) {
nlohmann::json jCygnet = jsonList.at(i);
std::string name = jCygnet["cygnetDisplayTitle"];
std::string name = jCygnet["cygnetDisplayTitle"].get<std::string>();
std::replace(name.begin(), name.end(),'.', ',');
CygnetInfo info = {
name,
jCygnet["cygnetDescription"],
jCygnet["cygnetUpdateInterval"],
jCygnet["cygnetDescription"].get<std::string>(),
jCygnet["cygnetUpdateInterval"].get<int>(),
false
};
_cygnetInformation[jCygnet["cygnetID"]] = std::make_shared<CygnetInfo>(
info
);
_cygnetInformation[jCygnet["cygnetID"].get<int>()] =
std::make_shared<CygnetInfo>(info);
}
}
}
@@ -699,8 +706,9 @@ void IswaManager::addCdfFiles(std::string cdfpath) {
for (size_t i = 0; i < cdfGroups.size(); i++) {
nlohmann::json cdfGroup = cdfGroups.at(i);
std::string groupName = cdfGroup["group"];
std::string fieldlineSeedsIndexFile = cdfGroup["fieldlinefile"];
std::string groupName = cdfGroup["group"].get<std::string>();
std::string fieldlineSeedsIndexFile =
cdfGroup["fieldlinefile"].get<std::string>();
if (_cdfInformation.find(groupName) != _cdfInformation.end()) {
LWARNING("CdfGroup with name" + groupName + " already exists");
@@ -713,9 +721,9 @@ void IswaManager::addCdfFiles(std::string cdfpath) {
for (size_t j = 0; j < cdfs.size(); j++) {
nlohmann::json cdf = cdfs.at(j);
std::string name = cdf["name"];
std::string path = cdf["path"];
std::string date = cdf["date"];
std::string name = cdf["name"].get<std::string>();
std::string path = cdf["path"].get<std::string>();
std::string date = cdf["date"].get<std::string>();
_cdfInformation[groupName].push_back({
name,
+2 -2
View File
@@ -167,7 +167,7 @@ void Connection::handleJson(const nlohmann::json& json) {
}
// The topic id may be an already discussed topic, or a new one.
const TopicId topicId = *topicJson;
const TopicId topicId = topicJson->get<TopicId>();
auto topicIt = _topics.find(topicId);
if (topicIt == _topics.end()) {
@@ -179,7 +179,7 @@ void Connection::handleJson(const nlohmann::json& json) {
LERROR("Type must be specified as a string when a new topic is initialized");
return;
}
const std::string type = *typeJson;
const std::string type = typeJson->get<std::string>();
ZoneText(type.c_str(), type.size());
if (!isAuthorized() && (type != "authorize")) {
@@ -172,7 +172,7 @@ bool FlightControllerTopic::isDone() const {
}
void FlightControllerTopic::handleJson(const nlohmann::json& json) {
auto it = CommandMap.find(json[TypeKey]);
auto it = CommandMap.find(json[TypeKey].get<std::string>());
if (it == CommandMap.end()) {
LWARNING(
std::format("Malformed JSON command: no '{}' in payload", TypeKey)
@@ -268,7 +268,7 @@ void FlightControllerTopic::updateView(const nlohmann::json& json) const {
void FlightControllerTopic::changeFocus(const nlohmann::json& json) const {
if (json.find(FocusKey) == json.end()) {
const std::string j = json;
const std::string j = json.get<std::string>();
LWARNING(
std::format("Could not find '{}' key in JSON. JSON was:\n{}", FocusKey, j)
);
@@ -285,13 +285,16 @@ void FlightControllerTopic::changeFocus(const nlohmann::json& json) const {
}
}
const std::string focus = json.find(FocusKey) != json.end() ? json[FocusKey] : "";
const std::string aim = json.find(AimKey) != json.end() ? json[AimKey] : "";
const std::string anchor = json.find(AnchorKey) != json.end() ? json[AnchorKey] : "";
const std::string focus =
json.find(FocusKey) != json.end() ? json[FocusKey].get<std::string>() : "";
const std::string aim =
json.find(AimKey) != json.end() ? json[AimKey].get<std::string>() : "";
const std::string anchor =
json.find(AnchorKey) != json.end() ? json[AnchorKey].get<std::string>() : "";
const bool resetVelocities = json[ResetVelocitiesKey];
const bool retargetAnchor = json[RetargetAnchorKey];
const bool retargetAim = json[RetargetAimKey];
const bool resetVelocities = json[ResetVelocitiesKey].get<bool>();
const bool retargetAnchor = json[RetargetAnchorKey].get<bool>();
const bool retargetAim = json[RetargetAimKey].get<bool>();
Scene* scene = global::renderEngine->scene();
const SceneGraphNode* focusNode = scene->sceneGraphNode(focus);
@@ -322,15 +325,15 @@ void FlightControllerTopic::changeFocus(const nlohmann::json& json) const {
void FlightControllerTopic::setRenderableEnabled(const nlohmann::json& json) const {
if (json[RenderableKey].find(SceneNodeName) == json[RenderableKey].end()) {
const std::string j = json;
const std::string j = json.get<std::string>();
LWARNING(
std::format("Could not find '{}' key in JSON. JSON was:\n{}", FocusKey, j)
);
return;
}
const std::string name = json[RenderableKey][SceneNodeName];
const bool enabled = json[RenderableKey][SceneNodeEnabled];
const std::string name = json[RenderableKey][SceneNodeName].get<std::string>();
const bool enabled = json[RenderableKey][SceneNodeEnabled].get<bool>();
const SceneGraphNode* node = global::renderEngine->scene()->sceneGraphNode(name);
if (node && node->renderable() != nullptr) {
@@ -388,7 +391,11 @@ void FlightControllerTopic::setFriction(bool roll, bool rotation, bool zoom) con
}
void FlightControllerTopic::setFriction(const nlohmann::json& json) const {
setFriction(json[FrictionRollKey], json[FrictionRotationKey], json[FrictionZoomKey]);
setFriction(
json[FrictionRollKey].get<bool>(),
json[FrictionRotationKey].get<bool>(),
json[FrictionZoomKey].get<bool>()
);
}
void FlightControllerTopic::disengageAutopilot() const {
@@ -406,7 +413,9 @@ void FlightControllerTopic::engageAutopilot(const nlohmann::json &json) {
for (auto it = input.begin(); it != input.end(); it++) {
const auto mapIt = AxisIndexMap.find(it.key());
if (mapIt == AxisIndexMap.end()) {
if (it.key() != TypeKey || CommandMap.find(it.value()) == CommandMap.end()) {
if (it.key() != TypeKey ||
CommandMap.find(it->get<std::string>()) == CommandMap.end())
{
LWARNING(std::format(
"No axis, button, or command named '{}' (value: {})",
it.key(), static_cast<int>(it.value())
@@ -419,7 +428,7 @@ void FlightControllerTopic::engageAutopilot(const nlohmann::json &json) {
}
void FlightControllerTopic::handleAutopilot(const nlohmann::json &json) {
const bool engaged = json[AutopilotEngagedKey];
const bool engaged = json[AutopilotEngagedKey].get<bool>();
if (engaged) {
engageAutopilot(json);
@@ -446,7 +455,9 @@ void FlightControllerTopic::processInputState(const nlohmann::json& json) {
for (auto it = input.begin(); it != input.end(); it++) {
const auto mapIt = AxisIndexMap.find(it.key());
if (mapIt == AxisIndexMap.end()) {
if (it.key() != TypeKey || CommandMap.find(it.value()) == CommandMap.end()) {
if (it.key() != TypeKey ||
CommandMap.find(it->get<std::string>()) == CommandMap.end())
{
LWARNING(std::format(
"No axis, button, or command named '{}' (value: {})",
it.key() , static_cast<int>(it.value())
@@ -459,7 +470,7 @@ void FlightControllerTopic::processInputState(const nlohmann::json& json) {
}
void FlightControllerTopic::processLua(const nlohmann::json &json) {
const std::string script = json[LuaScript];
const std::string script = json[LuaScript].get<std::string>();
global::scriptEngine->queueScript(script);
}
+2 -2
View File
@@ -174,7 +174,7 @@ HorizonsResultCode isValidHorizonsAnswer(const json& answer) {
if (auto version = signature->find("version"); version != signature->end()) {
// Extract the major version from the version string
std::string v = *version;
std::string v = version->get<std::string>();
v = v.substr(0, v.find('.'));
if (v != CurrentMajorVersion) {
@@ -197,7 +197,7 @@ HorizonsResultCode isValidHorizonsAnswer(const json& answer) {
// Errors
if (auto it = answer.find("error"); it != answer.end()) {
// There was an error
const std::string errorMsg = *it;
const std::string errorMsg = it->get<std::string>();
// @CPP23 (malej, 2022-04-08) In all cases below, the string function contains
// should be used instead of find
+2
View File
@@ -460,6 +460,8 @@ target_include_directories(openspace-core
${PROJECT_SOURCE_DIR}
)
target_link_libraries(openspace-core PUBLIC nlohmann_json)
target_precompile_headers(openspace-core PRIVATE
<openspace/json.h>
<openspace/properties/numericalproperty.h>
+1 -1
View File
@@ -28,6 +28,7 @@
#include <openspace/engine/globals.h>
#include <openspace/engine/settings.h>
#include <openspace/engine/moduleengine.h>
#include <openspace/json.h>
#include <openspace/util/json_helper.h>
#include <ghoul/filesystem/file.h>
#include <ghoul/filesystem/filesystem.h>
@@ -35,7 +36,6 @@
#include <ghoul/lua/ghoul_lua.h>
#include <ghoul/lua/lua_helper.h>
#include <ghoul/misc/assert.h>
#include <json/json.hpp>
#include <optional>
namespace {
+1 -1
View File
@@ -26,6 +26,7 @@
#include <openspace/engine/configuration.h>
#include <openspace/engine/globals.h>
#include <openspace/json.h>
#include <openspace/navigation/navigationhandler.h>
#include <openspace/navigation/navigationstate.h>
#include <openspace/scripting/lualibrary.h>
@@ -43,7 +44,6 @@
#include <ctime>
#include <filesystem>
#include <set>
#include <json/json.hpp>
#include "profile_lua.inl"
+2 -2
View File
@@ -91,8 +91,8 @@ void sortJson(nlohmann::json& json, const std::string& key) {
json.begin(),
json.end(),
[&key](const nlohmann::json& lhs, const nlohmann::json& rhs) {
const std::string lhsString = ghoul::toLowerCase(lhs[key]);
const std::string rhsString = ghoul::toLowerCase(rhs[key]);
const std::string lhsString = ghoul::toLowerCase(lhs[key].get<std::string>());
const std::string rhsString = ghoul::toLowerCase(rhs[key].get<std::string>());
return rhsString > lhsString;
}
+1 -1
View File
@@ -96,7 +96,7 @@ namespace {
auto result = answer.find("result");
CHECK(result != answer.end());
const HorizonsFile horizonsFile(filePath, *result);
const HorizonsFile horizonsFile(filePath, result->get<std::string>());
HorizonsResultCode resultCode = isValidHorizonsFile(horizonsFile.file());
CHECK(resultCode == expectedResultCode);
+1 -1
View File
@@ -34,7 +34,7 @@
#include <ghoul/filesystem/filesystem.h>
#include <filesystem>
#include <fstream>
#include <json/json.hpp>
#include <nlohmann/json.hpp>
// clang-tidy is convinced that it is possible to use emplace_back instead of push_back
// for the profiole types, but I haven't been able to convince the Visual Studio
+1 -1
View File
@@ -27,7 +27,7 @@
#include <catch2/matchers/catch_matchers_string.hpp>
#include <openspace/engine/settings.h>
#include <json/json.hpp>
#include <openspace/json.h>
#include <filesystem>
#include <fstream>
+2 -2
View File
@@ -25,11 +25,11 @@
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_exception.hpp>
#include <openspace/engine/configuration.h>
#include <openspace/json.h>
#include <ghoul/filesystem/filesystem.h>
#include <nlohmann/json.hpp>
#include <nlohmann/json-schema.hpp>
#include <sgct/config.h>
#include <openspace/engine/configuration.h>
#include <filesystem>
#include <fstream>
#include <sstream>