simple_log.html 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 .
  5. Use, modification and distribution is subject to the Boost Software
  6. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. http://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>
  28. The purpose of this example is to help clarify the usage of the
  29. <a href="archives.html"><strong>Archive Concept</strong></a>
  30. so 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
  33. archive class. This class can be used to send any serializable types
  34. on an output text stream in a readable format. Usage of this facility
  35. is trivially easy:
  36. <pre><code>
  37. #include "simple_log_archive.hpp"
  38. ...
  39. // display the complete schedule
  40. simple_log_archive log(std::cout);
  41. log << schedule;
  42. </code></pre>
  43. and it produces the following output
  44. <pre><code>
  45. schedule
  46. count 6
  47. item
  48. first
  49. driver bob
  50. hour 6
  51. minute 24
  52. second ->
  53. stops
  54. count 3
  55. item ->
  56. latitude
  57. degrees 34
  58. minutes 135
  59. seconds 52.56
  60. longitude
  61. degrees 134
  62. minutes 22
  63. seconds 78.3
  64. ...
  65. </code></pre>
  66. The complete example is <a href="../example/demo_simple_log.cpp" target="demo_simple_log_cpp">
  67. <code>demo_simple_log.cpp</code></a>. Look at
  68. <a href="archive_reference.html#trivial">Trivial Archive</a> to get a
  69. better understanding of how this works.
  70. Also, note the following:
  71. <ul>
  72. <li>Only 160 lines of code.
  73. <li>Header only - linking with the serialization library not required.
  74. <li>Displays ALL <a href="serialization.html"><strong>Serializable</strong></a> types.
  75. <li>Lacks some features.
  76. <ul>
  77. <li>it will not display the data from the derived type given the pointer to a
  78. polymorphic base class. That is, only displays the information of the base class.
  79. To add that see the next example.
  80. <li>doesn't display information serialized as binary data
  81. </ul>
  82. </ul>
  83. <hr>
  84. <p><i>&copy; Copyright <a href="http://www.rrsd.com">Robert Ramey</a> 2002-2010.
  85. Distributed under the Boost Software License, Version 1.0. (See
  86. accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  87. </i></p>
  88. </body>
  89. </html>