overview.html 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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-4 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 - Overview</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">Overview</h2>
  24. </td>
  25. </tr>
  26. </table>
  27. <hr>
  28. <dl class="index">
  29. <dt><a href="#Requirements">Requirements</a></dt>
  30. <dt><a href="#otherimplementations">Other Implementations</a></dt>
  31. </dl>
  32. <p>Here, we use the term <strong>"serialization"</strong> to mean
  33. the reversible deconstruction of an arbitrary set of C++ data structures
  34. to a sequence of bytes. Such a system can be used to reconstitute
  35. an equivalent structure in another program context. Depending on
  36. the context, this might used implement object persistence, remote
  37. parameter passing or other facility. In this system we use the term
  38. <strong>"archive"</strong> to refer to a specific rendering of this
  39. stream of bytes. This could be a file of binary data, text data,
  40. XML, or some other created by the user of this library.
  41. <h2><a name="Requirements"></a>Our goals for such a system are:</h2>
  42. <ol>
  43. <li>Code portability - depend only on ANSI C++ facilities.
  44. <li>Code economy - exploit features of C++ such as RTTI,
  45. templates, and multiple inheritance, etc. where appropriate to
  46. make code shorter and simpler to use.
  47. <li>Independent versioning for each class definition. That
  48. is, when a class definition changed, older files can still be
  49. imported to the new version of the class.
  50. <li>Deep pointer save and restore. That is, save and restore
  51. of pointers saves and restores the data pointed to.
  52. <li>Proper restoration of pointers to shared data.
  53. <li>Serialization of STL containers and other commonly used
  54. templates.
  55. <li>Data Portability - Streams of bytes created on one platform
  56. should be readable on any other.
  57. <li>Orthogonal specification of class serialization and archive format.
  58. That is, any file format should be able to store serialization
  59. of any arbitrary set of C++ data structures without having to
  60. alter the serialization of any class.
  61. <li>Non-intrusive. Permit serialization to be applied to
  62. unaltered classes. That is, don't require that classes to be
  63. serialized be derived from a specific base class or implement
  64. specified member functions. This is necessary to easily
  65. permit serialization to be applied to classes from class
  66. libraries that we cannot or don't want to have to alter.
  67. <li> The <strong>archive</strong> interface must be simple
  68. enough to easily permit creation of a new type of archive.
  69. <li> The <strong>archive</strong> interface must be rich
  70. enough to permit the creation of an <strong>archive</strong>
  71. that presents serialized data as XML in a useful manner.
  72. </ol>
  73. <h2><a name="otherimplementations"></a>Other implementations</h2>
  74. Before getting started I searched around for current
  75. implementations. I found several.
  76. <ul>
  77. <li><u>MFC</u> This is the one that I am very familiar with.
  78. I have used it for several years and have found it very useful.
  79. However it fails requirements 1, 2, 3, 6, 7, and 9. In spite
  80. of all the requirements not fulfilled, this is the most
  81. useful implementation I've found. It turns out that class
  82. versioning - partially implemented in MFC - really is
  83. indispensable for my applications. Inevitably, version 1.x of
  84. a shipping program needs to store more information in files
  85. than was originally provided for. MFC is the only one of these
  86. implementations that supports this - though only for the most
  87. derived class. Still it's better than nothing and does the
  88. job. MFC doesn't implement serialization of STL collections.
  89. Though it does so for MFC collections.
  90. <li><u>CommonC++ libraries</u> <a href="bibliography.html#1">[1]</a>
  91. As far as I can tell, this
  92. closely follows the MFC implementation but does address a few
  93. of the issues. It is portable and creates portable archives but
  94. skips versioning. It does support proper and complete
  95. restoration of pointers and STL collections. It does address
  96. compression though not in the way that I would prefer. The
  97. package would also benefit from having better documentation.
  98. So it fails to address 2, 3, 7, 8, and 9.
  99. <li><u>Eternity</u> <a href="bibliography.html#2">[2]</a>
  100. This is a bare bones package. It
  101. seems well coded but it really needs documentation and
  102. examples. It's not obvious how to use it without time
  103. consuming study of the source code. Recent versions do support
  104. files in XML format. This Fails 3, 6, 7?, 8, and 9.
  105. <li><u>Holub's implementation</u> <a href="bibliography.html#3">[3]</a> This is the article that
  106. first got me thinking about my own requirements for
  107. a serialization implementation. Interesting and worth
  108. the read if you can overlook the arrogant tone of the prose.
  109. This implementation fails 2, 3, 4, 5, and 6.
  110. <li><u>s11n</u> <a href="bibliography.html#13">[13]</a>
  111. This library has similar goals to this one. Some aspects of the
  112. implemenation are also similar. As of this writing, it would seem that:
  113. <ul>
  114. <li>Portability(1) is guarenteed only for recent versions of GCC.
  115. <li>Versioning(3) of class definitions is not explicitly supported by
  116. the library.
  117. <li>it doesn't seem to automatically account for shared pointers(5).
  118. I concluded this from the documentation as well as the statement that
  119. serialization of graph like structures is not supported.
  120. </ul>
  121. Its has lots of differences - and lots in common with this implementation.
  122. </ul>
  123. <hr>
  124. <p>Revised 1 November, 2004
  125. <p><i>&copy; Copyright <a href="http://www.rrsd.com">Robert Ramey</a> 2002-2004.
  126. Distributed under the Boost Software License, Version 1.0. (See
  127. accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  128. </i></p>
  129. </body>
  130. </html>