headers.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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 - Code Structure</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">Code Structure</h2>
  24. </td>
  25. </tr>
  26. </table>
  27. <hr>
  28. <dl class="page-index">
  29. <dt><a href="#userincludes">Files Included by User Programs</a>
  30. <dl class="page-index">
  31. <dt><a href="#archiveimplementations">Archive Implementations</a>
  32. <dt><a href="#serializationdeclarations">Serialization Declarations</a>
  33. <dt><a href="#serializationimplementations">Serialization Implementations</a>
  34. </dl>
  35. <dt><a href="#libraryimplementation">Files Which Implement the Library</a>
  36. <dl class="page-index">
  37. <dt><a href="#archivedevelopment">Archive Development</a>
  38. <dt><a href="#archiveinternals">Archive Internals</a>
  39. <dt><a href="#codemodules">Archive Library Code Modules</a>
  40. <dt><a href="#dataflowiterators">Dataflow Iterators</a>
  41. </dl>
  42. </dl>
  43. This library includes a large number of files. They are organized and classified
  44. according to the purposes listed in the above index.
  45. <p>
  46. <code style="white-space: normal">namespace</code> of classes and templates is synchronized
  47. with the directory in which the file is found. For example, the class declaration
  48. <pre><code>
  49. boost::archive::text_oarchive
  50. </code></pre>
  51. is included with the following declaration
  52. <pre><code>
  53. #include &lt;boost/archive/text_oarchive.hpp&gt;
  54. </code></pre>
  55. <a name="userincludes">
  56. <h3>Files Included by User Programs</h3>
  57. Using this library entails including headers listed in this section.
  58. It should not be necessary to explictly include any other header files.
  59. <a name="archiveimplementations">
  60. <h4>Archive Implementations</h4>
  61. These header files contain declarations used to save and restore data to each type
  62. of archive. Include the archives according to the facilities the code module requires.
  63. <dl>
  64. <dt><a target="archive_exception" href="../../../boost/archive/archive_exception.hpp">
  65. boost/archive/archive_exception.hpp
  66. </a>
  67. <dd>Exceptions which might be invoked by the library.</dd>
  68. <dt><a target="binary_iarchive" href="../../../boost/archive/binary_iarchive.hpp">
  69. boost/archive/binary_iarchive.hpp
  70. </a>
  71. <dd>native binary input archive used for loading.</dd>
  72. <dt><a target="binary_oarchive" href="../../../boost/archive/binary_oarchive.hpp">
  73. boost/archive/binary_oarchive.hpp
  74. </a>
  75. <dd>native binary output archive used for saving.</dd>
  76. <dt><a target="text_iarchive" href="../../../boost/archive/text_iarchive.hpp">
  77. boost/archive/text_iarchive.hpp
  78. </a>
  79. <dd>text input archive used for loading.</dd>
  80. <dt><a target="text_oarchive" href="../../../boost/archive/text_oarchive.hpp">
  81. boost/archive/text_oarchive.hpp
  82. </a>
  83. <dd>text output archive used for saving.</dd>
  84. <dt><a target="text_wiarchive" href="../../../boost/archive/text_wiarchive.hpp">
  85. boost/archive/text_wiarchive.hpp
  86. </a>
  87. <dd>wide character text input archive used for loading.</dd>
  88. <dt><a target="text_woarchive" href="../../../boost/archive/text_woarchive.hpp">
  89. boost/archive/text_woarchive.hpp
  90. </a>
  91. <dd>wide character text input archive used for saving.</dd>
  92. <dt><a target="xml_iarchive" href="../../../boost/archive/xml_iarchive.hpp">
  93. boost/archive/xml_iarchive.hpp
  94. </a>
  95. <dd>xml input archive used for loading.</dd>
  96. <dt><a target="text_oarchive" href="../../../boost/archive/xml_oarchive.hpp">
  97. boost/archive/xml_oarchive.hpp
  98. </a>
  99. <dd>xml output archive used for saving.</dd>
  100. <dt><a target="text_wiarchive" href="../../../boost/archive/xml_wiarchive.hpp">
  101. boost/archive/xml_wiarchive.hpp
  102. </a>
  103. <dd>wide character xml input archive used for loading.</dd>
  104. <dt><a target="text_woarchive" href="../../../boost/archive/xml_woarchive.hpp">
  105. boost/archive/xml_woarchive.hpp
  106. </a>
  107. <dd>wide character xml output archive used for saving.</dd>
  108. </dl>
  109. <a name="serializationdeclarations">
  110. <h4>Serialization Declarations</h4>
  111. To specify how a type is serialized, one codes templates for serialization functions.
  112. In the simplest cases, this does not require the inclusion of any header files for this purpose.
  113. In most cases one or more of the following header files will have to be included in order
  114. to complete or refine the description of the serializaition implementation for a given class.
  115. <dl>
  116. <dt><a target="base_object" href="../../../boost/serialization/base_object.hpp">
  117. boost/serialization/base_object.hpp
  118. </a>
  119. <dd>For serialization of base classes.</dd>
  120. <dt><a target="nvp" href="../../../boost/serialization/nvp.hpp">
  121. boost/serialization/nvp.hpp
  122. </a>
  123. <dd>To associate a name tag with a serializable object. This is necessary to
  124. properly render an xml archive which includes the object name.</dd>
  125. <dt><a target="split_free" href="../../../boost/serialization/split_free.hpp">
  126. boost/serialization/split_free.hpp
  127. </a>
  128. <dd>To divide implementation of <em>non-intrusive</em> serialization into separate
  129. save and load functions.</dd>
  130. <dt><a target="split_member" href="../../../boost/serialization/split_member.hpp">
  131. boost/serialization/split_member.hpp
  132. </a>
  133. <dd>To divide implementation of <em>intrusive</em> serialization into separate
  134. save and load functions.</dd>
  135. <dt><a target="export" href="../../../boost/serialization/export.hpp">
  136. boost/serialization/export.hpp
  137. </a>
  138. <dd>For serialization of pointers to derived classes via key export.</dd>
  139. <dt><a target="assume_abstract" href="../../../boost/serialization/assume_abstract.hpp">
  140. boost/serialization/assume_abstract.hpp
  141. </a>
  142. <dd>This is just a thin wrapper which permits one to explicitly specify that a
  143. particular type is an abstract base class. It is necessary to use this
  144. for compilers which don't support the boost type traits implementation of
  145. is_abstact.
  146. </dd>
  147. </dl>
  148. This group will be required less frequently. The are used to override aspects of
  149. the default implementation of the serialization process for specified types.
  150. <dl>
  151. <dt><a target="version" href="../../../boost/serialization/version.hpp">
  152. boost/serialization/version.hpp
  153. </a>
  154. <dd>To override the default version index (0) assigned to a class.</dd>
  155. <dt><a target="level" href="../../../boost/serialization/level.hpp">
  156. boost/serialization/level.hpp
  157. </a>
  158. <dd>To override the default implementaton level trait for a type.</dd>
  159. <dt><a target="tracking" href="../../../boost/serialization/tracking.hpp">
  160. boost/serialization/tracking.hpp
  161. </a>
  162. <dd>To override the default tracking trait for a type.</dd>
  163. <dt><a target="type_info_implementation" href="../../../boost/serialization/type_info_implementation.hpp">
  164. boost/serialization/type_info_implementation.hpp
  165. </a>
  166. <dd>By default, the library uses RTTI, to identify types at runtime. In some cases, E.G.
  167. such as a platform which doesn't implement RTTI, this header can be included to permit
  168. the override of the default runtime type identification system.</dd>
  169. </dl>
  170. <a name="serializationimplementations">
  171. <h4>Serialization Implementations</h4>
  172. This group of headers includes templates which implement serialization for Standard
  173. Library or Boost Library templates. Any program which uses these templates can
  174. invoke serialization of objects of these types just by including the corresponding header.
  175. <p>
  176. By convention these header files are named:
  177. boost/serialization/xxx.hpp
  178. where xxx is the name of the header file which contains the type to be serialized.
  179. For example, the declaration
  180. <pre><code>
  181. #include &lt;boost/serialization/list.hpp&gt;
  182. </code></pre>
  183. includes the code to implement serialization of the STL
  184. <code style="white-space: normal">std::list</code> type. While
  185. <pre><code>
  186. #include &lt;boost/serialization/shared_ptr.hpp&gt;
  187. </code></pre>
  188. includes code to implement serialization of the BOOST <code style="white-space: normal">boost::shared_ptr</code> type.
  189. Note that including the serialization header for a type automatically includes the
  190. appropriate header of the type to be serialized.
  191. As of this writing, the library includes templates of all STL library templates as well
  192. as templates for <code style="white-space: normal">boost::optional</code>,
  193. <code style="white-space: normal">boost::shared_ptr</code>, and
  194. <code style="white-space: normal">boost::scoped_ptr</code>.
  195. Presumably, this list will expand with the passage of time.
  196. <a name="libraryimplementation">
  197. <h3>Files Which Implement the Library</h3>
  198. <a name="archivedevelopment">
  199. <h4>Archive Development</h4>
  200. These header files contain declarations for basic types used to create
  201. concrete archive types that are made available to users above. Users wishing
  202. to make their own type of archive may want to examine these headers to
  203. see how the archives included with the libary have been constructed.
  204. <dl>
  205. <dt><a target="basic_archive" href="../../../boost/archive/basic_archive.hpp">
  206. boost/archive/basic_archive.hpp
  207. </a>
  208. </dt>
  209. <dd>
  210. This file includes declarations for certain types that have to be accounted
  211. for in all archive implementations. The serialization system relies on
  212. certain special types such as <code style="white-space: normal">class_id_type</code> and others to
  213. record information in archives that is required to reconstruct the original
  214. data structure. These are handled exactly as any other serializable type.
  215. That is, they can be handled as simple primitives such as they are in simple
  216. text files, or with special code as they are in xml archives.
  217. </dd>
  218. <dt><a target="basic_text_oprimitive" href="../../../boost/archive/basic_text_oprimitive.hpp">
  219. boost/archive/basic_text_oprimitive.hpp
  220. </a>
  221. <dt><a target="basic_text_iprimitive" href="../../../boost/archive/basic_text_iprimitive.hpp">
  222. boost/archive/basic_text_iprimitive.hpp
  223. </a>
  224. </dt>
  225. <dd>
  226. Implementation of serialization of primitive types in terms of character
  227. or wide character text streams. This is used in the implementation of text and
  228. xml archives. Presumably this would be useful for implementations of other variations
  229. of text archives such as user friendly text or windows ini files.
  230. </dd>
  231. <dt><a target="basic_binary_oprimitive" href="../../../boost/archive/basic_binary_oprimitive.hpp">
  232. boost/archive/basic_binary_oprimitive.hpp
  233. </a>
  234. <dt><a target="basic_binary_iprimitive" href="../../../boost/archive/basic_binary_iprimitive.hpp">
  235. boost/archive/basic_binary_iprimitive.hpp
  236. </a>
  237. </dt>
  238. <dd>
  239. Implementation of serialization of primitive types in terms of character
  240. or wide character binary streams.
  241. </dd>
  242. <dt><a target="basic_binary_oarchive" href="../../../boost/archive/basic_binary_oarchive.hpp">
  243. boost/archive/basic_binary_oarchive.hpp
  244. </a>
  245. <dt><a target="basic_binary_iarchive" href="../../../boost/archive/basic_binary_iarchive.hpp">
  246. boost/archive/basic_binary_iarchive.hpp
  247. </a>
  248. <dd>
  249. Implementation of serialization of all types in terms of character
  250. or wide character binary streams. This is factored out separately from the
  251. implementation of binary primitives above. This may facilitate the creation of
  252. other types of binary archives in the future. It also preserves analogy and symmetry with
  253. the rest of the library which aids in understanding.
  254. </dd>
  255. <dt><a target="basic_text_oarchive" href="../../../boost/archive/basic_text_oarchive.hpp">
  256. boost/archive/basic_text_oarchive.hpp
  257. </a>
  258. <dt><a target="basic_te't_iarchive" href="../../../boost/archive/basic_text_iarchive.hpp">
  259. boost/archive/basic_text_iarchive.hpp
  260. </a>
  261. </dt>
  262. <dt><a target="basic_xml_oarchive" href="../../../boost/archive/basic_xml_oarchive.hpp">
  263. boost/archive/basic_xml_oarchive.hpp
  264. </a>
  265. <dt><a target="basic_xml_iarchive" href="../../../boost/archive/basic_xml_iarchive.hpp">
  266. boost/archive/basic_xml_iarchive.hpp
  267. </a>
  268. </dt>
  269. <dd>
  270. Implementation of serialization of all types in terms of character
  271. or wide character text streams. These classes specify archive type specific
  272. behavior on a type by type basis. For example, <code style="white-space: normal">basic_xml_oarchive.hpp</code>
  273. includes code to guarantee that any object not attached to a name will
  274. trap during compile time. On the other hand, <code style="white-space: normal">basic_text_oarchive.hpp</code>
  275. contains code to strip out and ingore any names attached to objects.
  276. <p>
  277. <dt><a target="common_iarchive" href="../../../boost/archive/detail/common_iarchive.hpp">
  278. boost/archive/detail/common_iarchive.hpp
  279. </a>
  280. <dt><a target="common_oarchive" href="../../../boost/archive/detail/common_oarchive.hpp">
  281. boost/archive/detail/common_oarchive.hpp
  282. </a>
  283. <dd>
  284. All archive implementations are derived from these header files. They provide
  285. the interface to the internal implementation details of the library.
  286. </dd>
  287. </dl>
  288. <a name="archiveinternals">
  289. <h4>Archive Internals</h4>
  290. The interface (see <a target="detail" href="archives.html">Archive Concepts</a>)
  291. and implementation are factored out into separate classes to minimize code duplication.
  292. These files are found in the directory
  293. <a target="boost_archive_detail" href="../../../boost/archive/detail">boost/archive/detail</a>.
  294. These are included as necessary by the archive class implemenations listed above.
  295. This has the unfortunate side effect of making the implementation less transparent.
  296. Users should never find it necessary to change these files.
  297. <p>
  298. The following discussion is based on the
  299. <a target="class_diagram" href="class_diagram.html">class diagram</a>.
  300. <p>
  301. <dt><a target="interface_iarchive" href="../../../boost/archive/detail/interface_iarchive.hpp">
  302. boost/archive/detail/interface_iarchive.hpp</a>
  303. <dt><a target="interface_iarchive" href="../../../boost/archive/detail/interface_iarchive.hpp">
  304. boost/archive/detail/interface_iarchive.hpp</a>
  305. <dd>
  306. Here are the declarations and definitions for the
  307. <a href="archives.html">archive_concept</a>. This class redirects calls to the
  308. archive interface to a function named <code>save_override</code> in the most derived
  309. archive class.
  310. </dd>
  311. <code>save_override</code> is declared and implemented in each class in
  312. the archive hierarchy.
  313. <pre><code>
  314. template<class T>
  315. void save_override(T & t, BOOST_PFTO int){
  316. // All for otherwise unhandled types are forwarded to the base class.
  317. // This emulates behavior for function overloading.
  318. this->base::save_override(t, 0);
  319. }
  320. void save_override(const some_type & t, int){
  321. // any special handling for some type
  322. // this will usually entail forwarding some other operation
  323. // in the most derived class.
  324. this->This()->...
  325. // or in one of its parents basic_text_oprimitive
  326. this->This()->save(static_cast&lt;int&gt;(t));
  327. }
  328. ... // other special type handling
  329. </code></pre>
  330. Note the usage of
  331. <a target="detail" href="implementation.html#functiontemplateordering">Partial Function Template Ordering</a>
  332. to permit the correct save implementation to be selected.
  333. </dd>
  334. <a name="codemodules">
  335. <h4>Archive Library Code Modules</h4>
  336. Parts of the library are implemented as library code. All of this code is to be found in
  337. <a target="src" href="../../../libs/serialization/src">libs/serialization/src</a>.
  338. in the form of *.cpp. The directory
  339. <a target="src" href="../../../boost/archive/impl">boost/archive/impl</a>
  340. contains *.ipp files which implement templates. These templates are instantiated
  341. only by archive implementation so are generally not included in user code modules.
  342. <p>
  343. The trade offs related to library implementation via pre-compiled code and templated
  344. headers are well known. This library uses both. It uses templated headers
  345. to generate code to serialize user and primitive types and it uses pre-compiled
  346. library code for that part of the code which only depends upon the archive type.
  347. Building of the library generates and compiles code for all archives implemented.
  348. <ul>
  349. <li>Serialization of user and primitive types runs at top speed. This is a noticeable
  350. difference with a previous version of the library which did not use templates for archives.
  351. <li>Library implementation code that never changes need only be compiled once
  352. rather than each time a user's program is recompiled. This can save much
  353. development time.
  354. <li>Headers which solely related to implementation need only be included
  355. in the library code modules. This prevents a user program from accidently
  356. depending on an implementation feature of the serialization library.
  357. <li>In building the library I came to the conclusions that there can arise
  358. situations regarding static code/data instantiation that could not be
  359. satisfactorily addressed without a code module. Unfortunately, I've forgotten
  360. the circumstances which led me to this conclusion.
  361. </ul>
  362. An example of this is the usage of the spirit library in the library.
  363. It takes a long time to compile and includes lots of other files. Having this
  364. only in the library is much more convenient that having to include it in every
  365. program which uses xml serialization.
  366. <a name="dataflowiterators">
  367. <h4>Dataflow Iterators</h4>
  368. In the course of developing this library, it became convenient to make a set
  369. of composable iterator adaptors for handling archive text. Applications include
  370. escaping and unescaping xml text and implementing to/from base64 conversion among
  371. others.
  372. <p>
  373. This is a ripe topic in itself. It's touched upon by the
  374. <a href="../../../libs/iterator/doc/index.html">boost iterator</a> libraries,
  375. <a href="http://www.zib.de/weiser/vtl/index.html">View Template Library</a>, and others.
  376. <p>
  377. The code for these iterators is really independent of this library. But since it
  378. hasn't been and probably won't be reviewed outside of this context. I've left it in a directory
  379. local to the serialization library:
  380. <a target="archiveiterators" href="../../../boost/archive/iterators">boost/archive/iterators</a>.
  381. These iterators are described in
  382. <a href="dataflow.html">Dataflow Iterators</a>.
  383. <hr>
  384. <p><i>&copy; Copyright <a href="http://www.rrsd.com">Robert Ramey</a> 2002-2004.
  385. Distributed under the Boost Software License, Version 1.0. (See
  386. accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  387. </i></p>
  388. </body>
  389. </html>