Skip to content

Commit

Permalink
#376: rename virtual serialize macros
Browse files Browse the repository at this point in the history
  • Loading branch information
cz4rs committed Nov 20, 2024
1 parent 50d8d8f commit 8aaf3fa
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 42 deletions.
22 changes: 11 additions & 11 deletions docs/shared/checkpoint_learn_serialize.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

*Serialization* is the process of recursively traversing C++ objects into a
simple format that can be stored or transmitted and reconstructed later.
*checkpoint* translates the object into a set of contiguous bits and provides
*magistrate* translates the object into a set of contiguous bits and provides
the steps to reverse the process, i.e. to reconstitute the object from the set
of bits.

Expand Down Expand Up @@ -55,15 +55,15 @@ to actually perform the serialization.

\subsection reconstruct_class Class reconstruction

There are several ways to allow *checkpoint* to reconstruct a
class. *checkpoint* will try to detect a reconstruction strategy in the
There are several ways to allow *magistrate* to reconstruct a
class. *magistrate* will try to detect a reconstruction strategy in the
following resolution order:
1. Tagged constructor: `MyClass(checkpoint::SERIALIZE_CONSTRUCT_TAG) {}`
1. Tagged constructor: `MyClass(magistrate::SERIALIZE_CONSTRUCT_TAG) {}`
1. Reconstruction `MyClass::reconstruct(buf)` or `reconstruct(MyClass, buf)`
1. Default constructor: `MyClass()`

If no reconstruct strategy is detected with type traits, *checkpoint* will fail
at compile-time with a static assertion indicating that *checkpoint* can't
If no reconstruct strategy is detected with type traits, *magistrate* will fail
at compile-time with a static assertion indicating that *magistrate* can't
reconstruct the class.

The example in \ref ckpt_learn_ex1 illustrates the reconstruct method.
Expand All @@ -82,11 +82,11 @@ serialization of the class state.

To serialize polymorphic class hierarchies, one must write serializers for each
class in the hierarchy. Then, the user should either insert macros
`checkpoint_virtual_serialize_root()` and
`checkpoint_virtual_serialize_derived_from(T)` to inform *checkpoint* of the
`magistrate_virtual_serialize_root()` and
`magistrate_virtual_serialize_derived_from(T)` to inform *magistrate* of the
hierarchy so it can automatically traverse the hierarchy. Alternatively, the
user may use the inheritance wrappers `checkpoint::SerializableBase<T>` and
`checkpoint::SerializableDerived<T, U>` to achieve the same effect.
user may use the inheritance wrappers `magistrate::SerializableBase<T>` and
`magistrate::SerializableDerived<T, U>` to achieve the same effect.

The example in \ref ckpt_learn_ex6_polymorphic_macro illustrates the
approach uses the macros. The example in \ref ckpt_learn_example_polymorphic
Expand All @@ -99,6 +99,6 @@ illustrates this approach.
type.

