From 67affc75a4824dfd8675cc5455d9ee71b1583c1c Mon Sep 17 00:00:00 2001 From: hnOsmium0001 Date: Sun, 10 Apr 2022 22:42:14 -0700 Subject: Add shader and corresponding editor components --- source/RapidJsonHelper.hpp | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 source/RapidJsonHelper.hpp (limited to 'source/RapidJsonHelper.hpp') diff --git a/source/RapidJsonHelper.hpp b/source/RapidJsonHelper.hpp new file mode 100644 index 0000000..ac1f664 --- /dev/null +++ b/source/RapidJsonHelper.hpp @@ -0,0 +1,67 @@ +#pragma once + +#include +#include +#include +#include + +#define BRUSSEL_JSON_GET(object, name, type, out, failAction) \ + { \ + auto it = (object).FindMember(name); \ + if (it == (object).MemberEnd()) failAction; \ + auto& value = it->value; \ + if (!value.Is()) failAction; \ + (out) = value.Get(); \ + } + +#define BRUSSEL_JSON_GET_DEFAULT(object, name, type, out, theDefault) \ + do { \ + auto it = (object).FindMember(name); \ + if (it == (object).MemberEnd()) { \ + (out) = theDefault; \ + break; \ + } \ + auto& value = it->value; \ + if (!value.Is()) { \ + (out) = theDefault; \ + break; \ + } \ + (out) = value.Get(); \ + } while (0); + +namespace rapidjson { + +inline const Value* GetProperty(const Value& value, Type type, std::string_view name) { + for (auto it = value.MemberBegin(); it != value.MemberEnd(); ++it) { + if (it->name.GetStringLength() != name.size()) continue; + if (std::memcmp(it->name.GetString(), name.data(), name.size())) continue; + + return &it->value; + } + return nullptr; +} + +inline std::string_view AsStringView(const Value& value) { + return std::string_view(value.GetString(), value.GetStringLength()); +} + +inline std::string_view AsStringView(const GenericStringRef& strRef) { + return std::string_view(strRef.s, strRef.length); +} + +inline std::string AsString(const Value& value) { + return std::string(value.GetString(), value.GetStringLength()); +} + +inline std::string AsString(const GenericStringRef& strRef) { + return std::string(strRef.s, strRef.length); +} + +// RapidJson itself already provides std::string and const char* overloads +inline GenericStringRef StringRef(std::string_view str) { + return GenericStringRef( + str.data() ? str.data() : "", + str.size()); +} + +} // namespace rapidjson -- cgit v1.2.3-70-g09d2