summaryrefslogtreecommitdiff
path: root/libs/flyweight
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2014-10-31 14:41:14 +0000
committer <>2014-12-12 16:07:56 +0000
commited232fdd34968697a68783b3195b1da4226915b5 (patch)
tree7a7053ceb8874b28ec4b868d4c49b500008a102e /libs/flyweight
parent1c3648bf5b7d17fcd4fe9bc95802b16fd9eee304 (diff)
downloadboost-tarball-ed232fdd34968697a68783b3195b1da4226915b5.tar.gz
Imported from /home/lorry/working-area/delta_boost-tarball/boost_1_57_0.tar.bz2.boost_1_57_0
Diffstat (limited to 'libs/flyweight')
-rw-r--r--libs/flyweight/doc/acknowledgements.html14
-rw-r--r--libs/flyweight/doc/examples.html41
-rw-r--r--libs/flyweight/doc/performance.html6
-rw-r--r--libs/flyweight/doc/reference/flyweight.html69
-rw-r--r--libs/flyweight/doc/reference/index.html7
-rw-r--r--libs/flyweight/doc/release_notes.html21
-rw-r--r--libs/flyweight/doc/tests.html7
-rw-r--r--libs/flyweight/doc/tutorial/basics.html49
-rw-r--r--libs/flyweight/doc/tutorial/extension.html6
-rw-r--r--libs/flyweight/doc/tutorial/key_value.html6
-rw-r--r--libs/flyweight/example/Jamfile.v28
-rw-r--r--libs/flyweight/example/serialization.cpp133
-rw-r--r--libs/flyweight/meta/libraries.json14
-rw-r--r--libs/flyweight/test/Jamfile.v24
-rw-r--r--libs/flyweight/test/test_all_main.cpp4
-rw-r--r--libs/flyweight/test/test_basic_template.hpp7
-rw-r--r--libs/flyweight/test/test_serialization.cpp31
-rw-r--r--libs/flyweight/test/test_serialization.hpp11
-rw-r--r--libs/flyweight/test/test_serialization_main.cpp18
-rw-r--r--libs/flyweight/test/test_serialization_template.hpp128
20 files changed, 556 insertions, 28 deletions
diff --git a/libs/flyweight/doc/acknowledgements.html b/libs/flyweight/doc/acknowledgements.html
index 326231853..15de3178f 100644
--- a/libs/flyweight/doc/acknowledgements.html
+++ b/libs/flyweight/doc/acknowledgements.html
@@ -72,6 +72,16 @@ and to Peter Dimov for kindly extending the interface of his
implementation of the fix.
</p>
+<h2><a name="boost_1_57">Boost 1.57 release</a></h2>
+
+<p>
+Boost.Flyweight serialization uses the newly introduced
+<a href="../../serialization/doc/special.html#helpersupport">helper support
+functionality</a> of the <a href="../../serialization/index.html">Boost Serialization Library</a>
+from Robert Ramey. Without helper support, serialization of <code>flyweight</code>s would have
+been unacceptably costly in terms of archive space consumption.
+</p>
+
<hr>
<div class="prev_link"><a href="release_notes.html"><img src="prev.gif" alt="release notes" border="0"><br>
@@ -85,9 +95,9 @@ Index
<br>
-<p>Revised April 25th 2009</p>
+<p>Revised September 1st 2014</p>
-<p>&copy; Copyright 2006-2009 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
+<p>&copy; Copyright 2006-2014 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
Distributed under the Boost Software
License, Version 1.0. (See accompanying file <a href="../../../LICENSE_1_0.txt">
LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
diff --git a/libs/flyweight/doc/examples.html b/libs/flyweight/doc/examples.html
index 2bef5cf58..0bf9463a8 100644
--- a/libs/flyweight/doc/examples.html
+++ b/libs/flyweight/doc/examples.html
@@ -36,8 +36,9 @@ Tests
<li><a href="#example3">Example 3: flyweights and the composite pattern</a></li>
<li><a href="#example4">Example 4: formatted text processing</a></li>
<li><a href="#example5">Example 5: flyweight-based memoization</a></li>
- <li><a href="#example6">Example 6: performance comparison</a></li>
- <li><a href="#example7">Example 7: custom factory</a></li>
+ <li><a href="#example6">Example 6: serialization</a></li>
+ <li><a href="#example7">Example 7: performance comparison</a></li>
+ <li><a href="#example8">Example 8: custom factory</a></li>
</ul>
<h2><a name="example1">Example 1: basic usage</a></h2>
@@ -155,7 +156,7 @@ characters varies.
<p>
For the sake of brevity, the HTML parsing capabilities of this program
are coarse: for instance, elements without end-tag (like &lt;BR&gt;), character
-enconding and HTML entities (e.g. "&amp;copy;" for &copy;) are not properly
+encoding and HTML entities (e.g. "&amp;copy;" for &copy;) are not properly
handled. Improving the parsing code is left as an exercise to the reader.
</p>
@@ -200,7 +201,33 @@ policy is used so that the memoized computations persist for future
use throughout the program. The provided program develops this example in full.
</p>
-<h2><a name="example6">Example 6: performance comparison</a></h2>
+<h2><a name="example6">Example 6: serialization</a></h2>
+
+<p>
+See <a href="../example/serialization.cpp">source code</a>.
+</p>
+
+<p>
+If <code>T</code> is serializable (using
+<a href="../../serialization/index.html">Boost.Serialization</a>),
+<code>flyweight&lt;T&gt;</code> is automatically
+serializable as well. The example program performs the following two
+complementary procedures:
+<ul>
+ <li>Read a text file as a <code>std::vector&lt;flyweight&lt;std::string&gt; &gt;</code>
+ and save the structure to a serialization file.
+ </li>
+ <li>Load a <code>std::vector&lt;flyweight&lt;std::string&gt; &gt;</code> from a
+ serialization file and write it as a text file.
+ </li>
+</ul>
+If you visually inspect the contents of any of the generated serialization files
+you can notice that no word appears twice; Boost.Flyweight implements some internal
+machinery that avoids duplicating output information when saving equal
+<code>flyweight</code> objects.
+</p>
+
+<h2><a name="example7">Example 7: performance comparison</a></h2>
<p>
See <a href="../example/perf.cpp">source code</a>.
@@ -218,7 +245,7 @@ The program has been used to produce the experimental results given
at the <a href="performance.html#results">performance section</a>.
</p>
-<h2><a name="example7">Example 7: custom factory</a></h2>
+<h2><a name="example8">Example 8: custom factory</a></h2>
<p>
See <a href="../example/custom_factory.cpp">source code</a>.
@@ -245,9 +272,9 @@ Tests
<br>
-<p>Revised December 2nd 2008</p>
+<p>Revised October 14th 2014</p>
-<p>&copy; Copyright 2006-2008 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
+<p>&copy; Copyright 2006-2014 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
Distributed under the Boost Software
License, Version 1.0. (See accompanying file <a href="../../../LICENSE_1_0.txt">
LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
diff --git a/libs/flyweight/doc/performance.html b/libs/flyweight/doc/performance.html
index cac737fa5..ae9d854d6 100644
--- a/libs/flyweight/doc/performance.html
+++ b/libs/flyweight/doc/performance.html
@@ -300,7 +300,7 @@ into the processor cache.
<h2><a name="results">Experimental results</a></h2>
<p>
-A <a href="examples.html#example6">profiling program</a> was devised to test
+A <a href="examples.html#example7">profiling program</a> was devised to test
the space and time efficiency of different instantiations of <code>flyweight</code>
against a base situation not using Boost.Flyweight. The profiled scenarios are:
<ol>
@@ -459,9 +459,9 @@ Examples
<br>
-<p>Revised June 22nd 2009</p>
+<p>Revised September 1st 2014</p>
-<p>&copy; Copyright 2006-2009 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
+<p>&copy; Copyright 2006-2014 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
Distributed under the Boost Software
License, Version 1.0. (See accompanying file <a href="../../../LICENSE_1_0.txt">
LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
diff --git a/libs/flyweight/doc/reference/flyweight.html b/libs/flyweight/doc/reference/flyweight.html
index 2574cd49c..009f5f387 100644
--- a/libs/flyweight/doc/reference/flyweight.html
+++ b/libs/flyweight/doc/reference/flyweight.html
@@ -50,6 +50,12 @@ Key-value flyweights
</li>
</ul>
</li>
+ <li><a href="#serialize_synopsis">Header
+ <code>"boost/flyweight/serialize.hpp"</code> synopsis</a>
+ <ul>
+ <li><a href="#serialization">Serialization</a></li>
+ </ul>
+ </li>
</ul>
<h2>
@@ -241,6 +247,8 @@ objects constructed from equivalent keys.
<span class=comment>// construct/copy/destroy:</span>
+ <span class=identifier>flyweight</span><span class=special>();</span>
+
<span class=keyword>template</span><span class=special>&lt;</span><span class=keyword>typename</span><span class=special>...</span> <span class=identifier>Args</span><span class=special>&gt;</span>
<span class=keyword>explicit</span> <span class=identifier>flyweight</span><span class=special>(</span><span class=identifier>Args</span><span class=special>&amp;&amp;...</span> <span class=identifier>args</span><span class=special>);</span>
@@ -356,6 +364,16 @@ constructed.<br>
<h4><a name="constructors">Constructors, copy and assignment</a></h4>
+<code>flyweight();</code>
+
+<blockquote>
+<b>Effects:</b> Constructs a <code>flyweight</code> object with the value
+<code>value_type(key_type())</code>
+if <code>flyweight</code> is key-value
+or <code>value_type()</code>
+otherwise.
+</blockquote>
+
<a name="fwd_ctor">
<code>template&lt;typename... Args&gt;<br>
explicit flyweight(Args&amp;&amp;... args);</code></a>
@@ -641,6 +659,55 @@ arguments accepted by <code>flyweight</code>
is 5.
</blockquote>
+<h2>
+<a name="serialize_synopsis">Header
+</a><a href="../../../../boost/flyweight/serialize.hpp"><code>"boost/flyweight/serialize.hpp"</code></a>
+synopsis
+</h2>
+
+<p>
+<code>serialize.hpp</code> includes the necessary functionality for interoperability
+of <code>flyweight</code> with
+<a href="../../../serialization/index.html">Boost.Serialization</a>.
+</p>
+
+<h3><a name="serialization">Serialization</a></h3>
+
+<p>
+<code>flyweight</code>s can be archived and retrieved by means of
+<a href="../../../serialization/index.html">Boost.Serialization</a>. Regular as well
+as XML archives are supported.
+Serialization is done in an efficient manner so that saving equivalent <code>flyweight</code>s
+result in their common <code>key_type</code> value being stored only once, regardless
+of whether <code>key_type</code> is
+<a href="../../../serialization/doc/traits.html#tracking">tracked</a> by
+Boost.Serialization or not.
+</p>
+
+Operation: saving of a <code>flyweight</code> object <code>x</code> to an
+output archive (XML archive) <code>ar</code>.
+
+<blockquote>
+<b>Requires:</b> <code>key_type</code> is serializable (XML-serializable).<br>
+<b>Effects:</b> The value <code>k=x.get_key()</code> is saved into <code>ar</code> as
+part of this operation or of a previous saving operation of a <code>flyweight</code>
+object with the same key.<br>
+<b>Exception safety:</b> Strong with respect to <code>x</code>. If an exception
+is thrown, <code>ar</code> may be left in an inconsistent state.
+</blockquote>
+
+Operation: loading of a <code>flyweight</code> <code>x'</code> from an
+input archive (XML archive) <code>ar</code>.
+
+<blockquote>
+<b>Requires:</b> <code>key_type</code> is serializable (XML-serializable).<br>
+<b>Effects:</b> <code>x'</code> is associated to a value constructed from a key
+equivalent to <code>k'</code>, a restored copy of the value <code>k</code>
+defined above.<br>
+<b>Exception safety:</b> Strong with respect to <code>x'</code>. If an exception
+is thrown, <code>ar</code> may be left in an inconsistent state.
+</blockquote>
+
<hr>
<div class="prev_link"><a href="index.html"><img src="../prev.gif" alt="Boost.Flyweight reference" border="0"><br>
@@ -655,7 +722,7 @@ Key-value flyweights
<br>
-<p>Revised February 1st 2014</p>
+<p>Revised September 3rd 2014</p>
<p>&copy; Copyright 2006-2014 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
Distributed under the Boost Software
diff --git a/libs/flyweight/doc/reference/index.html b/libs/flyweight/doc/reference/index.html
index 1ad8c7714..4d68d69f4 100644
--- a/libs/flyweight/doc/reference/index.html
+++ b/libs/flyweight/doc/reference/index.html
@@ -53,6 +53,7 @@ Boost.Flyweight comprises the following public headers:
<ul>
<li><a href="flyweight.html#flyweight_fwd_synopsis"><code>"boost/flyweight/flyweight_fwd.hpp"</code></a></li>
<li><a href="flyweight.html#synopsis"><code>"boost/flyweight/flyweight.hpp"</code></a></li>
+ <li><a href="flyweight.html#serialize_synopsis"><code>"boost/flyweight/flyweight_serialize.hpp"</code></a></li>
</ul>
</li>
<li>Key-value flyweights
@@ -110,7 +111,9 @@ Boost.Flyweight comprises the following public headers:
<h2><a name="dependencies">Dependencies</a></h2>
<p>
-Boost.Flyweight is a header-only library, requiring no additional
+In order to use the serialization capabilities of Boost.Flyweight,
+the appropriate Boost.Serialization library module must be linked. Other
+than that, Boost.Flyweight is a header-only library, requiring no additional
object modules. The default <a href="locking.html#simple_locking"><code>simple_locking</code></a>
locking policy introduces a dependency on the Pthreads library on those POSIX-compliant
environments where the <a href="../../../config/doc/html/index.html">Boost.Config</a> macro
@@ -151,7 +154,7 @@ Index
<br>
-<p>Revised April 4th 2014</p>
+<p>Revised September 1st 2014</p>
<p>&copy; Copyright 2006-2014 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
Distributed under the Boost Software
diff --git a/libs/flyweight/doc/release_notes.html b/libs/flyweight/doc/release_notes.html
index f901691e3..f943e7da3 100644
--- a/libs/flyweight/doc/release_notes.html
+++ b/libs/flyweight/doc/release_notes.html
@@ -31,6 +31,7 @@ Acknowledgements
<h2>Contents</h2>
<ul>
+ <li><a href="#boost_1_57">Boost 1.57 release</a></li>
<li><a href="#boost_1_56">Boost 1.56 release</a></li>
<li><a href="#boost_1_55">Boost 1.55 release</a></li>
<li><a href="#boost_1_45">Boost 1.45 release</a></li>
@@ -40,6 +41,24 @@ Acknowledgements
<li><a href="#boost_1_38">Boost 1.38 release</a></li>
</ul>
+<h2><a name="boost_1_57">Boost 1.57 release</a></h2>
+
+<p>
+<ul>
+ <li>Added serialization support via
+ <a href="../../serialization/index.html">Boost Serialization</a>.
+ </li>
+ <li>
+ <code>flyweight</code> default constructor was made <code>explicit</code> in
+ Boost 1.56, which introduces a regression in some
+ <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1518">initialization
+ scenarios</a>. The former non-<code>explicit</code>
+ default constructor has been restored
+ (ticket <a href="https://svn.boost.org/trac/boost/ticket/10439">#10439</a>).
+ </li>
+</ul>
+</p>
+
<h2><a name="boost_1_56">Boost 1.56 release</a></h2>
<p>
@@ -130,7 +149,7 @@ Acknowledgements
<br>
-<p>Revised February 1st 2014</p>
+<p>Revised September 4th 2014</p>
<p>&copy; Copyright 2006-2014 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
Distributed under the Boost Software
diff --git a/libs/flyweight/doc/tests.html b/libs/flyweight/doc/tests.html
index 825f79a9b..01f930c50 100644
--- a/libs/flyweight/doc/tests.html
+++ b/libs/flyweight/doc/tests.html
@@ -79,6 +79,11 @@ of Boost.Flyweight.
<td><a href="tutorial/configuration.html#no_tracking"><code>no_tracking</code></a> policy.</td>
</tr>
<tr>
+ <td><a href="../test/test_serialization.cpp"><code>test_serialization.cpp</code></a></td>
+ <td>Exercises <code>flyweight</code> <a href="tutorial/basics.html#serialization">serialization
+ capabilities</a>.</td>
+</tr>
+<tr class="odd_tr">
<td><a href="../test/test_set_factory.cpp"><code>test_set_factory.cpp</code></a></td>
<td><a href="tutorial/configuration.html#set_factory"><code>set_factory</code></a>
factory specifier.</td>
@@ -101,7 +106,7 @@ Future work
<br>
-<p>Revised February 1st 2014</p>
+<p>Revised September 1st 2014</p>
<p>&copy; Copyright 2006-2014 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
Distributed under the Boost Software
diff --git a/libs/flyweight/doc/tutorial/basics.html b/libs/flyweight/doc/tutorial/basics.html
index 2af60575d..26f813b07 100644
--- a/libs/flyweight/doc/tutorial/basics.html
+++ b/libs/flyweight/doc/tutorial/basics.html
@@ -30,7 +30,11 @@ Key-value flyweights
<h2>Contents</h2>
<ul>
- <li><a href="#intro">Introduction</a></li>
+ <li><a href="#intro">Introduction</a>
+ <ul>
+ <li><a href="#serialization">Serialization</a></li>
+ </ul>
+ </li>
<li><a href="#requirements">Flyweight requirements</a></li>
</ul>
@@ -172,6 +176,45 @@ The <a href="../examples.html">examples section</a> explores
some common usage scenarios of Boost.Flyweight.
</p>
+<h4><a name="serialization">Serialization</a></h4>
+
+<p>
+<code>flyweight&lt;T&gt;</code> can be serialized by means of the
+<a href="../../../serialization/index.html">Boost Serialization Library</a>
+as long as the underlying <code>T</code> is serializable. Both regular and
+XML archives are supported. In order to
+use Boost.Flyweight serialization capabilities, the specific
+header <a href="../reference/flyweight.html#serialize_synopsis"><code>"boost/flyweight/serialize.hpp"</code></a>
+must be included.
+</p>
+
+<blockquote><pre><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">flyweight</span><span class="special">/</span><span class="identifier">serialize</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Archive</span><span class="special">&gt;</span>
+<span class="keyword">void</span> <span class="identifier">serialize</span><span class="special">(</span><span class="identifier">Archive</span><span class="special">&amp;</span> <span class="identifier">ar</span><span class="special">,</span><span class="identifier">user_entry</span><span class="special">&amp;</span> <span class="identifier">user</span><span class="special">,</span><span class="keyword">const</span> <span class="keyword">unsigned</span> <span class="keyword">int</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="identifier">ar</span><span class="special">&amp;</span><span class="identifier">user</span><span class="special">.</span><span class="identifier">first_name</span><span class="special">;</span>
+ <span class="identifier">ar</span><span class="special">&amp;</span><span class="identifier">user</span><span class="special">.</span><span class="identifier">last_name</span><span class="special">;</span>
+ <span class="identifier">ar</span><span class="special">&amp;</span><span class="identifier">user</span><span class="special">.</span><span class="identifier">age</span><span class="special">;</span>
+ <span class="special">...</span>
+<span class="special">}</span>
+</pre></blockquote>
+
+<p>
+Much as using Boost.Flyweight reduces memory consumption due to the internal
+sharing of duplicate values, serializing <code>flyweight</code>s can also
+result in smaller archive files, as a common value is only stored
+once and their associated <code>flyweight</code>s get saved as references to it.
+This policy is observed even if <code>flyweight</code> underlying type is
+not <a href="../../../serialization/doc/traits.html#tracking">tracked</a>
+by Boost.Serialization.
+</p>
+
+<p>
+See <a href="../examples.html#example6">example 6</a> at the examples section
+for an illustration of use of Boost.Flyweight serialization capabilities.
+</p>
+
<h3><a name="requirements">Flyweight requirements</a></h3>
<p>
@@ -214,9 +257,9 @@ Key-value flyweights
<br>
-<p>Revised December 2nd 2008</p>
+<p>Revised September 1st 2014</p>
-<p>&copy; Copyright 2006-2008 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
+<p>&copy; Copyright 2006-2014 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
Distributed under the Boost Software
License, Version 1.0. (See accompanying file <a href="../../../../LICENSE_1_0.txt">
LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
diff --git a/libs/flyweight/doc/tutorial/extension.html b/libs/flyweight/doc/tutorial/extension.html
index b82967309..87f92ea86 100644
--- a/libs/flyweight/doc/tutorial/extension.html
+++ b/libs/flyweight/doc/tutorial/extension.html
@@ -270,7 +270,7 @@ to do this tagging:
</p>
<p>
-<a href="../examples.html#example7">Example 7</a> in the examples section develops
+<a href="../examples.html#example8">Example 8</a> in the examples section develops
in full the <code>verbose_factory_class</code> case sketched above.
</p>
@@ -549,9 +549,9 @@ Technical issues
<br>
-<p>Revised December 2nd 2008</p>
+<p>Revised September 1st 2014</p>
-<p>&copy; Copyright 2006-2008 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
+<p>&copy; Copyright 2006-2014 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
Distributed under the Boost Software
License, Version 1.0. (See accompanying file <a href="../../../../LICENSE_1_0.txt">
LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
diff --git a/libs/flyweight/doc/tutorial/key_value.html b/libs/flyweight/doc/tutorial/key_value.html
index ddcb35658..e49cdef6f 100644
--- a/libs/flyweight/doc/tutorial/key_value.html
+++ b/libs/flyweight/doc/tutorial/key_value.html
@@ -202,6 +202,8 @@ by the user. The only requisite retained on <code>T</code> is that it must be
constructible from <code>K</code>; only in the case that a flyweight is directly
assigned a <code>T</code> object is also <code>T</code> required to be
<a href="http://www.sgi.com/tech/stl/Assignable.html"><code>Assignable</code></a>.
+To serialize objects of type <code>flyweight&lt;key_value&lt;K,T&gt; &gt;</code>
+only <code>K</code> needs to be serializable.
</p>
<hr>
@@ -218,9 +220,9 @@ Configuring Boost.Flyweight
<br>
-<p>Revised February 21st 2009</p>
+<p>Revised September 1st 2014</p>
-<p>&copy; Copyright 2006-2009 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
+<p>&copy; Copyright 2006-2014 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
Distributed under the Boost Software
License, Version 1.0. (See accompanying file <a href="../../../../LICENSE_1_0.txt">
LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
diff --git a/libs/flyweight/example/Jamfile.v2 b/libs/flyweight/example/Jamfile.v2
index b329a6c84..3c9bcd18c 100644
--- a/libs/flyweight/example/Jamfile.v2
+++ b/libs/flyweight/example/Jamfile.v2
@@ -1,6 +1,6 @@
# Boost.Flyweight examples Jamfile
#
-# Copyright 2006-2008 Joaquín M López Muñoz.
+# Copyright 2006-2014 Joaquín M López Muñoz.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
@@ -47,3 +47,9 @@ exe perf
: <include>$(BOOST_ROOT)
: release
;
+
+exe serialization
+ : serialization.cpp
+ /boost/serialization//boost_serialization/<link>static
+ : <include>$(BOOST_ROOT)
+ ;
diff --git a/libs/flyweight/example/serialization.cpp b/libs/flyweight/example/serialization.cpp
new file mode 100644
index 000000000..80227a539
--- /dev/null
+++ b/libs/flyweight/example/serialization.cpp
@@ -0,0 +1,133 @@
+/* Boost.Flyweight example of serialization.
+ *
+ * Copyright 2006-2014 Joaquin M Lopez Munoz.
+ * Distributed under the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org/libs/flyweight for library home page.
+ */
+
+#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
+#include <algorithm>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/flyweight.hpp>
+#include <boost/flyweight/serialize.hpp>
+#include <boost/serialization/vector.hpp>
+#include <boost/tokenizer.hpp>
+#include <cstdio>
+#include <cstdlib>
+#include <fstream>
+#include <iostream>
+#include <iterator>
+#include <sstream>
+#include <stdexcept>
+#include <string>
+#include <vector>
+
+using namespace boost::flyweights;
+
+typedef flyweight<std::string> fw_string;
+typedef std::vector<fw_string> text_container;
+
+/* Read a text file into a text_container and serialize to an archive. */
+
+void save_serialization_file()
+{
+ /* Define a tokenizer on std::istreambuf. */
+
+ typedef std::istreambuf_iterator<char> char_iterator;
+ typedef boost::tokenizer<
+ boost::char_separator<char>,
+ char_iterator
+ > tokenizer;
+
+ std::cout<<"enter input text file name: ";
+ std::string in;
+ std::getline(std::cin,in);
+ std::ifstream ifs(in.c_str());
+ if(!ifs){
+ std::cout<<"can't open "<<in<<std::endl;
+ std::exit(EXIT_FAILURE);
+ }
+
+ /* Tokenize using space and common punctuaction as separators, and
+ * keeping the separators.
+ */
+
+ tokenizer tok=tokenizer(
+ char_iterator(ifs),char_iterator(),
+ boost::char_separator<char>(
+ "",
+ "\t\n\r !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"));
+ text_container txt;
+ for(tokenizer::iterator it=tok.begin();it!=tok.end();++it){
+ txt.push_back(fw_string(*it));
+ }
+
+ std::cout<<"enter output serialization file name: ";
+ std::string out;
+ std::getline(std::cin,out);
+ std::ofstream ofs(out.c_str());
+ if(!ofs){
+ std::cout<<"can't open "<<out<<std::endl;
+ std::exit(EXIT_FAILURE);
+ }
+ boost::archive::text_oarchive oa(ofs);
+ oa<<const_cast<const text_container&>(txt);
+}
+
+/* Read a serialization archive and save the result to a text file. */
+
+void load_serialization_file()
+{
+ std::cout<<"enter input serialization file name: ";
+ std::string in;
+ std::getline(std::cin,in);
+ std::ifstream ifs(in.c_str());
+ if(!ifs){
+ std::cout<<"can't open "<<in<<std::endl;
+ std::exit(EXIT_FAILURE);
+ }
+ boost::archive::text_iarchive ia(ifs);
+ text_container txt;
+ ia>>txt;
+
+ std::cout<<"enter output text file name: ";
+ std::string out;
+ std::getline(std::cin,out);
+ std::ofstream ofs(out.c_str());
+ if(!ofs){
+ std::cout<<"can't open "<<out<<std::endl;
+ std::exit(EXIT_FAILURE);
+ }
+ std::copy(
+ txt.begin(),txt.end(),
+ std::ostream_iterator<std::string>(ofs));
+}
+
+int main()
+{
+ try{
+ std::cout<<"1 load a text file and save it as a serialization file\n"
+ "2 load a serialization file and save it as a text file\n";
+ for(;;){
+ std::cout<<"select option, enter to exit: ";
+ std::string str;
+ std::getline(std::cin,str);
+ if(str.empty())break;
+ std::istringstream istr(str);
+ int option=-1;
+ istr>>option;
+ if(option==1)save_serialization_file();
+ else if(option==2)load_serialization_file();
+ }
+ }
+ catch(const std::exception& e){
+ std::cout<<"error: "<<e.what()<<std::endl;
+ std::exit(EXIT_FAILURE);
+ }
+
+ return 0;
+}
diff --git a/libs/flyweight/meta/libraries.json b/libs/flyweight/meta/libraries.json
new file mode 100644
index 000000000..90a540608
--- /dev/null
+++ b/libs/flyweight/meta/libraries.json
@@ -0,0 +1,14 @@
+{
+ "key": "flyweight",
+ "name": "Flyweight",
+ "authors": [
+ "Joaqu\u00edn M L\u00f3pez Mu\u00f1oz"
+ ],
+ "description": "Design pattern to manage large quantities of highly redundant objects.",
+ "category": [
+ "Patterns"
+ ],
+ "maintainers": [
+ "Joaquin M Lopez Munoz <joaquin -at- tid.es>"
+ ]
+}
diff --git a/libs/flyweight/test/Jamfile.v2 b/libs/flyweight/test/Jamfile.v2
index 62a5b4470..d43d08214 100644
--- a/libs/flyweight/test/Jamfile.v2
+++ b/libs/flyweight/test/Jamfile.v2
@@ -1,6 +1,6 @@
# Boost.Flyweight tests Jamfile
#
-# Copyright 2006-2008 Joaquín M López Muñoz.
+# Copyright 2006-2014 Joaquín M López Muñoz.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
@@ -26,6 +26,8 @@ test-suite "flyweight" :
[ run test_multictor.cpp test_multictor_main.cpp ]
[ run test_no_locking.cpp test_no_locking_main.cpp ]
[ run test_no_tracking.cpp test_no_tracking_main.cpp ]
+ [ run test_serialization.cpp test_serialization_main.cpp
+ /boost/serialization//boost_serialization/<link>static ]
[ run test_set_factory.cpp test_set_factory_main.cpp ]
;
diff --git a/libs/flyweight/test/test_all_main.cpp b/libs/flyweight/test/test_all_main.cpp
index 709a8b3fe..737f95a8f 100644
--- a/libs/flyweight/test/test_all_main.cpp
+++ b/libs/flyweight/test/test_all_main.cpp
@@ -1,6 +1,6 @@
/* Boost.Flyweight test suite.
*
- * Copyright 2006-2008 Joaquin M Lopez Munoz.
+ * Copyright 2006-2014 Joaquin M Lopez Munoz.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
@@ -18,6 +18,7 @@
#include "test_multictor.hpp"
#include "test_no_locking.hpp"
#include "test_no_tracking.hpp"
+#include "test_serialization.hpp"
#include "test_set_factory.hpp"
int main()
@@ -30,6 +31,7 @@ int main()
test_multictor();
test_no_locking();
test_no_tracking();
+ test_serialization();
test_set_factory();
return boost::report_errors();
diff --git a/libs/flyweight/test/test_basic_template.hpp b/libs/flyweight/test/test_basic_template.hpp
index ac6002509..3a4f423b3 100644
--- a/libs/flyweight/test/test_basic_template.hpp
+++ b/libs/flyweight/test/test_basic_template.hpp
@@ -60,6 +60,13 @@ void test_basic_template(
BOOST_TEST(f2==cr2);
#endif
+#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
+ /* testcase for https://svn.boost.org/trac/boost/ticket/10439 */
+
+ Flyweight f3={};
+ BOOST_TEST(f3==f2);
+#endif
+
f1=f1;
BOOST_TEST(f1==f1);
diff --git a/libs/flyweight/test/test_serialization.cpp b/libs/flyweight/test/test_serialization.cpp
new file mode 100644
index 000000000..9f42774df
--- /dev/null
+++ b/libs/flyweight/test/test_serialization.cpp
@@ -0,0 +1,31 @@
+/* Boost.Flyweight of serialization capabilities.
+ *
+ * Copyright 2006-2014 Joaquin M Lopez Munoz.
+ * Distributed under the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org/libs/flyweight for library home page.
+ */
+
+#include "test_serialization.hpp"
+
+#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
+#include <boost/flyweight.hpp>
+#include "test_serialization_template.hpp"
+
+using namespace boost::flyweights;
+
+struct serialization_flyweight_specifier
+{
+ template<typename T>
+ struct apply
+ {
+ typedef flyweight<T> type;
+ };
+};
+
+void test_serialization()
+{
+ test_serialization_template<serialization_flyweight_specifier>();
+}
diff --git a/libs/flyweight/test/test_serialization.hpp b/libs/flyweight/test/test_serialization.hpp
new file mode 100644
index 000000000..b1af4ae39
--- /dev/null
+++ b/libs/flyweight/test/test_serialization.hpp
@@ -0,0 +1,11 @@
+/* Boost.Flyweight of serialization capabilities.
+ *
+ * Copyright 2006-2014 Joaquin M Lopez Munoz.
+ * Distributed under the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org/libs/flyweight for library home page.
+ */
+
+void test_serialization();
diff --git a/libs/flyweight/test/test_serialization_main.cpp b/libs/flyweight/test/test_serialization_main.cpp
new file mode 100644
index 000000000..d27068478
--- /dev/null
+++ b/libs/flyweight/test/test_serialization_main.cpp
@@ -0,0 +1,18 @@
+/* Boost.Flyweight of serialization capabilities.
+ *
+ * Copyright 2006-2014 Joaquin M Lopez Munoz.
+ * Distributed under the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org/libs/flyweight for library home page.
+ */
+
+#include <boost/detail/lightweight_test.hpp>
+#include "test_serialization.hpp"
+
+int main()
+{
+ test_serialization();
+ return boost::report_errors();
+}
diff --git a/libs/flyweight/test/test_serialization_template.hpp b/libs/flyweight/test/test_serialization_template.hpp
new file mode 100644
index 000000000..767708187
--- /dev/null
+++ b/libs/flyweight/test/test_serialization_template.hpp
@@ -0,0 +1,128 @@
+/* Boost.Flyweight test template for serialization capabilities.
+ *
+ * Copyright 2006-2014 Joaquin M Lopez Munoz.
+ * Distributed under the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org/libs/flyweight for library home page.
+ */
+
+#ifndef BOOST_FLYWEIGHT_TEST_SERIALIZATION_TEMPLATE_HPP
+#define BOOST_FLYWEIGHT_TEST_SERIALIZATION_TEMPLATE_HPP
+
+#if defined(_MSC_VER)&&(_MSC_VER>=1200)
+#pragma once
+#endif
+
+#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/flyweight/key_value.hpp>
+#include <boost/flyweight/serialize.hpp>
+#include <boost/functional/hash.hpp>
+#include <boost/mpl/apply.hpp>
+#include <boost/serialization/vector.hpp>
+#include <string>
+#include <sstream>
+#include <vector>
+#include "heavy_objects.hpp"
+
+#define LENGTHOF(array) (sizeof(array)/sizeof((array)[0]))
+
+struct tracked_string
+{
+ typedef tracked_string type;
+
+ tracked_string(){}
+ tracked_string(const char* str_):str(str_){}
+
+ const std::string& get()const{return str;}
+
+ friend bool operator==(const type& x,const type& y){return x.str==y.str;}
+ friend bool operator< (const type& x,const type& y){return x.str< y.str;}
+ friend bool operator!=(const type& x,const type& y){return x.str!=y.str;}
+ friend bool operator> (const type& x,const type& y){return x.str> y.str;}
+ friend bool operator>=(const type& x,const type& y){return x.str>=y.str;}
+ friend bool operator<=(const type& x,const type& y){return x.str<=y.str;}
+
+private:
+ friend class boost::serialization::access;
+
+ template<class Archive>
+ void serialize(Archive& ar,const unsigned int){ar&str;}
+
+ std::string str;
+};
+
+#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
+namespace boost{
+#endif
+
+inline std::size_t hash_value(const tracked_string& x)
+{
+ boost::hash<std::string> h;
+ return h(x.get());
+}
+
+#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
+} /* namespace boost */
+#endif
+
+template<typename Flyweight,typename ForwardIterator>
+void test_serialization_template(
+ ForwardIterator first,ForwardIterator last
+ BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Flyweight))
+{
+ std::vector<Flyweight> v1;
+ while(first!=last)v1.push_back(Flyweight(*first++));
+ std::ostringstream oss;
+ {
+ const std::vector<Flyweight>& crv1=v1;
+ boost::archive::text_oarchive oa(oss);
+ oa<<crv1;
+ }
+
+ std::vector<Flyweight> v2;
+ {
+ std::istringstream iss(oss.str());
+ boost::archive::text_iarchive ia(iss);
+ ia>>v2;
+ }
+
+ BOOST_TEST(v1==v2);
+}
+
+template<typename FlyweightSpecifier>
+void test_serialization_template(
+ BOOST_EXPLICIT_TEMPLATE_TYPE(FlyweightSpecifier))
+{
+ typedef typename boost::mpl::apply1<
+ FlyweightSpecifier,std::string
+ >::type string_flyweight;
+
+ typedef typename boost::mpl::apply1<
+ FlyweightSpecifier,tracked_string
+ >::type tracked_string_flyweight;
+
+ typedef typename boost::mpl::apply1<
+ FlyweightSpecifier,
+ boost::flyweights::key_value<std::string,texture,from_texture_to_string>
+ >::type texture_flyweight;
+
+ const char* words[]={"hello","boost","flyweight","boost","bye","c++","c++"};
+ test_serialization_template<string_flyweight>(
+ &words[0],&words[0]+LENGTHOF(words));
+ test_serialization_template<tracked_string_flyweight>(
+ &words[0],&words[0]+LENGTHOF(words));
+
+ const char* textures[]={
+ "wood","grass","sand","granite","terracotta","wood","sand","grass"};
+ test_serialization_template<texture_flyweight>(
+ &textures[0],&textures[0]+LENGTHOF(textures));
+}
+
+#undef LENGTHOF
+
+#endif