Skip to content

Commit

Permalink
#249: Add Traversal example to list
Browse files Browse the repository at this point in the history
  • Loading branch information
thearusable committed Jul 26, 2022
1 parent a562826 commit 7d599a5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
8 changes: 8 additions & 0 deletions docs/md/checkpoint_learn_example_traversal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
\page ckpt_learn_ex_traversal Program Example Traversal

The full code for this *checkpoint* example can be found here:
`examples/checkpoint_example_traversal.cc`

\subsubsection ex Example source code:
\snippet examples/checkpoint_example_traversal.cc Serialization with custom traverser

10 changes: 10 additions & 0 deletions docs/md/checkpoint_learn_example_traversal_nonintrusive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
\page ckpt_learn_ex_traversal_nonintrusive Non-Intrusive Program Example Traversal

\attention All Non-Intrusive serialize methods <b>MUST</b> be placed in the namespace of type which they serialize.

The full code for this *checkpoint* example can be found here:
`examples/checkpoint_example_traversal_nonintrusive.cc`

\subsubsection ex Example source code:
\snippet examples/checkpoint_example_traversal_nonintrusive.cc Non-Intrusive Serialization with custom traverser

3 changes: 2 additions & 1 deletion docs/md/checkpoint_learn_examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
| checkpoint_example_to_file | Serialize / deserialize structure to file | \subpage ckpt_learn_ex_tofile |
| checkpoint_example_polymorphic | Serialization of polymorphic class hierarchy | \subpage ckpt_learn_example_polymorphic |
| checkpoint_example_polymorphic_macro | Serialization of polymorphic class hierarchy with macros | \subpage ckpt_learn_example_polymorphic_macro |
| checkpoint_example_traversal | Serialization with custom traverser | \subpage ckpt_learn_ex_traversal |

&nbsp;
&nbsp;
Expand All @@ -23,4 +24,4 @@ Please do not put serialize methods in global magistrate namespace.
| checkpoint_example_to_file | Serialize / deserialize structure to file | \subpage ckpt_learn_ex_tofile_nonintrusive |
| checkpoint_example_polymorphic | Serialization of polymorphic class hierarchy | \subpage ckpt_learn_example_polymorphic_nonintrusive |
| checkpoint_example_polymorphic_macro | Serialization of polymorphic class hierarchy with macros | \subpage ckpt_learn_example_polymorphic_macro_nonintrusive |

| checkpoint_example_traversal | Serialization with custom traverser | \subpage ckpt_learn_ex_traversal_nonintrusive |
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@
//@HEADER
*/

/// [Serialization with custom traverser]

#include <checkpoint/checkpoint.h>

#include <cstdio>
#include <string>

namespace magistrate::intrusive::examples {
namespace magistrate { namespace intrusive { namespace examples {

struct TestObject {

Expand Down Expand Up @@ -75,7 +77,7 @@ struct TestObject {
std::vector<std::string> vec3;
};

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

/// Custom traverser for printing raw bytes
struct PrintBytesTraverse : checkpoint::Serializer {
Expand Down Expand Up @@ -149,3 +151,5 @@ int main(int, char**) {

return 0;
}

/// [Serialization with custom traverser]
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@
//@HEADER
*/

/// [Non-Intrusive Serialization with custom traverser]

#include <checkpoint/checkpoint.h>

#include <cstdio>
#include <string>

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

struct TestObject {

Expand All @@ -74,11 +76,11 @@ struct TestObject {
std::vector<std::string> vec3;
};

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

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

template <typename Serializer>
void serialize(Serializer& s, TestObject& obj) {
Expand Down Expand Up @@ -147,7 +149,7 @@ struct TypedTraverse : checkpoint::Serializer {
}
};

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

int main(int, char**) {
using namespace magistrate::nonintrusive::examples;
Expand All @@ -163,3 +165,5 @@ int main(int, char**) {

return 0;
}

/// [Non-Intrusive Serialization with custom traverser]

0 comments on commit 7d599a5

Please sign in to comment.