From f5d6c771ab0ece876fb7b7798f93b15f10e5201f Mon Sep 17 00:00:00 2001 From: Phil Miller Date: Mon, 26 Oct 2020 16:12:52 -0400 Subject: [PATCH 1/3] #138: Virtual Serializer: Add a registered function to attempt dynamic_cast to the registered type --- src/checkpoint/dispatch/vrt/object_registry.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/checkpoint/dispatch/vrt/object_registry.h b/src/checkpoint/dispatch/vrt/object_registry.h index d5d6dc05..ce1664e0 100644 --- a/src/checkpoint/dispatch/vrt/object_registry.h +++ b/src/checkpoint/dispatch/vrt/object_registry.h @@ -59,22 +59,25 @@ namespace objregistry { template struct ObjectEntry { - template + template ObjectEntry( TypeIdx in_idx, std::size_t in_size, Allocator&& in_allocator, - Constructor&& in_constructor + Constructor&& in_constructor, + Caster&& in_caster ) : idx_(in_idx), size_(in_size), allocator_(in_allocator), - constructor_(in_constructor) + constructor_(in_constructor), + caster_(in_caster) { } TypeIdx idx_ = no_type_idx; /**< The type index for this ObjT */ std::size_t size_ = 0; /**< The registered object size */ std::function allocator_; /**< Do standard allocation for object */ std::function constructor_; /**< Construct object on memory */ + std::function caster_; /**< Try to dynamic_cast */ }; template @@ -111,7 +114,8 @@ Registrar::Registrar() { index, sizeof(ObjT), []() -> void* { return std::allocator{}.allocate(1); }, - [](void* buf) -> BaseType* { return dispatch::Reconstructor::constructAllowFail(buf); } + [](void* buf) -> BaseType* { return dispatch::Reconstructor::constructAllowFail(buf); }, + [](void* buf) -> ObjT* { return dynamic_cast(buf); } } ); } From fe6baf879b0b708614195152df5f542a938be88b Mon Sep 17 00:00:00 2001 From: Phil Miller Date: Mon, 26 Oct 2020 16:16:04 -0400 Subject: [PATCH 2/3] #138: Tighten up types --- src/checkpoint/dispatch/vrt/object_registry.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/checkpoint/dispatch/vrt/object_registry.h b/src/checkpoint/dispatch/vrt/object_registry.h index ce1664e0..5d843c4d 100644 --- a/src/checkpoint/dispatch/vrt/object_registry.h +++ b/src/checkpoint/dispatch/vrt/object_registry.h @@ -77,7 +77,7 @@ struct ObjectEntry { std::size_t size_ = 0; /**< The registered object size */ std::function allocator_; /**< Do standard allocation for object */ std::function constructor_; /**< Construct object on memory */ - std::function caster_; /**< Try to dynamic_cast */ + std::function caster_; /**< Try to dynamic_cast */ }; template @@ -115,7 +115,7 @@ Registrar::Registrar() { sizeof(ObjT), []() -> void* { return std::allocator{}.allocate(1); }, [](void* buf) -> BaseType* { return dispatch::Reconstructor::constructAllowFail(buf); }, - [](void* buf) -> ObjT* { return dynamic_cast(buf); } + [](BaseType* buf) -> ObjT* { return dynamic_cast(buf); } } ); } From 14a0ec3377cff18521e23f096e40250c69005fa8 Mon Sep 17 00:00:00 2001 From: Phil Miller Date: Mon, 26 Oct 2020 16:20:54 -0400 Subject: [PATCH 3/3] #138: Correct dynamic_cast --- src/checkpoint/dispatch/vrt/object_registry.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/checkpoint/dispatch/vrt/object_registry.h b/src/checkpoint/dispatch/vrt/object_registry.h index 5d843c4d..03c0b689 100644 --- a/src/checkpoint/dispatch/vrt/object_registry.h +++ b/src/checkpoint/dispatch/vrt/object_registry.h @@ -115,7 +115,7 @@ Registrar::Registrar() { sizeof(ObjT), []() -> void* { return std::allocator{}.allocate(1); }, [](void* buf) -> BaseType* { return dispatch::Reconstructor::constructAllowFail(buf); }, - [](BaseType* buf) -> ObjT* { return dynamic_cast(buf); } + [](BaseType* buf) -> ObjT* { return dynamic_cast(buf); } } ); }