diff --git a/src/checkpoint/dispatch/vrt/base.h b/src/checkpoint/dispatch/vrt/base.h index 4235fbc8..6ce31cd9 100644 --- a/src/checkpoint/dispatch/vrt/base.h +++ b/src/checkpoint/dispatch/vrt/base.h @@ -75,6 +75,38 @@ return ::checkpoint::dispatch::vrt::objregistry::makeObjIdx<_CheckpointBaseType>(); \ } +#define checkpoint_virtual_serialize_root_decl() \ + auto _CheckpointVSBaseTypeFn() -> decltype(auto) { return this; } \ + virtual void _checkpointDynamicSerialize( \ + void* s, \ + ::checkpoint::dispatch::vrt::TypeIdx ser_idx, \ + ::checkpoint::dispatch::vrt::TypeIdx expected_idx \ + ); \ + virtual ::checkpoint::dispatch::vrt::TypeIdx _checkpointDynamicTypeIndex(); + +#define checkpoint_virtual_serialize_root_def(CLASS) \ + void CLASS::_checkpointDynamicSerialize( \ + void* s, \ + ::checkpoint::dispatch::vrt::TypeIdx ser_idx, \ + ::checkpoint::dispatch::vrt::TypeIdx expected_idx \ + ) { \ + using _CheckpointBaseType = \ + ::checkpoint::dispatch::vrt::checkpoint_base_type_t; \ + ::checkpoint::instantiateObjSerializer< \ + _CheckpointBaseType, \ + checkpoint_serializer_variadic_args() \ + >(); \ + ::checkpoint::dispatch::vrt::assertTypeIdxMatch<_CheckpointBaseType>(expected_idx); \ + auto dispatcher = \ + ::checkpoint::dispatch::vrt::serializer_registry::getObjIdx<_CheckpointBaseType>(ser_idx); \ + dispatcher(s, *static_cast<_CheckpointBaseType*>(this)); \ + } \ + ::checkpoint::dispatch::vrt::TypeIdx CLASS::_checkpointDynamicTypeIndex() { \ + using _CheckpointBaseType = \ + ::checkpoint::dispatch::vrt::checkpoint_base_type_t; \ + return ::checkpoint::dispatch::vrt::objregistry::makeObjIdx<_CheckpointBaseType>(); \ + } + #define checkpoint_virtual_serialize_base(BASE) checkpoint_virtual_serialize_root() namespace checkpoint { namespace dispatch { namespace vrt { diff --git a/src/checkpoint/dispatch/vrt/derived.h b/src/checkpoint/dispatch/vrt/derived.h index 81290d01..7dc317b6 100644 --- a/src/checkpoint/dispatch/vrt/derived.h +++ b/src/checkpoint/dispatch/vrt/derived.h @@ -86,6 +86,51 @@ return ::checkpoint::dispatch::vrt::objregistry::makeObjIdx<_CheckpointDerivedType>(); \ } +#define checkpoint_virtual_serialize_derived_decl() \ + void _checkpointDynamicSerialize( \ + void* s, \ + ::checkpoint::dispatch::vrt::TypeIdx base_ser_idx, \ + ::checkpoint::dispatch::vrt::TypeIdx expected_idx \ + ) override; \ + ::checkpoint::dispatch::vrt::TypeIdx _checkpointDynamicTypeIndex() override; + +#define checkpoint_virtual_serialize_derived_from_def(CLASS, PARENT) \ + template <> \ + void CLASS::_checkpointDynamicSerialize( \ + void* s, \ + ::checkpoint::dispatch::vrt::TypeIdx base_ser_idx, \ + ::checkpoint::dispatch::vrt::TypeIdx expected_idx \ + ) { \ + using _CheckpointDerivedType = \ + ::checkpoint::dispatch::vrt::checkpoint_derived_type_t; \ + ::checkpoint::instantiateObjSerializer< \ + _CheckpointDerivedType, \ + checkpoint_serializer_variadic_args() \ + >(); \ + debug_checkpoint( \ + "%s: BEGIN: _checkpointDynamicSerialize: serializer_idx=%d {\n", \ + typeid(_CheckpointDerivedType).name(), base_ser_idx \ + ); \ + ::checkpoint::dispatch::vrt::assertTypeIdxMatch<_CheckpointDerivedType>(expected_idx); \ + auto base_idx = ::checkpoint::dispatch::vrt::objregistry::makeObjIdx(); \ + PARENT::_checkpointDynamicSerialize(s, base_ser_idx, base_idx); \ + auto dispatcher = \ + ::checkpoint::dispatch::vrt::serializer_registry::getBaseIdx<_CheckpointDerivedType>( \ + base_ser_idx \ + ); \ + dispatcher(s, *static_cast<_CheckpointDerivedType*>(this)); \ + debug_checkpoint( \ + "%s: END: _checkpointDynamicSerialize: serializer_idx=%d }\n", \ + typeid(_CheckpointDerivedType).name(), base_ser_idx \ + ); \ + } \ + template <> \ + ::checkpoint::dispatch::vrt::TypeIdx CLASS::_checkpointDynamicTypeIndex() { \ + using _CheckpointDerivedType = \ + ::checkpoint::dispatch::vrt::checkpoint_derived_type_t; \ + return ::checkpoint::dispatch::vrt::objregistry::makeObjIdx<_CheckpointDerivedType>(); \ + } + #define checkpoint_virtual_serialize_derived(DERIVED, PARENT) checkpoint_virtual_serialize_derived_from(PARENT) namespace checkpoint { namespace dispatch { namespace vrt {