implementation.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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 - Implementation Notes</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">Implementation Notes</h2>
  24. </td>
  25. </tr>
  26. </table>
  27. <hr>
  28. <dl class="page-index">
  29. <dt><a href="#charencoding">Character Encoding</a>
  30. <dt><a href="#othercompilerissues">Specific Compiler/Library Issues</a>
  31. <dl class="page-index">
  32. <dt><a href="#gcc4x">44.X</a>
  33. <dt><a href="#intel80">Intel 8.0</a>
  34. <dt><a href="#vc80">Visual C++ 8.0</a>
  35. <dt><a href="#vc71">Visual C++ 7.1</a>
  36. <dt><a href="#comeau">Comeau 4.3.3</a>
  37. <dt><a href="#codewarrior9">Code Warrior 9.x</a>
  38. <dt><a href="#codewarrior">Code Warrior 8.3</a>
  39. <dt><a href="#tru64">TRU64</a>
  40. <dt><a href="#dinkumware">Dinkumware Library</a>
  41. <dt><a href="#stlport">STLPort 4.5.3</a>
  42. </dl>
  43. </dl>
  44. <h3><a name="charencoding">Character Encoding</a></h3>
  45. The whole question of character encoding combined with wide characters
  46. is much more complicated than it would seem to be. The current library
  47. defines in 3 formats (text, binary, and XML), wide and narrow characters,
  48. and attempts to be portable between compiler libraries. The results of
  49. a rather long consideration of all these factors has been to set
  50. default encoding according to the following rules.
  51. <ul>
  52. <li>All text archives (i.e. <code style="white-space: normal">text_?archive</code>) will produce
  53. text output in the current stream <code style="white-space: normal">locale</code>. Generally this will
  54. produce no changes in string data.
  55. <li>To produce binary output with Microsoft compilers, the stream
  56. will have to be opened with mode <code style="white-space: normal">ios::binary</code>.
  57. Failure to do so will result in 0x0d characters (carriage-return)
  58. characters being removed from the input stream if they are followed
  59. by a 0x0a character (line-feed). This could corrupt the input
  60. and make the file unreadable. On UNIX systems the <code style="white-space: normal">ios::binary</code>
  61. is not required and is ignored if used.
  62. <li>character XML archives (i.e. xml_oarchive) will produce XML output
  63. with characters encoded according to the current stream <code style="white-space: normal">locale</code>.
  64. <li>wide character XML archives (i.e. xml_woarchive) will produce
  65. files encoded in UTF-8.
  66. </ul>
  67. This character encoding is implemented by changing the <code style="white-space: normal">locale</code> of the
  68. i/o stream used by an archive when the archive is constructed, the stream
  69. locale is changed back to its original value. This action can be overridden
  70. by specifying <code style="white-space: normal">boost::archive::no_codecvt</code>
  71. when the archive is opened. In this case, the stream <code style="white-space: normal">locale</code> will
  72. not be changed by the serialization library.
  73. <p>
  74. Note that the code conversion included for wide character text and XML
  75. archives could alter <code style="white-space: normal">std::string</code> data stored in archives.
  76. Suppose a normal (multi-byte) character string
  77. is written to a wide character stream. Our system uses the current <code style="white-space: normal">locale</code>
  78. to translate it to a wide character string before writing it out.
  79. Upon reading, it is translated back to a (multi-byte)string.
  80. If the <code style="white-space: normal">locale</code> on the platform that reads the archive is different than
  81. the <code style="white-space: normal">locale</code> on the platform that wrote the stream, the actual string data
  82. may be altered by the serialization process. To avoid this, either
  83. avoid usage of <code style="white-space: normal">locale</code> dependent multi-byte strings or be sure that
  84. the <code style="white-space: normal">locale</code> is set correctly before reading the archive.
  85. <p>
  86. To produce wide character text output (i.e. 16 bit characters on Win32 systems),
  87. do the following.
  88. <ul>
  89. <li>Open a wide character stream.
  90. <li>Alter the stream <code style="white-space: normal">locale</code> to use
  91. <code style="white-space: normal">boost::archive::codecvt_null&lt;OStream::char_type&gt;</code>
  92. <li>Create the archive with the flag <code style="white-space: normal">no_codecvt</code>.
  93. </ul>
  94. Naturally, the input process has to be symmetrical.
  95. <h3><a name="othercompilerissues">Specific Compiler/Library Issues</a></h3>
  96. <h4><a name="gcc4x">GCC 4.X</a></h4>
  97. <ul>
  98. <li>GCC versions for Cygwin and MinGW fail to support wide character I/O.
  99. So all tests using wide char I/O fail. Note that if wide character I/O support
  100. is added with STLPort, all tests complete successfully.
  101. <li>This compiler generates long warning messages related to the usage of
  102. non virtual destructors in polymorphic classes. These warnings have been
  103. carefully considered and the code that generates these warning has been
  104. unchanged. In this case the warning should should be ignored as in certain
  105. usages of the library, making the destructors virtual could lead to problems.
  106. As an alternative, base class destructors have been made "protected" to
  107. address the concerns that motivate these warning messages. When building
  108. the serialization library and tests with bjam, these warnings are suppressed.
  109. When building one's own applications, these warnings can be suppressed by
  110. adding the following to the compiler command line:
  111. <pre><code>
  112. -Wno-non-virtual-dtor
  113. -Wno-ctor-dtor-privacy
  114. </code></pre>
  115. </ul>
  116. <h4><a name="intel80">Intel C++ 8.0</a></h4>
  117. No known issues. All tests compile and run in debug and release modes.
  118. <h4><a name="vc80">Visual C++ 8.0</a></h4>
  119. This compiler emits warnings for calls to functions from the standard
  120. library which are deemed security risks. The serialization depends upon
  121. making some of these calls so programs which use the serialization library
  122. will get warning messages. These messages can be suppressed from the command
  123. line by including the following switch:
  124. <pre><code>
  125. /wd4996
  126. </code></pre>
  127. <h4><a name="vc71">Visual C++ 7.1</a></h4>
  128. Derivation from an archive class defined in a DLL as described in ... will not work.
  129. This is due to the way that VC++ handles templated code with __decl(dllexport) and
  130. __decl(dllimport) specifications. Basically, this compiler requires that all the
  131. instantiations have the same specification - even though they have different
  132. template arguments. The example <code style="white-space: normal">
  133. demo_portable_iarchive.cpp</code> would have to be reformulated as a library or dll
  134. similar to the pre-defined archives in order to function.
  135. <p>
  136. This compiler does not have RTTI or exception handling turned on by default. Although
  137. they are not strictly necessary to use the serialization package, the example and test
  138. programs presume that they are enabled. So be sure your command line or IDE settings
  139. enable these features if you want to build and run these programs.
  140. <p>
  141. This compiler can treat <code style="white-space: normal">wchar_t</code> as either
  142. a short integer or an intrinsic type.
  143. If <code style="white-space: normal">/Zc:wchar_t</code> is specified on the
  144. compile command line, <code style="white-space: normal">wchar_t</code> will be
  145. considered an intrinsic type - otherwise
  146. it will be treated as a synonym for a 16 bit integer. The library can be used
  147. either way - <strong>BUT</strong> - both the libray <strong>AND</strong> the application
  148. must be compiled with the same switch settings. Note that <code style="white-space: normal">BJAM</code>
  149. includes this switch by default. So if want to use the libraries that
  150. <code style="white-space: normal">BJAM</code> builds, you should include this switch
  151. when you compile your own applications.
  152. <h5>Using the Visual C++ IDE</h5>
  153. The library includes a VC++ 7.1 "Solution" - <code style="white-space: normal">BoostSerializationLibrary</code>
  154. along with a set of project files - one for each demo and test. Consider the following if you
  155. decide to use these configurations.
  156. <ul>
  157. <li>The projects assume that the tests have been built with bjam using the default
  158. locations. This will result in a <code style="white-space: normal">bin</code> subdirectory
  159. within one's main boost directory. Below this there is a whole structure which maintains
  160. object and library files according to the type of build. The easiest way to build this is to
  161. invoke the runtest script which uses bjam (see below). If the libraries are not in these locations,
  162. the projects will have to be modified accordingly.
  163. <li>There are project configurations for all the combinations of build variants that boost
  164. supports. That is for release, debug, static, static multi-threading, etc..
  165. <li>If you want to use/debug the DLL versions of libraries and corresponding tests, alter
  166. the project file to define <code style="white-space: normal">BOOST_ALL_DYN_LINK=1</code>.
  167. Note that for the executables to run, the <code style="white-space: normal">PATH</code>
  168. environmental variable will have to include the directories that contain the DLL versions of
  169. the boost libraries.
  170. <li>If you have difficulties building your own projects and linking with the boost libraries,
  171. compare the project settings of your own projects with the ones here. VC sometimes requires
  172. consistent settings between projects and the libraries they use in order to link properly.
  173. In particular, check support for exceptions, runtime typing(RTTI), and intrinsic support for
  174. wide characters. The standard version of this library presumes that these facilities are
  175. enabled. Projects generated by the IDE wizard do not have these features enabled by default.
  176. <li>Frequently when trying to build a project or view project properties, one is presented with
  177. a message box with the message "unspecified error". This seems to occur when one changes the
  178. build configuration selection. It turns out this can be "fixed" by going to the "Build"
  179. menu item, selecting "Configuration Manager" and selecting a build configuration for the project
  180. you're working with.
  181. <li>To test that boost libraries are built correctly, one can build and test them the way we do.
  182. This entails:
  183. <ol>
  184. <li>downloading a copy of bjam.exe
  185. <li>building process_jam_log
  186. <li>building compiler_status
  187. <li>invoking runtest.bat
  188. </ol>
  189. This will build the serialization library and run the tests on your system. If there are more than a
  190. a couple of test failures, you likely won't be able to get your own projects working. If most of the
  191. tests pass, you can be confident that your own projects will work once you get your project settings
  192. in sync with those included here.
  193. </ul>
  194. <h4><a name="comeau">Comeau 4.3.3</a></h4>
  195. <ul>
  196. <li>This compiler fails to make a DLL with export under windows.
  197. <li>The associated library - libcomo fails when using a codecvt facet.
  198. This generates a failure with all wide character archives.
  199. <li>the test_set fails by going into an infinite memory leak.
  200. </ul>
  201. <h4><a name="codewarrior9">Code Warrior 9.x</a></h4>
  202. <ul>
  203. <li>Some tests and demos fail - still under investigation
  204. </ul>
  205. <h4><a name="codewarrior">Code Warrior 8.3</a></h4>
  206. all the above issues for Code Warrior 9.x plus:
  207. <ul>
  208. <li>This compiler only supports templated streams with the static library version.
  209. <li>The above inhibits the build of DLL versions of the library.
  210. <li>Some demos fail - still under investigation
  211. </ul>
  212. <h4><a name="tru64">TRU64</a></h4>
  213. All tests and demos pass except for test_variant. Boost Variant doesn't function
  214. wih this compiler
  215. <h4><a name="dinkumware">Dinkumware Library</a></h4>
  216. Several compilers, including Visual C++ 6.0, use an older dinkumware library.
  217. These platforms have several issues:
  218. <ul>
  219. <li>The dinkumware library shipped with this compiler does not change the locale facet
  220. of an i/o stream unless the <code style="white-space: normal">imbue</code> function is called before the
  221. stream is opened. In order to use this library with this environment to generate UTF-8
  222. files, one cannot depend on the "automatic" setting of locale that archives implement. The
  223. stream locale must be set explicitly on the stream before an archive is opened on it. The
  224. archive should be opened with the <code style="white-space: normal">no_codecvt</code> flag. Note this problem will
  225. occur on all compilers shipped with this library.
  226. <li>Other issues have been worked around in the file.
  227. <a href="../../../boost/archive/dinkumware.hpp" target="dinkumware_hpp">dinkumware.hpp</a>
  228. </ul>
  229. <h4><a name="stlport">STLPort 4.5.3</a></h4>
  230. <ul>
  231. <li>when built to use the dynamic linking versions of the C++ runtime code (<runtime-link>dynamic)
  232. all tests fail to link. This is due to a missing symbol in the stlport library related
  233. to custom codecvt facets.
  234. <li>the test_set fails to run correctly. It seems the hashed set iterator doesn't
  235. implement the ++ operator correctly. This causes the test to fail by consuming all available
  236. memory. Given this, this test is commented out.
  237. </ul>
  238. <hr>
  239. <p>Revised 1 November, 2004
  240. <p><i>&copy; Copyright <a href="http://www.rrsd.com">Robert Ramey</a> 2002-2015.
  241. Distributed under the Boost Software License, Version 1.0. (See
  242. accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  243. </i></p>
  244. </body>
  245. </html>