28#include <unordered_map>
45 return reinterpret_cast<ObjectId>(p);
59 std::vector<boost::recursive_variant_>,
60 std::unordered_map<int, boost::recursive_variant_>,
61 std::unordered_map<std::string, boost::recursive_variant_>>::type;
63using PackedMap = std::vector<std::pair<std::string, PackedVariant>>;
74 mutable std::unordered_map<ObjectId, ObjectRef> m_objects;
78 auto const &
objects()
const {
return m_objects; }
82 std::vector<PackedVariant>
ret(
vec.size());
84 std::ranges::transform(
vec,
ret.begin(), [
this](
const Variant &v) {
85 return boost::apply_visitor(*this, v);
93 auto operator()(
const std::unordered_map<K, Variant> &map)
const {
94 std::unordered_map<K, PackedVariant>
ret{};
96 for (
auto const &
it : map) {
97 ret.insert({
it.first, boost::apply_visitor(*
this,
it.second)});
114 return std::forward<T>(
val);
124 std::unordered_map<ObjectId, ObjectRef>
const &
objects;
131 std::vector<Variant>
ret(
vec.size());
134 return boost::apply_visitor(*this, v);
141 template <
typename K>
142 auto operator()(
const std::unordered_map<K, PackedVariant> &map)
const {
143 std::unordered_map<K, Variant>
ret{};
145 for (
auto const &
it : map) {
146 ret.insert({
it.first, boost::apply_visitor(*
this,
it.second)});
154 return std::forward<T>(
val);
183 std::unordered_map<ObjectId, ObjectRef>
const &objects) {
196 std::ranges::transform(v,
ret.begin(), [](
auto const &kv) {
197 return std::pair<std::string, PackedVariant>{kv.first, pack(kv.second)};
211 std::unordered_map<ObjectId, ObjectRef>
const &objects) {
214 std::ranges::transform(
215 v, std::inserter(ret, ret.end()),
216 [&objects](
auto const &kv) -> std::pair<std::string, Variant> {
217 return {kv.first, unpack(kv.second, objects)};
Type to indicate no value in Variant.
Base class for interface handles.
PackedVariant pack(const Variant &v)
Transform a Variant to a PackedVariant.
std::shared_ptr< ObjectHandle > ObjectRef
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
std::unordered_map< std::string, Variant > VariantMap
boost::make_recursive_variant< None, bool, int, std::size_t, double, std::string, ObjectRef, Utils::Vector3b, Utils::Vector3i, Utils::Vector2d, Utils::Vector3d, Utils::Vector4d, std::vector< int >, std::vector< double >, std::vector< boost::recursive_variant_ >, std::unordered_map< int, boost::recursive_variant_ >, std::unordered_map< std::string, boost::recursive_variant_ > >::type Variant
Possible types for parameters.
std::vector< std::pair< std::string, PackedVariant > > PackedMap
Variant unpack(const PackedVariant &v, std::unordered_map< ObjectId, ObjectRef > const &objects)
Unpack a PackedVariant.
boost::make_recursive_variant< None, bool, int, std::size_t, double, std::string, ObjectId, Utils::Vector3b, Utils::Vector3i, Utils::Vector2d, Utils::Vector3d, Utils::Vector4d, std::vector< int >, std::vector< double >, std::vector< boost::recursive_variant_ >, std::unordered_map< int, boost::recursive_variant_ >, std::unordered_map< std::string, boost::recursive_variant_ > >::type PackedVariant
Packed version of Variant.
ObjectId object_id(const ObjectHandle *p)
Id for object.
Utils::Vector< bool, 3 > Vector3b
Visitor that converts a Variant to a PackedVariant.
auto operator()(const std::unordered_map< K, Variant > &map) const
PackedVariant operator()(const ObjectRef &so_ptr) const
PackedVariant operator()(T &&val) const
auto operator()(const std::vector< Variant > &vec) const
auto const & objects() const
Map of objects whose references were replaced by ids.
Visitor that converts a PackedVariant to a Variant.
auto operator()(const std::vector< PackedVariant > &vec) const
UnpackVisitor(std::unordered_map< ObjectId, ObjectRef > const &objects)
Variant operator()(const ObjectId &id) const
Variant operator()(T &&val) const
auto operator()(const std::unordered_map< K, PackedVariant > &map) const
std::unordered_map< ObjectId, ObjectRef > const & objects