Skip to content

Commit

Permalink
#260: Use new namespace alias in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
thearusable committed May 20, 2024
1 parent 22313ba commit 4210f9b
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 91 deletions.
4 changes: 2 additions & 2 deletions examples/checkpoint_example_1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

#include <cstdio>

namespace magistrate { namespace intrusive { namespace examples {
namespace checkpoint { namespace intrusive { namespace examples {

// \struct MyTest
// \brief Simple structure with two variables of built-in types
Expand Down Expand Up @@ -105,7 +105,7 @@ struct MyTest {
}
};

}}} // end namespace magistrate::intrusive::examples
}}} // end namespace checkpoint::intrusive::examples

int main(int, char**) {
using namespace magistrate::intrusive::examples;
Expand Down
8 changes: 4 additions & 4 deletions examples/checkpoint_example_1_nonintrusive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#include <cstdio>

// \brief Namespace containing type which will be serialized
namespace magistrate { namespace nonintrusive { namespace examples {
namespace checkpoint { namespace nonintrusive { namespace examples {

// \brief Simple structure with three variables of built-in types
struct MyTest3 {
Expand All @@ -60,12 +60,12 @@ struct MyTest3 {
}
};

}}} // end namespace magistrate::nonintrusive::examples
}}} // end namespace checkpoint::nonintrusive::examples

// \brief Function to serialize the MyTest3 structure.
// In Non-Intrusive way, this function needs to be placed in the namespace
// of the type which will be serialized.
namespace magistrate { namespace nonintrusive { namespace examples {
namespace checkpoint { namespace nonintrusive { namespace examples {
// \brief Templated function for serializing/deserializing
// a variable of type `MyTest3`. Non-nonintrusive version of the function
// placed outside of `MyTest3` structure.
Expand Down Expand Up @@ -93,7 +93,7 @@ namespace magistrate { namespace nonintrusive { namespace examples {
s | my_test3.c;
}

}}} // end namespace magistrate::nonintrusive::examples
}}} // end namespace checkpoint::nonintrusive::examples

int main(int, char**) {
using namespace magistrate::nonintrusive::examples;
Expand Down
4 changes: 2 additions & 2 deletions examples/checkpoint_example_2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

#include <cstdio>

namespace magistrate { namespace intrusive { namespace examples {
namespace checkpoint { namespace intrusive { namespace examples {

// \struct MyTest2
// \brief Simple structure with one variable of built-in type
Expand Down Expand Up @@ -125,7 +125,7 @@ struct MyTest {
}
};

}}} // end namespace magistrate::intrusive::examples
}}} // end namespace checkpoint::intrusive::examples

int main(int, char**) {
using namespace magistrate::intrusive::examples;
Expand Down
8 changes: 4 additions & 4 deletions examples/checkpoint_example_2_nonintrusive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#include <cstdio>

// \brief Namespace containing types which will be serialized
namespace magistrate { namespace nonintrusive { namespace examples {
namespace checkpoint { namespace nonintrusive { namespace examples {

// \struct MyTest2
// \brief Simple structure with one variable of built-in type
Expand Down Expand Up @@ -90,11 +90,11 @@ struct MyTest {
}
};

}}} // end namespace magistrate::nonintrusive::examples
}}} // end namespace checkpoint::nonintrusive::examples

// \brief In Non-Intrusive way, serialize function needs to be placed in the namespace
// of the type which will be serialized.
namespace magistrate { namespace nonintrusive { namespace examples {
namespace checkpoint { namespace nonintrusive { namespace examples {

// \brief Templated function for serializing/deserializing
// a variable of type `MyTest`
Expand Down Expand Up @@ -132,7 +132,7 @@ void serialize(Serializer& s, MyTest2& my_test2) {
s | my_test2.c;
}

}}} // end namespace magistrate::nonintrusive::examples
}}} // end namespace checkpoint::nonintrusive::examples

int main(int, char**) {
using namespace magistrate::nonintrusive::examples;
Expand Down
7 changes: 3 additions & 4 deletions examples/checkpoint_example_3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
// class of a serializable/deserializable type.
//

namespace magistrate { namespace intrusive { namespace examples {
namespace checkpoint { namespace intrusive { namespace examples {

// \brief Structure with a variable of built-in type.
//
Expand Down Expand Up @@ -120,13 +120,12 @@ struct TestReconstruct {
}
};

}}} // end namespace magistrate::intrusive::examples
}}} // end namespace checkpoint::intrusive::examples

#include "checkpoint/traits/serializable_traits.h"

namespace magistrate {
namespace checkpoint {

using namespace ::checkpoint;
using namespace intrusive::examples;

static_assert(
Expand Down
13 changes: 6 additions & 7 deletions examples/checkpoint_example_3_nonintrusive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
//

// \brief Namespace containing types which will be serialized
namespace magistrate { namespace nonintrusive { namespace examples {
namespace checkpoint { namespace nonintrusive { namespace examples {

// \brief Structure with a variable of built-in type.
struct TestDefaultCons {
Expand Down Expand Up @@ -103,11 +103,11 @@ struct TestReconstruct {
}
};

}}} // end namespace magistrate::nonintrusive::examples
}}} // end namespace checkpoint::nonintrusive::examples

// \brief In Non-Intrusive way, serialize function needs to be placed in the namespace
// of the type which will be serialized.
namespace magistrate { namespace nonintrusive { namespace examples {
namespace checkpoint { namespace nonintrusive { namespace examples {

// \brief Non-Intrusive Serialize method for TestDefaultCons structure.
//
Expand All @@ -130,13 +130,12 @@ void serialize(Serializer& s, TestReconstruct& tr) {
s | tr.a;
}

}}} // end namespace magistrate::nonintrusive::examples
}}} // end namespace checkpoint::nonintrusive::examples

#include "checkpoint/traits/serializable_traits.h"

namespace magistrate {
namespace checkpoint {

using namespace ::checkpoint;
using namespace nonintrusive::examples;

static_assert(
Expand All @@ -158,7 +157,7 @@ static_assert(
"Should be serializable"
);

} // end namespace magistrate
} // end namespace checkpoint


int main(int, char**) {
Expand Down
24 changes: 12 additions & 12 deletions examples/checkpoint_example_polymorphic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
#include <checkpoint/checkpoint.h>
#include "checkpoint/dispatch/dispatch_virtual.h"

namespace magistrate { namespace intrusive { namespace examples {
namespace checkpoint { namespace intrusive { namespace examples {

struct MyBase : ::checkpoint::SerializableBase<MyBase> {
struct MyBase : ::magistrate::SerializableBase<MyBase> {
MyBase() { printf("MyBase cons\n"); }
explicit MyBase(::checkpoint::SERIALIZE_CONSTRUCT_TAG) { printf("MyBase recons\n"); }
explicit MyBase(::magistrate::SERIALIZE_CONSTRUCT_TAG) { printf("MyBase recons\n"); }

virtual ~MyBase() = default;

Expand All @@ -65,9 +65,9 @@ struct MyBase : ::checkpoint::SerializableBase<MyBase> {
virtual void test() = 0;
};

struct MyObj : ::checkpoint::SerializableDerived<MyObj, MyBase> {
struct MyObj : ::magistrate::SerializableDerived<MyObj, MyBase> {
explicit MyObj(int val) { printf("MyObj cons\n"); val_ = val;}
explicit MyObj(::checkpoint::SERIALIZE_CONSTRUCT_TAG){}
explicit MyObj(::magistrate::SERIALIZE_CONSTRUCT_TAG){}

template <typename SerializerT>
void serialize(SerializerT&) {
Expand All @@ -80,9 +80,9 @@ struct MyObj : ::checkpoint::SerializableDerived<MyObj, MyBase> {
}
};

struct MyObj2 : ::checkpoint::SerializableDerived<MyObj2, MyBase> {
struct MyObj2 : ::magistrate::SerializableDerived<MyObj2, MyBase> {
explicit MyObj2(int val) { printf("MyObj2 cons\n"); val_=val; }
explicit MyObj2(::checkpoint::SERIALIZE_CONSTRUCT_TAG) {}
explicit MyObj2(::magistrate::SERIALIZE_CONSTRUCT_TAG) {}

template <typename SerializerT>
void serialize(SerializerT&) {
Expand All @@ -94,10 +94,10 @@ struct MyObj2 : ::checkpoint::SerializableDerived<MyObj2, MyBase> {
}
};

struct MyObj3 : ::checkpoint::SerializableDerived<MyObj3, MyBase> {
struct MyObj3 : ::magistrate::SerializableDerived<MyObj3, MyBase> {
int a=0, b=0, c=0;
explicit MyObj3(int val) { printf("MyObj3 cons\n"); a= 10; b=20; c=100; val_=val;}
explicit MyObj3(::checkpoint::SERIALIZE_CONSTRUCT_TAG) {}
explicit MyObj3(::magistrate::SERIALIZE_CONSTRUCT_TAG) {}

template <typename SerializerT>
void serialize(SerializerT& s) {
Expand Down Expand Up @@ -134,21 +134,21 @@ void test() {
v.vec.push_back(std::make_unique<MyObj2>(20));
v.vec.push_back(std::make_unique<MyObj>(10));

auto ret = checkpoint::serialize(v);
auto ret = magistrate::serialize(v);

auto const& buf = ret->getBuffer();
auto const& buf_size = ret->getSize();

printf("ptr=%p, size=%ld\n*****\n\n", static_cast<void*>(buf), buf_size);

auto t = checkpoint::deserialize<ExampleVector>(buf);
auto t = magistrate::deserialize<ExampleVector>(buf);

for (auto&& elm : t->vec) {
elm->test();
}
}

}}} // end namespace magistrate::intrusive::examples
}}} // end namespace checkpoint::intrusive::examples

int main(int, char**) {
using namespace magistrate::intrusive::examples;
Expand Down
16 changes: 8 additions & 8 deletions examples/checkpoint_example_polymorphic_macro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@
#include <checkpoint/checkpoint.h>
#include "checkpoint/dispatch/dispatch_virtual.h"

namespace magistrate { namespace intrusive { namespace examples {
namespace checkpoint { namespace intrusive { namespace examples {

// \struct Abstract base class
struct MyBase {

MyBase() { printf("MyBase cons\n"); }
explicit MyBase(::checkpoint::SERIALIZE_CONSTRUCT_TAG) { printf("MyBase recons\n"); }
explicit MyBase(::magistrate::SERIALIZE_CONSTRUCT_TAG) { printf("MyBase recons\n"); }

virtual ~MyBase() = default;

Expand All @@ -73,7 +73,7 @@ struct MyBase {
struct MyObj : public MyBase {

explicit MyObj(int val) : MyBase() { printf("MyObj cons\n"); val_ = val;}
explicit MyObj(::checkpoint::SERIALIZE_CONSTRUCT_TAG) {}
explicit MyObj(::magistrate::SERIALIZE_CONSTRUCT_TAG) {}

// Add macro for serialization
checkpoint_virtual_serialize_derived_from(MyBase)
Expand All @@ -91,7 +91,7 @@ struct MyObj : public MyBase {

struct MyObj2 : public MyBase {
explicit MyObj2(int val) { printf("MyObj2 cons\n"); val_=val; }
explicit MyObj2(::checkpoint::SERIALIZE_CONSTRUCT_TAG) {}
explicit MyObj2(::magistrate::SERIALIZE_CONSTRUCT_TAG) {}

// Add macro for serialization
checkpoint_virtual_serialize_derived_from(MyBase)
Expand All @@ -111,7 +111,7 @@ struct MyObj3 : public MyBase {
int a=0, b=0, c=0;

explicit MyObj3(int val) { printf("MyObj3 cons\n"); a= 10; b=20; c=100; val_=val;}
explicit MyObj3(::checkpoint::SERIALIZE_CONSTRUCT_TAG) {}
explicit MyObj3(::magistrate::SERIALIZE_CONSTRUCT_TAG) {}

// Add macro for serialization
checkpoint_virtual_serialize_derived_from(MyBase)
Expand Down Expand Up @@ -151,7 +151,7 @@ void test() {
v.vec.push_back(std::make_unique<MyObj2>(20));
v.vec.push_back(std::make_unique<MyObj>(10));

auto ret = checkpoint::serialize(v);
auto ret = magistrate::serialize(v);

{
// Display information about serialization result
Expand All @@ -160,14 +160,14 @@ void test() {
printf("ptr=%p, size=%ld\n*****\n\n", static_cast<void*>(buf), buf_size);
}

auto t = checkpoint::deserialize<ExampleVector>(ret->getBuffer());
auto t = magistrate::deserialize<ExampleVector>(ret->getBuffer());

for (auto&& elm : t->vec) {
elm->test();
}
}

}}} // end namespace magistrate::intrusive::examples
}}} // end namespace checkpoint::intrusive::examples

int main(int, char**) {
using namespace magistrate::intrusive::examples;
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 @@ -47,7 +47,7 @@
#include "checkpoint/dispatch/dispatch_virtual.h"

// \brief Namespace containing types which will be serialized
namespace magistrate { namespace nonintrusive { namespace examples {
namespace checkpoint { namespace nonintrusive { namespace examples {

// \struct Abstract base class
struct MyBase {
Expand Down Expand Up @@ -138,11 +138,11 @@ void test() {
}
}

}}} // end namespace magistrate::nonintrusive::examples
}}} // end namespace checkpoint::nonintrusive::examples

// \brief In Non-Intrusive way, serialize function needs to be placed in the namespace
// of the type which will be serialized.
namespace magistrate { namespace nonintrusive { namespace examples {
namespace checkpoint { namespace nonintrusive { namespace examples {

template <typename S>
void serialize(S& s, MyBase& obj) {
Expand Down Expand Up @@ -173,7 +173,7 @@ void serialize(SerializerT& s, ExampleVector& obj) {
s | obj.vec;
}

}}} // end namespace magistrate::nonintrusive::examples
}}} // end namespace checkpoint::nonintrusive::examples

int main(int, char**) {
using namespace magistrate::nonintrusive::examples;
Expand Down
Loading

0 comments on commit 4210f9b

Please sign in to comment.