Skip to content
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

#138: Virtual Serializer: Automatically determine base classes to call #150

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
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*(T*)> 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); },
[](BaseType* buf) -> ObjT* { return dynamic_cast<ObjT*>(buf); }
}
);
}
Expand Down