Skip to content

Commit

Permalink
#138: Virtual Serializer: Add a registered function to attempt dynami…
Browse files Browse the repository at this point in the history
…c_cast to the registered type
  • Loading branch information
PhilMiller committed Oct 26, 2020
1 parent 318d5bc commit f5d6c77
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/checkpoint/dispatch/vrt/object_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,25 @@ namespace objregistry {
template <typename T>
struct ObjectEntry {

template <typename Allocator, typename Constructor>
template <typename Allocator, typename Constructor, typename Caster>
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<void*(void)> allocator_; /**< Do standard allocation for object */
std::function<T*(void*)> constructor_; /**< Construct object on memory */
std::function<T*(void*)> caster_; /**< Try to dynamic_cast<ObjT> */
};

template <typename T>
Expand Down Expand Up @@ -111,7 +114,8 @@ Registrar<ObjT>::Registrar() {
index,
sizeof(ObjT),
[]() -> void* { return std::allocator<ObjT>{}.allocate(1); },
[](void* buf) -> BaseType* { return dispatch::Reconstructor<ObjT>::constructAllowFail(buf); }
[](void* buf) -> BaseType* { return dispatch::Reconstructor<ObjT>::constructAllowFail(buf); },
[](void* buf) -> ObjT* { return dynamic_cast<ObjT>(buf); }
}
);
}
Expand Down

0 comments on commit f5d6c77

Please sign in to comment.