aboutsummaryrefslogtreecommitdiff
path: root/source/RapidJsonHelper.hpp
diff options
context:
space:
mode:
authorhnOsmium0001 <[email protected]>2022-04-17 20:08:57 -0700
committerhnOsmium0001 <[email protected]>2022-04-17 20:08:57 -0700
commitd43508ba4843801cbbf1f42a27af260d4eef5701 (patch)
tree39c51368cfe8ec097c08f198877cf07e9ff835ee /source/RapidJsonHelper.hpp
parent509201784d6525fc26345e55a56ab81e4a7616b3 (diff)
Initial work on sprites and texture system
Diffstat (limited to 'source/RapidJsonHelper.hpp')
-rw-r--r--source/RapidJsonHelper.hpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/source/RapidJsonHelper.hpp b/source/RapidJsonHelper.hpp
index 9dc0701..75cd93a 100644
--- a/source/RapidJsonHelper.hpp
+++ b/source/RapidJsonHelper.hpp
@@ -75,4 +75,36 @@ inline GenericStringRef<char> StringRef(std::string_view str) {
str.size());
}
+template <class TIter, class TSentienl>
+rapidjson::Value WriteVectorPrimitives(rapidjson::Document& root, TIter begin, TSentienl end) {
+ using TElement = typename TIter::value_type;
+
+ rapidjson::Value list;
+ while (begin != end) {
+ if constexpr (std::is_same_v<TElement, std::string>) {
+ auto& elm = *begin;
+ list.PushBack(rapidjson::Value(elm.c_str(), elm.size()), root.GetAllocator());
+ } else {
+ list.PushBack(*begin, root.GetAllocator());
+ }
+ ++begin;
+ }
+ return list;
+}
+
+template <class TContainer>
+bool ReadVectorPrimitives(const rapidjson::Value& value, TContainer& list) {
+ using TElement = typename TContainer::value_type;
+
+ if (!value.IsArray()) return false;
+
+ list.reserve(value.Size());
+ for (auto& elm : value.GetArray()) {
+ if (!elm.Is<TElement>()) return {};
+ list.push_back(elm.Get<TElement>());
+ }
+
+ return true;
+}
+
} // namespace rapidjson