- If one has a raw pointer, `Teuchos::RCP<T>`, or `std::shared_ptr<T>`,
`checkpoint::allocateConstructForPointer<SerializerT,T>(s, ptr)` can be
`magistrate::allocateConstructForPointer<SerializerT,T>(s, ptr)` can be
invoked to properly allocate and construct the concrete class depending on
runtime type.
8 changes: 4 additions & 4 deletions examples/checkpoint_example_polymorphic_macro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct MyBase {
virtual ~MyBase() = default;

// Add serializing macro
checkpoint_virtual_serialize_root()
magistrate_virtual_serialize_root()

int val_ = 0;

Expand All @@ -76,7 +76,7 @@ struct MyObj : public MyBase {
explicit MyObj(::magistrate::SERIALIZE_CONSTRUCT_TAG) {}

// Add macro for serialization
checkpoint_virtual_serialize_derived_from(MyBase)
magistrate_virtual_serialize_derived_from(MyBase)

template <typename SerializerT>
void serialize(SerializerT&) {
Expand All @@ -94,7 +94,7 @@ struct MyObj2 : public MyBase {
explicit MyObj2(::magistrate::SERIALIZE_CONSTRUCT_TAG) {}

// Add macro for serialization
checkpoint_virtual_serialize_derived_from(MyBase)
magistrate_virtual_serialize_derived_from(MyBase)

template <typename SerializerT>
void serialize(SerializerT&) {
Expand All @@ -114,7 +114,7 @@ struct MyObj3 : public MyBase {
explicit MyObj3(::magistrate::SERIALIZE_CONSTRUCT_TAG) {}

// Add macro for serialization
checkpoint_virtual_serialize_derived_from(MyBase)
magistrate_virtual_serialize_derived_from(MyBase)

template <typename SerializerT>
void serialize(SerializerT& s) {
Expand Down
8 changes: 4 additions & 4 deletions examples/checkpoint_example_polymorphic_macro_nonintrusive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct MyBase {
virtual ~MyBase() = default;

// Add serializing macro
checkpoint_virtual_serialize_root()
magistrate_virtual_serialize_root()

int val_ = 0;

Expand All @@ -71,7 +71,7 @@ struct MyObj : public MyBase {
explicit MyObj(::checkpoint::SERIALIZE_CONSTRUCT_TAG) {}

// Add macro for serialization
checkpoint_virtual_serialize_derived_from(MyBase)
magistrate_virtual_serialize_derived_from(MyBase)

void test() override {
printf("test MyObj 10 == %d ?\n", val_);
Expand All @@ -84,7 +84,7 @@ struct MyObj2 : public MyBase {
explicit MyObj2(::checkpoint::SERIALIZE_CONSTRUCT_TAG) {}

// Add macro for serialization
checkpoint_virtual_serialize_derived_from(MyBase)
magistrate_virtual_serialize_derived_from(MyBase)

void test() override {
printf("test MyObj2 20 == %d ?\n", val_);
Expand All @@ -100,7 +100,7 @@ struct MyObj3 : public MyBase {
explicit MyObj3(::checkpoint::SERIALIZE_CONSTRUCT_TAG) {}

// Add macro for serialization
checkpoint_virtual_serialize_derived_from(MyBase)
magistrate_virtual_serialize_derived_from(MyBase)

void test() override {
printf("val_ 30 a 10 b 20 c 100 = %d %d %d %d\n", val_, a, b, c);
Expand Down
4 changes: 2 additions & 2 deletions src/checkpoint/dispatch/dispatch_virtual.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
*
* - Insert checkpoint macros in your virtual class hierarchy for derived and
* base classes with the corresponding macros:
* - \c checkpoint_virtual_serialize_root()
* - \c checkpoint_virtual_serialize_derived_from(ParentT)
* - \c magistrate_virtual_serialize_root()
* - \c magistrate_virtual_serialize_derived_from(ParentT)
*
* --------------------------- Invocation ------------------------------------
*
Expand Down
6 changes: 3 additions & 3 deletions src/checkpoint/dispatch/vrt/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#include "checkpoint/dispatch/vrt/inheritance_assert_helpers.h"
#include "checkpoint/dispatch/vrt/serialize_instantiator.h"

#define checkpoint_virtual_serialize_root() \
#define magistrate_virtual_serialize_root() \
auto _CheckpointVSBaseTypeFn() -> decltype(auto) { return this; } \
virtual void _checkpointDynamicSerialize( \
void* s, \
Expand All @@ -74,7 +74,7 @@
return ::checkpoint::dispatch::vrt::objregistry::makeObjIdx<_CheckpointBaseType>(); \
}

#define checkpoint_virtual_serialize_base(BASE) checkpoint_virtual_serialize_root()
#define magistrate_virtual_serialize_base(BASE) magistrate_virtual_serialize_root()

namespace checkpoint { namespace dispatch { namespace vrt {

Expand All @@ -86,7 +86,7 @@ namespace checkpoint { namespace dispatch { namespace vrt {
*/
template <typename BaseT>
struct SerializableBase {
checkpoint_virtual_serialize_root()
magistrate_virtual_serialize_root()

virtual ~SerializableBase() {}
};
Expand Down
6 changes: 3 additions & 3 deletions src/checkpoint/dispatch/vrt/derived.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#include "checkpoint/dispatch/vrt/inheritance_assert_helpers.h"
#include "checkpoint/dispatch/vrt/serialize_instantiator.h"

#define checkpoint_virtual_serialize_derived_from(PARENT) \
#define magistrate_virtual_serialize_derived_from(PARENT) \
void _checkpointDynamicSerialize( \
void* s, \
::checkpoint::dispatch::vrt::TypeIdx base_ser_idx, \
Expand Down Expand Up @@ -85,7 +85,7 @@
return ::checkpoint::dispatch::vrt::objregistry::makeObjIdx<_CheckpointDerivedType>(); \
}

#define checkpoint_virtual_serialize_derived(DERIVED, PARENT) checkpoint_virtual_serialize_derived_from(PARENT)
#define magistrate_virtual_serialize_derived(DERIVED, PARENT) magistrate_virtual_serialize_derived_from(PARENT)

namespace checkpoint { namespace dispatch { namespace vrt {

Expand Down Expand Up @@ -124,7 +124,7 @@ struct SerializableDerived : BaseT {

SerializableDerived() = default;

checkpoint_virtual_serialize_derived(DerivedT, BaseT)
magistrate_virtual_serialize_derived(DerivedT, BaseT)
};

}}} /* end namespace checkpoint::dispatch::vrt */
Expand Down
2 changes: 1 addition & 1 deletion src/checkpoint/dispatch/vrt/inheritance_assert_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ inline void assertTypeIdxMatch(TypeIdx const expected_idx) {
"\" does not matched expected value. "
"You are probably missing a SerializableBase<T> or SerializableDerived<T> "
"in the virtual class hierarchy; or, if you are using macros: "
"checkpoint_virtual_serialize_root() or checkpoint_virtual_serialize_derived_from(..)";
"magistrate_virtual_serialize_root() or magistrate_virtual_serialize_derived_from(..)";
checkpointAssert(
obj_idx == expected_idx or expected_idx == no_type_idx, debug_str.c_str()
);
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_footprinter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void serialize(Serializer& s, Test2 t) {

struct TestBase {

checkpoint_virtual_serialize_root()
magistrate_virtual_serialize_root()

virtual ~TestBase() = default;

Expand All @@ -100,7 +100,7 @@ struct TestDerived2 : TestBase {
explicit TestDerived2(int) {}
explicit TestDerived2(SERIALIZE_CONSTRUCT_TAG) {}

checkpoint_virtual_serialize_derived_from(TestBase)
magistrate_virtual_serialize_derived_from(TestBase)

template <
typename SerializerT,
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_serialization_error_checking.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ TEST_F(TestObject, test_serialization_error_checking) {
}

struct Base {
checkpoint_virtual_serialize_root()
magistrate_virtual_serialize_root()

virtual ~Base() = default;

Expand All @@ -128,7 +128,7 @@ struct Base {
};

struct Derived : public Base {
checkpoint_virtual_serialize_derived_from(Base)
magistrate_virtual_serialize_derived_from(Base)

int dd{4};

Expand Down
20 changes: 10 additions & 10 deletions tests/unit/test_virtual_serialize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ struct TestBase {
explicit TestBase(TEST_CONSTRUCT) { init(); }
explicit TestBase(SERIALIZE_CONSTRUCT_TAG) {}

checkpoint_virtual_serialize_root()
magistrate_virtual_serialize_root()

virtual ~TestBase() = default;

Expand Down Expand Up @@ -245,7 +245,7 @@ struct TestDerived1 : TestBase {
explicit TestDerived1(TEST_CONSTRUCT tag) : Parent(tag) { init(); }
explicit TestDerived1(SERIALIZE_CONSTRUCT_TAG tag) : Parent(tag) {}

checkpoint_virtual_serialize_derived_from(TestBase)
magistrate_virtual_serialize_derived_from(TestBase)

template <typename SerializerT>
void serialize(SerializerT& s) {
Expand Down Expand Up @@ -278,7 +278,7 @@ struct TestDerived2 : TestBase {
explicit TestDerived2(TEST_CONSTRUCT tag) : Parent(tag) { init(); }
explicit TestDerived2(SERIALIZE_CONSTRUCT_TAG tag) : Parent(tag) {}

checkpoint_virtual_serialize_derived_from(TestBase)
magistrate_virtual_serialize_derived_from(TestBase)

template <typename SerializerT>
void serialize(SerializerT& s) {
Expand Down Expand Up @@ -312,7 +312,7 @@ struct TestDerived3 : TestDerived2 {
explicit TestDerived3(TEST_CONSTRUCT tag) : Parent(tag) { init(); }
explicit TestDerived3(SERIALIZE_CONSTRUCT_TAG tag) : Parent(tag) {}

checkpoint_virtual_serialize_derived_from(TestDerived2)
magistrate_virtual_serialize_derived_from(TestDerived2)

template <typename SerializerT>
void serialize(SerializerT& s) {
Expand Down Expand Up @@ -424,7 +424,7 @@ struct TestBase {
explicit TestBase(TEST_CONSTRUCT) { init(); }
explicit TestBase(SERIALIZE_CONSTRUCT_TAG) {}

checkpoint_virtual_serialize_root()
magistrate_virtual_serialize_root()

virtual ~TestBase() = default;

Expand Down Expand Up @@ -454,7 +454,7 @@ struct TestDerived1 : TestBase {
explicit TestDerived1(TEST_CONSTRUCT tag) : Parent(tag) { init(); }
explicit TestDerived1(SERIALIZE_CONSTRUCT_TAG tag) : Parent(tag) {}

checkpoint_virtual_serialize_derived_from(Parent)
magistrate_virtual_serialize_derived_from(Parent)

template <typename SerializerT>
void serialize(SerializerT& s) {
Expand Down Expand Up @@ -499,7 +499,7 @@ struct TestDerived2 : TestBase {
explicit TestDerived2(TEST_CONSTRUCT tag) : Parent(tag) { init(); }
explicit TestDerived2(SERIALIZE_CONSTRUCT_TAG tag) : Parent(tag) {}

checkpoint_virtual_serialize_derived_from(Parent)
magistrate_virtual_serialize_derived_from(Parent)

template <typename SerializerT>
void serialize(SerializerT& s) {
Expand Down Expand Up @@ -620,7 +620,7 @@ INSTANTIATE_TYPED_TEST_CASE_P(
using TestVirtualSerializeTemplated = TestHarness;

struct HolderBase {
checkpoint_virtual_serialize_root()
magistrate_virtual_serialize_root()

virtual ~HolderBase() = default;

Expand All @@ -630,7 +630,7 @@ struct HolderBase {

template <typename ObjT>
struct HolderObjBase : HolderBase {
checkpoint_virtual_serialize_derived_from(HolderBase)
magistrate_virtual_serialize_derived_from(HolderBase)

virtual ObjT* get() = 0;

Expand All @@ -640,7 +640,7 @@ struct HolderObjBase : HolderBase {

template <typename ObjT>
struct HolderBasic final : HolderObjBase<ObjT> {
checkpoint_virtual_serialize_derived_from(HolderObjBase<ObjT>)
magistrate_virtual_serialize_derived_from(HolderObjBase<ObjT>)

ObjT* get() override { return obj_.get(); }
std::unique_ptr<ObjT> obj_ = nullptr;
Expand Down

0 comments on commit 8aaf3fa

Please sign in to comment.