Skip to content

Support vector<bool> when loading and saving json #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.82.1 (2025-07-10)

- Add support for serialization and deserialization of std::vector<bool> for mujinjson.

## 0.82.0 (2025-06-27)

- Add targetTemplateSceneData in RegisterMinViableRegionInfo.
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE )
# make sure to change the version in docs/Makefile
set (MUJINCLIENT_VERSION_MAJOR 0)
set (MUJINCLIENT_VERSION_MINOR 82)
set (MUJINCLIENT_VERSION_PATCH 0)
set (MUJINCLIENT_VERSION_PATCH 1)
set (MUJINCLIENT_VERSION ${MUJINCLIENT_VERSION_MAJOR}.${MUJINCLIENT_VERSION_MINOR}.${MUJINCLIENT_VERSION_PATCH})
set (MUJINCLIENT_SOVERSION ${MUJINCLIENT_VERSION_MAJOR}.${MUJINCLIENT_VERSION_MINOR})
set (CLIENT_SOVERSION ${MUJINCLIENT_VERSION_MAJOR}.${MUJINCLIENT_VERSION_MINOR})
Expand Down
16 changes: 16 additions & 0 deletions include/mujincontrollerclient/mujinjson.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,17 @@ inline void LoadJsonValue(const rapidjson::GenericValue<Encoding, Allocator>& v,
}
}

template <typename Encoding=rapidjson::UTF8<>, typename Allocator=rapidjson::MemoryPoolAllocator<> >
inline void LoadJsonValue(const rapidjson::GenericValue<Encoding, Allocator>& v, std::vector<bool>::reference t) {
if (v.IsInt()) t = v.GetInt();
else if (v.IsBool()) t = v.GetBool();
else if (v.IsString()) {
t = LexicalCast<bool>(v.GetString(), "Bool");
} else {
throw MujinJSONException("Cannot convert json type " + GetJsonString(v) + " to Bool");
}
}

template<typename T, class AllocT = std::allocator<T>, typename Encoding=rapidjson::UTF8<>, typename Allocator=rapidjson::MemoryPoolAllocator<> >
inline void LoadJsonValue(const rapidjson::GenericValue<Encoding, Allocator>& v, std::vector<T, AllocT>& t);

Expand Down Expand Up @@ -715,6 +726,11 @@ inline void SaveJsonValue(rapidjson::GenericValue<Encoding, Allocator>& v, const
v.SetBool(t);
}

template <typename Encoding, typename Allocator, typename Allocator2>
inline void SaveJsonValue(rapidjson::GenericValue<Encoding, Allocator>& v, const std::vector<bool>::reference t, Allocator2& alloc) {
v.SetBool(t);
}

template <typename Encoding, typename Allocator, typename Allocator2>
inline void SaveJsonValue(rapidjson::GenericValue<Encoding, Allocator>& v, const int8_t& t, Allocator2& alloc) {
v.SetInt(t);
Expand Down