diff --git a/include/mujincontrollerclient/mujinjson.h b/include/mujincontrollerclient/mujinjson.h index 3d23a788..cb4983d1 100644 --- a/include/mujincontrollerclient/mujinjson.h +++ b/include/mujincontrollerclient/mujinjson.h @@ -511,12 +511,24 @@ inline void LoadJsonValue(const rapidjson::GenericValue& v, } } -template, typename Encoding=rapidjson::UTF8<>, typename Allocator=rapidjson::MemoryPoolAllocator<> > +// These prototypes are necessary to allow recursive container types to be deserialized (e.g, std::vector>) +// Without declaring these up-front, specializations for value types implemented after the containing type will fail to deduce, causing headaches. + +template , typename Encoding = rapidjson::UTF8<>, typename Allocator = rapidjson::MemoryPoolAllocator<>> inline void LoadJsonValue(const rapidjson::GenericValue& v, std::vector& t); -template, typename Allocator=rapidjson::MemoryPoolAllocator<> > +template , typename Allocator = rapidjson::MemoryPoolAllocator<>> inline void LoadJsonValue(const rapidjson::GenericValue& v, std::array& t); +template , typename Allocator = rapidjson::MemoryPoolAllocator<>> +inline void LoadJsonValue(const rapidjson::GenericValue& v, std::map& t); + +template , typename Allocator = rapidjson::MemoryPoolAllocator<>> +inline void LoadJsonValue(const rapidjson::GenericValue& v, std::deque& t); + +template , typename Allocator = rapidjson::MemoryPoolAllocator<>> +inline void LoadJsonValue(const rapidjson::GenericValue& v, std::unordered_map& t); + template, typename Allocator=rapidjson::MemoryPoolAllocator<> > inline void LoadJsonValue(const rapidjson::GenericValue& v, boost::shared_ptr& ptr) { static_assert(std::is_default_constructible::value, "Shared pointer of type must be default-constructible."); @@ -742,12 +754,24 @@ inline void SaveJsonValue(rapidjson::GenericValue& v, const v.CopyFrom(t, alloc); } -template, typename Encoding=rapidjson::UTF8<>, typename Allocator=rapidjson::MemoryPoolAllocator<>, typename Allocator2=rapidjson::MemoryPoolAllocator<> > +// These prototypes are necessary to allow recursive container types to be serialized (e.g, std::vector>) +// Without declaring these up-front, specializations for value types implemented after the containing type will fail to deduce, causing headaches. + +template , typename Encoding = rapidjson::UTF8<>, typename Allocator = rapidjson::MemoryPoolAllocator<>, typename Allocator2 = rapidjson::MemoryPoolAllocator<>> inline void SaveJsonValue(rapidjson::GenericValue& v, const std::vector& t, Allocator2& alloc); -template +template inline void SaveJsonValue(rapidjson::GenericValue& v, const std::array& t, Allocator2& alloc); +template +inline void SaveJsonValue(rapidjson::GenericValue& v, const std::map& t, Allocator2& alloc); + +template +inline void SaveJsonValue(rapidjson::GenericValue& v, const std::unordered_map& t, Allocator2& alloc); + +template +inline void SaveJsonValue(rapidjson::GenericValue& v, const std::deque& t, Allocator2& alloc); + /** do not remove: otherwise boost::shared_ptr could be treated as bool */ template