• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<!--
4(C) Copyright 2002-10 Robert Ramey - http://www.rrsd.com .
5Use, modification and distribution is subject to the Boost Software
6License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7http://www.boost.org/LICENSE_1_0.txt)
8-->
9<head>
10<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
11<link rel="stylesheet" type="text/css" href="../../../boost.css">
12<link rel="stylesheet" type="text/css" href="style.css">
13<title>Serialization - Derivation from an Existing Archive</title>
14</head>
15<body link="#0000ff" vlink="#800080">
16<table border="0" cellpadding="7" cellspacing="0" width="100%" summary="header">
17  <tr>
18    <td valign="top" width="300">
19      <h3><a href="../../../index.htm"><img height="86" width="277" alt="C++ Boost" src="../../../boost.png" border="0"></a></h3>
20    </td>
21    <td valign="top">
22      <h1 align="center">Serialization</h1>
23      <h2 align="center">A Simple Logging Archive Class</h2>
24    </td>
25  </tr>
26</table>
27<hr>
28The purpose of this example is to help clarify the usage of the
29<a href="archives.html"><strong>Archive Concept</strong></a>
30so that one can implement his own archive classes.
31<a href="../example/simple_log_archive.hpp" target="simple_archive_hpp">
32<code>simple_log_archive.hpp</code></a> implements a simple but useful
33archive class. This class can be used to send any serializable types
34on an output text stream in a readable format. Usage of this facility
35is trivially easy:
36
37<pre><code>
38#include "simple_log_archive.hpp"
39...
40// display the complete schedule
41simple_log_archive log(std::cout);
42log << schedule;
43</code></pre>
44
45and it produces the following output
46
47<pre><code>
48schedule
49 count 6
50 item
51  first
52   driver bob
53   hour 6
54   minute 24
55  second ->
56   stops
57    count 3
58    item ->
59     latitude
60      degrees 34
61      minutes 135
62      seconds 52.56
63     longitude
64      degrees 134
65      minutes 22
66      seconds 78.3
67...
68</code></pre>
69
70The complete example is <a href="../example/demo_simple_log.cpp" target="demo_simple_log_cpp">
71<code>demo_simple_log.cpp</code></a>.  Look at
72<a href="archive_reference.html#trivial">Trivial Archive</a> to get a
73better understanding of how this works.
74
75Also, note the following:
76<ul>
77  <li>Only 160 lines of code.
78  <li>Header only - linking with the serialization library not required.
79  <li>Displays ALL <a href="serialization.html"><strong>Serializable</strong></a> types.
80  <li>Lacks some features.
81  <ul>
82    <li>it will not display the data from the derived type given the pointer to a
83    polymorphic base class.  That is, only displays the information of the base class.
84    To add that see the next example.
85    <li>doesn't display information serialized as binary data
86  </ul>
87</ul>
88
89<hr>
90<p><i>&copy; Copyright <a href="http://www.rrsd.com">Robert Ramey</a> 2002-2010.
91Distributed under the Boost Software License, Version 1.0. (See
92accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
93</i></p>
94</body>
95</html>
96