style: adjust clang-format rules (#2186)
Co-authored-by: Vithorio Polten <reach@vithor.io>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* @file src/platform/windows/nvprefs/undo_data.cpp
|
||||
* @brief Definitions for undoing changes to nvidia preferences.
|
||||
*/
|
||||
// external includes
|
||||
// lib includes
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
// local includes
|
||||
@@ -17,54 +17,46 @@ namespace nlohmann {
|
||||
using data_t = nvprefs::undo_data_t::data_t;
|
||||
using opengl_swapchain_t = data_t::opengl_swapchain_t;
|
||||
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
struct adl_serializer<std::optional<T>> {
|
||||
static void
|
||||
to_json(json &j, const std::optional<T> &opt) {
|
||||
static void to_json(json &j, const std::optional<T> &opt) {
|
||||
if (opt == std::nullopt) {
|
||||
j = nullptr;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
j = *opt;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
from_json(const json &j, std::optional<T> &opt) {
|
||||
static void from_json(const json &j, std::optional<T> &opt) {
|
||||
if (j.is_null()) {
|
||||
opt = std::nullopt;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
opt = j.template get<T>();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
template<>
|
||||
struct adl_serializer<data_t> {
|
||||
static void
|
||||
to_json(json &j, const data_t &data) {
|
||||
j = json { { "opengl_swapchain", data.opengl_swapchain } };
|
||||
static void to_json(json &j, const data_t &data) {
|
||||
j = json {{"opengl_swapchain", data.opengl_swapchain}};
|
||||
}
|
||||
|
||||
static void
|
||||
from_json(const json &j, data_t &data) {
|
||||
static void from_json(const json &j, data_t &data) {
|
||||
j.at("opengl_swapchain").get_to(data.opengl_swapchain);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
template<>
|
||||
struct adl_serializer<opengl_swapchain_t> {
|
||||
static void
|
||||
to_json(json &j, const opengl_swapchain_t &opengl_swapchain) {
|
||||
static void to_json(json &j, const opengl_swapchain_t &opengl_swapchain) {
|
||||
j = json {
|
||||
{ "our_value", opengl_swapchain.our_value },
|
||||
{ "undo_value", opengl_swapchain.undo_value }
|
||||
{"our_value", opengl_swapchain.our_value},
|
||||
{"undo_value", opengl_swapchain.undo_value}
|
||||
};
|
||||
}
|
||||
|
||||
static void
|
||||
from_json(const json &j, opengl_swapchain_t &opengl_swapchain) {
|
||||
static void from_json(const json &j, opengl_swapchain_t &opengl_swapchain) {
|
||||
j.at("our_value").get_to(opengl_swapchain.our_value);
|
||||
j.at("undo_value").get_to(opengl_swapchain.undo_value);
|
||||
}
|
||||
@@ -73,46 +65,39 @@ namespace nlohmann {
|
||||
|
||||
namespace nvprefs {
|
||||
|
||||
void
|
||||
undo_data_t::set_opengl_swapchain(uint32_t our_value, std::optional<uint32_t> undo_value) {
|
||||
void undo_data_t::set_opengl_swapchain(uint32_t our_value, std::optional<uint32_t> undo_value) {
|
||||
data.opengl_swapchain = data_t::opengl_swapchain_t {
|
||||
our_value,
|
||||
undo_value
|
||||
};
|
||||
}
|
||||
|
||||
std::optional<undo_data_t::data_t::opengl_swapchain_t>
|
||||
undo_data_t::get_opengl_swapchain() const {
|
||||
std::optional<undo_data_t::data_t::opengl_swapchain_t> undo_data_t::get_opengl_swapchain() const {
|
||||
return data.opengl_swapchain;
|
||||
}
|
||||
|
||||
std::string
|
||||
undo_data_t::write() const {
|
||||
std::string undo_data_t::write() const {
|
||||
try {
|
||||
// Keep this assignment otherwise data will be treated as an array due to
|
||||
// initializer list shenanigangs.
|
||||
const json json_data = data;
|
||||
return json_data.dump();
|
||||
}
|
||||
catch (const std::exception &err) {
|
||||
error_message(std::string { "failed to serialize json data" });
|
||||
} catch (const std::exception &err) {
|
||||
error_message(std::string {"failed to serialize json data"});
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
undo_data_t::read(const std::vector<char> &buffer) {
|
||||
void undo_data_t::read(const std::vector<char> &buffer) {
|
||||
try {
|
||||
data = json::parse(std::begin(buffer), std::end(buffer));
|
||||
}
|
||||
catch (const std::exception &err) {
|
||||
error_message(std::string { "failed to parse json data: " } + err.what());
|
||||
} catch (const std::exception &err) {
|
||||
error_message(std::string {"failed to parse json data: "} + err.what());
|
||||
data = {};
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
undo_data_t::merge(const undo_data_t &newer_data) {
|
||||
void undo_data_t::merge(const undo_data_t &newer_data) {
|
||||
const auto &swapchain_data = newer_data.get_opengl_swapchain();
|
||||
if (swapchain_data) {
|
||||
set_opengl_swapchain(swapchain_data->our_value, swapchain_data->undo_value);
|
||||
|
||||
Reference in New Issue
Block a user