fix: merge back in relevant changes from ad5fa4030489ac6dadd6f29b3b5338ec3d4f3ea4
This commit is contained in:
parent
5f49ede204
commit
d93c906850
@ -1 +1 @@
|
||||
Subproject commit 5ec7201e2f968c6bcba5f18bf9aa5ab2c15e3365
|
||||
Subproject commit 9b901bad31f9809f4bfaefc8795589db3ce46250
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <core/enums/enums.hpp>
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
namespace Soundux
|
||||
|
@ -4,8 +4,45 @@
|
||||
#include <helper/version/check.hpp>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace Soundux
|
||||
{
|
||||
namespace traits
|
||||
{
|
||||
template <typename T> struct is_optional
|
||||
{
|
||||
private:
|
||||
static std::uint8_t test(...);
|
||||
template <typename O> static auto test(std::optional<O> *) -> std::uint16_t;
|
||||
|
||||
public:
|
||||
static const bool value = sizeof(test(reinterpret_cast<std::decay_t<T> *>(0))) == sizeof(std::uint16_t);
|
||||
};
|
||||
} // namespace traits
|
||||
} // namespace Soundux
|
||||
|
||||
namespace nlohmann
|
||||
{
|
||||
template <typename T> struct adl_serializer<std::optional<T>>
|
||||
{
|
||||
static void to_json(json &j, const std::optional<T> &obj)
|
||||
{
|
||||
if (obj)
|
||||
{
|
||||
j = *obj;
|
||||
}
|
||||
else
|
||||
{
|
||||
j = nullptr;
|
||||
}
|
||||
}
|
||||
static void from_json(const json &j, const std::optional<T> &obj)
|
||||
{
|
||||
if (!j.is_null())
|
||||
{
|
||||
obj = j.get<T>();
|
||||
}
|
||||
}
|
||||
}; // namespace nlohmann
|
||||
template <> struct adl_serializer<Soundux::Objects::Sound>
|
||||
{
|
||||
static void to_json(json &j, const Soundux::Objects::Sound &obj)
|
||||
@ -18,25 +55,10 @@ namespace nlohmann
|
||||
{"id", obj.id},
|
||||
{"path", obj.path},
|
||||
{"isFavorite", obj.isFavorite},
|
||||
{"localVolume", obj.localVolume},
|
||||
{"remoteVolume", obj.remoteVolume},
|
||||
{"modifiedDate", obj.modifiedDate},
|
||||
};
|
||||
|
||||
if (obj.localVolume)
|
||||
{
|
||||
j["localVolume"] = *obj.localVolume;
|
||||
}
|
||||
else
|
||||
{
|
||||
j["localVolume"] = nullptr;
|
||||
}
|
||||
if (obj.remoteVolume)
|
||||
{
|
||||
j["remoteVolume"] = *obj.remoteVolume;
|
||||
}
|
||||
else
|
||||
{
|
||||
j["remoteVolume"] = nullptr;
|
||||
}
|
||||
}
|
||||
static void from_json(const json &j, Soundux::Objects::Sound &obj)
|
||||
{
|
||||
@ -130,6 +152,18 @@ namespace nlohmann
|
||||
template <typename T> static void get_to_safe(const json &j, const std::string &key, T &member) noexcept
|
||||
{
|
||||
if (j.find(key) != j.end())
|
||||
{
|
||||
if constexpr (Soundux::traits::is_optional<T>::value)
|
||||
{
|
||||
if (j.at(key).type_name() == nlohmann::basic_json(typename T::value_type{}).type_name())
|
||||
{
|
||||
if (!j.at(key).is_null())
|
||||
{
|
||||
member = j.at(key).get<typename T::value_type>();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (j.at(key).type_name() == nlohmann::basic_json(T{}).type_name())
|
||||
{
|
||||
@ -137,6 +171,7 @@ namespace nlohmann
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void from_json(const json &j, Soundux::Objects::Settings &obj)
|
||||
{
|
||||
@ -277,22 +312,5 @@ namespace nlohmann
|
||||
};
|
||||
}
|
||||
};
|
||||
template <> struct adl_serializer<std::optional<Soundux::Objects::RecordingDevice>>
|
||||
{
|
||||
static void to_json(json &j, const std::optional<Soundux::Objects::RecordingDevice> &obj)
|
||||
{
|
||||
if (obj)
|
||||
{
|
||||
j = {
|
||||
{"name", obj->getName()},
|
||||
{"guid", obj->getGUID()},
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
j = "null";
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif
|
||||
} // namespace nlohmann
|
@ -5,7 +5,12 @@
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <optional>
|
||||
|
||||
#pragma push_macro("UNICOCDE")
|
||||
#undef UNICODE
|
||||
#include <process.hpp>
|
||||
#pragma pop_macro("UNICOCDE")
|
||||
|
||||
#include <regex>
|
||||
#include <system_error>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user