mirror of
https://github.com/boostorg/serialization.git
synced 2026-01-24 06:22:08 +00:00
Merged revisions 41072-41140 via svnmerge from
https://svn.boost.org/svn/boost/trunk ........ r41077 | troyer | 2007-11-13 23:00:02 -0800 (Tue, 13 Nov 2007) | 1 line Added support for std::complex to serialization ........ r41078 | joaquin | 2007-11-13 23:09:29 -0800 (Tue, 13 Nov 2007) | 1 line added missing include ........ r41079 | djowel | 2007-11-14 02:13:51 -0800 (Wed, 14 Nov 2007) | 1 line adjust to compensate for lack of <small> tag. ........ r41080 | djowel | 2007-11-14 02:17:09 -0800 (Wed, 14 Nov 2007) | 1 line refresh docs ........ r41081 | djowel | 2007-11-14 02:23:23 -0800 (Wed, 14 Nov 2007) | 1 line refresh docs ........ r41082 | djowel | 2007-11-14 02:24:21 -0800 (Wed, 14 Nov 2007) | 1 line refresh docs ........ r41083 | anthonyw | 2007-11-14 03:08:09 -0800 (Wed, 14 Nov 2007) | 1 line ignore and join all threads in group on exception ........ r41084 | anthonyw | 2007-11-14 03:56:53 -0800 (Wed, 14 Nov 2007) | 1 line interrupt and join all threads in a group if an exception is thrown during a test ........ r41086 | johnmaddock | 2007-11-14 04:14:19 -0800 (Wed, 14 Nov 2007) | 1 line Merged changes from the Sandbox to Trunk. ........ r41087 | anthonyw | 2007-11-14 04:17:41 -0800 (Wed, 14 Nov 2007) | 1 line interrupt and join all threads in a group if an exception is thrown during a test ........ r41088 | johnmaddock | 2007-11-14 04:41:32 -0800 (Wed, 14 Nov 2007) | 1 line Added WinCE workaround. ........ r41089 | johnmaddock | 2007-11-14 05:03:15 -0800 (Wed, 14 Nov 2007) | 1 line Catch exceptions thrown from thread creation. ........ r41090 | anthonyw | 2007-11-14 06:49:58 -0800 (Wed, 14 Nov 2007) | 1 line fixes for pthread implementation ........ r41091 | bemandawes | 2007-11-14 07:50:43 -0800 (Wed, 14 Nov 2007) | 1 line Replace old docs with excerpts from http://article.gmane.org/gmane.comp.lib.boost.testing/5020 ........ r41093 | eric_niebler | 2007-11-14 08:36:15 -0800 (Wed, 14 Nov 2007) | 1 line fix support for segmented iteration ........ r41094 | dave | 2007-11-14 09:37:55 -0800 (Wed, 14 Nov 2007) | 3 lines Update command-prompt instructions per http://news.gmane.org/find-root.php?message_id=%3cfhcrem%24c4%241%40ger.gmane.org%3e ........ r41095 | bemandawes | 2007-11-14 12:05:30 -0800 (Wed, 14 Nov 2007) | 1 line Bring docs more in line with reality:-) ........ r41097 | hljin | 2007-11-14 18:07:53 -0800 (Wed, 14 Nov 2007) | 1 line GIL: removed the example directory from the documentation as it is a duplication and re-directed the Doxygen documentation to a local copy (to be submitted next) ........ r41098 | hljin | 2007-11-14 18:30:13 -0800 (Wed, 14 Nov 2007) | 1 line GIL: added a local copy of the Doxygen documentation ........ r41099 | hljin | 2007-11-14 18:32:04 -0800 (Wed, 14 Nov 2007) | 1 line GIL: added a local copy of the Doxygen documentation (second batch) ........ r41100 | chris_kohlhoff | 2007-11-14 22:19:04 -0800 (Wed, 14 Nov 2007) | 6 lines Try to fix an order-of-initialisation problem with error_category references. The symptom, which only occurs in some applications, is a crash due to a dereference of a null pointer. The exact conditions under which the problem occurs are not fully understood, so this fix is probably more paranoid than necessary. ........ r41102 | jhunold | 2007-11-14 23:04:24 -0800 (Wed, 14 Nov 2007) | 1 line Suppress msvc "deprecated" warnings. ........ r41103 | johnmaddock | 2007-11-15 01:52:26 -0800 (Thu, 15 Nov 2007) | 1 line Fix some compiler warnings when building with the Intel and aCC compilers. ........ r41104 | garcia | 2007-11-15 04:50:48 -0800 (Thu, 15 Nov 2007) | 2 lines John Torjo is reviewing the X-files. ........ r41105 | hkaiser | 2007-11-15 05:27:24 -0800 (Thu, 15 Nov 2007) | 1 line Suppressed more warnings during build of Wave. ........ r41106 | bemandawes | 2007-11-15 06:36:40 -0800 (Thu, 15 Nov 2007) | 1 line GetUserDefaultUILanguage isn't present for Cygwin, so disable use ........ r41107 | bemandawes | 2007-11-15 07:20:27 -0800 (Thu, 15 Nov 2007) | 1 line Get rid of .cvsignore files ........ r41108 | eric_niebler | 2007-11-15 08:06:22 -0800 (Thu, 15 Nov 2007) | 1 line fix typo ........ r41110 | grafik | 2007-11-15 08:58:21 -0800 (Thu, 15 Nov 2007) | 1 line Fix building of multiple regression tools at once. ........ r41111 | gmelquio | 2007-11-15 09:52:31 -0800 (Thu, 15 Nov 2007) | 1 line Fixed documentation typo. ........ r41113 | grafik | 2007-11-15 10:56:43 -0800 (Thu, 15 Nov 2007) | 1 line Switch intel-win32 to use static multi thread runtime since the single thread static runtime is no longer available. (fixes #1287) ........ r41114 | andreas_huber69 | 2007-11-15 11:22:12 -0800 (Thu, 15 Nov 2007) | 1 line Added new FAQ item suggested by Chris Paulse. ........ r41116 | guwi17 | 2007-11-15 12:52:37 -0800 (Thu, 15 Nov 2007) | 4 lines This patch now lets the Sun compiler work for most of uBLAS. 'test4' is now failing. Too avoid other compilers complaining about missing return values in some functions where exceptions are thrown, code was added so an arbitatry were chosen. ........ r41117 | danmarsden | 2007-11-15 13:15:47 -0800 (Thu, 15 Nov 2007) | 1 line removing failing test on EDG compilers ........ r41118 | grafik | 2007-11-15 14:05:15 -0800 (Thu, 15 Nov 2007) | 1 line Remove redundant reference to system library. It causes double linking when used indirectly through filesystem. Which can lead to double linking incompatible variants when a specific filesystem variant is requested. ........ r41119 | grafik | 2007-11-15 14:05:22 -0800 (Thu, 15 Nov 2007) | 1 line Oops, forgot we need to use the root boost project settings when building. ........ [SVN r41141]
This commit is contained in:
@@ -471,6 +471,32 @@ and template parameters should be assigned according to the following table:
|
||||
<tr><td><code>IsWrapper</code></td><td><code></code>is the type a wrapper?</td><td><code>mpl::false_<br>mpl::true_</code></td><td><code>mpl::false_</code></td></tr>
|
||||
</table>
|
||||
|
||||
|
||||
<h3><a name="tracking">Bitwise serialization</a></h3>
|
||||
Some simple classes could be serialized just by directly copying all bits
|
||||
of the class. This is, in particular, the case for POD data types containing
|
||||
no pointer members, and which are neither versioned nor tracked. Some archives,
|
||||
such as non-portable binary archives can make us of this information to
|
||||
substantially speed up Serialization.
|
||||
|
||||
To indicate the possibility of bitwise serialization the type trait defined
|
||||
in the header
|
||||
file <a href="../../../boost/serialization/is_bitwise_serializable.hpp" target="is_bitwise_serializable">is_bitwise_serializable.hpp</a>
|
||||
is used:
|
||||
<pre><code>
|
||||
namespace boost { namespace serialization {
|
||||
template<class T>
|
||||
struct is_bitwise_serializable
|
||||
: public is_arithmetic<T>
|
||||
{};
|
||||
} }
|
||||
</code></pre>
|
||||
is used, and can be specialized for other classes. The specialization
|
||||
is made easy by the corresponding macro:
|
||||
<pre><code>
|
||||
BOOST_IS_BITWISE_SERIALIZABLE(my_class)
|
||||
</code></pre>
|
||||
|
||||
<hr>
|
||||
<p><i>© Copyright <a href="http://www.rrsd.com">Robert Ramey</a> 2002-2004 and Matthias Troyer 2006.
|
||||
Distributed under the Boost Software License, Version 1.0. (See
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace std{
|
||||
#include <boost/archive/archive_exception.hpp>
|
||||
#include <boost/archive/detail/auto_link_archive.hpp>
|
||||
#include <boost/mpl/placeholders.hpp>
|
||||
#include <boost/type_traits/is_fundamental.hpp>
|
||||
#include <boost/serialization/is_bitwise_serializable.hpp>
|
||||
#include <boost/serialization/array.hpp>
|
||||
#include <boost/archive/detail/abi_prefix.hpp> // must be the last header
|
||||
|
||||
@@ -113,7 +113,12 @@ public:
|
||||
~basic_binary_iprimitive();
|
||||
public:
|
||||
// we provide an optimized load for all fundamental types
|
||||
typedef is_fundamental<mpl::_1> use_array_optimization;
|
||||
//typedef serialization::is_bitwise_serializable<mpl::_1>
|
||||
// use_array_optimization;
|
||||
struct use_array_optimization {
|
||||
template <class T>
|
||||
struct apply : public serialization::is_bitwise_serializable<T> {};
|
||||
};
|
||||
|
||||
// the optimized load_array dispatches to load_binary
|
||||
template <class ValueType>
|
||||
@@ -160,7 +165,7 @@ basic_binary_iprimitive<Archive, Elem, Tr>::load_binary(
|
||||
static_cast<Elem *>(address),
|
||||
s
|
||||
);
|
||||
if(scount != static_cast<std::size_t>(s))
|
||||
if(scount != static_cast<std::streamsize>(s))
|
||||
boost::throw_exception(
|
||||
archive_exception(archive_exception::stream_error)
|
||||
);
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace std{
|
||||
#include <boost/archive/basic_streambuf_locale_saver.hpp>
|
||||
#include <boost/archive/archive_exception.hpp>
|
||||
#include <boost/archive/detail/auto_link_archive.hpp>
|
||||
#include <boost/type_traits/is_fundamental.hpp>
|
||||
#include <boost/serialization/is_bitwise_serializable.hpp>
|
||||
#include <boost/mpl/placeholders.hpp>
|
||||
#include <boost/serialization/array.hpp>
|
||||
#include <boost/archive/detail/abi_prefix.hpp> // must be the last header
|
||||
@@ -113,8 +113,16 @@ public:
|
||||
BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
|
||||
~basic_binary_oprimitive();
|
||||
public:
|
||||
|
||||
// we provide an optimized save for all fundamental types
|
||||
typedef is_fundamental<mpl::_1> use_array_optimization;
|
||||
// typedef serialization::is_bitwise_serializable<mpl::_1>
|
||||
// use_array_optimization;
|
||||
// workaround without using mpl lambdas
|
||||
struct use_array_optimization {
|
||||
template <class T>
|
||||
struct apply : public serialization::is_bitwise_serializable<T> {};
|
||||
};
|
||||
|
||||
|
||||
// the optimized save_array dispatches to save_binary
|
||||
template <class ValueType>
|
||||
|
||||
56
include/boost/serialization/complex.hpp
Normal file
56
include/boost/serialization/complex.hpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#ifndef BOOST_SERIALIZATION_COMPLEX_HPP
|
||||
#define BOOST_SERIALIZATION_COMPLEX_HPP
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// serialization/utility.hpp:
|
||||
// serialization for stl utility templates
|
||||
|
||||
// (C) Copyright 2007 Matthias Troyer .
|
||||
// Use, modification and distribution is subject to 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 for updates, documentation, and revision history.
|
||||
|
||||
#include <complex>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#include <boost/serialization/is_bitwise_serializable.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace serialization {
|
||||
|
||||
template<class Archive, class T>
|
||||
inline void serialize(
|
||||
Archive & ar,
|
||||
std::complex<T> & x,
|
||||
const unsigned int /* file_version */
|
||||
){
|
||||
ar & boost::serialization::make_nvp("real", x.real());
|
||||
ar & boost::serialization::make_nvp("imag", x.imag());
|
||||
}
|
||||
|
||||
/// specialization of serialization traits for complex
|
||||
template <class T>
|
||||
struct is_bitwise_serializable<std::complex<T> >
|
||||
: public is_bitwise_serializable<T> {};
|
||||
|
||||
template <class T>
|
||||
struct implementation_level<std::complex<T> >
|
||||
: mpl::int_<object_serializable> {} ;
|
||||
|
||||
// treat complex just like builtin arithmetic types for tracking
|
||||
template <class T>
|
||||
struct tracking_level<std::complex<T> >
|
||||
: mpl::int_<track_never> {} ;
|
||||
|
||||
} // serialization
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_SERIALIZATION_COMPLEX_HPP
|
||||
46
include/boost/serialization/is_bitwise_serializable.hpp
Normal file
46
include/boost/serialization/is_bitwise_serializable.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
// (C) Copyright 2007 Matthias Troyer
|
||||
|
||||
// Use, modification and distribution is subject to 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)
|
||||
|
||||
// Authors: Matthias Troyer
|
||||
|
||||
/** @file is_bitwise_serializable.hpp
|
||||
*
|
||||
* This header provides a traits class for determining whether a class
|
||||
* can be serialized (in a non-portable way) just by copying the bits.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef BOOST_SERIALIZATION_IS_BITWISE_SERIALIZABLE_HPP
|
||||
#define BOOST_SERIALIZATION_IS_BITWISE_SERIALIZABLE_HPP
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/mpl/bool.hpp>
|
||||
#include <boost/type_traits/is_arithmetic.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace serialization {
|
||||
template<class T>
|
||||
struct is_bitwise_serializable
|
||||
: public is_arithmetic<T>
|
||||
{};
|
||||
} // namespace serialization
|
||||
} // namespace boost
|
||||
|
||||
|
||||
// define a macro to make explicit designation of this more transparent
|
||||
#define BOOST_IS_BITWISE_SERIALIZABLE(T) \
|
||||
namespace boost { \
|
||||
namespace serialization { \
|
||||
template<> \
|
||||
struct is_bitwise_serializable< T > : mpl::true_ {}; \
|
||||
}} \
|
||||
/**/
|
||||
|
||||
#endif //BOOST_SERIALIZATION_IS_BITWISE_SERIALIZABLE_HPP
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#include <boost/serialization/is_bitwise_serializable.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace serialization {
|
||||
@@ -41,6 +42,17 @@ inline void serialize(
|
||||
ar & boost::serialization::make_nvp("second", p.second);
|
||||
}
|
||||
|
||||
/// specialization of is_bitwise_serializable for pairs
|
||||
template <class T, class U>
|
||||
struct is_bitwise_serializable<std::pair<T,U> >
|
||||
: public mpl::and_<is_bitwise_serializable<T>,is_bitwise_serializable<U> >
|
||||
{
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
struct implementation_level<std::pair<T,U> >
|
||||
: mpl::int_<object_serializable> {} ;
|
||||
|
||||
} // serialization
|
||||
} // namespace boost
|
||||
|
||||
|
||||
@@ -206,6 +206,7 @@ rule test-bsl-run_polymorphic_archive ( test-name : sources * ) {
|
||||
test-suite "serialization" :
|
||||
[ test-bsl-run_files test_array ]
|
||||
[ test-bsl-run_files test_binary ]
|
||||
[ test-bsl-run_files test_complex ]
|
||||
[ test-bsl-run_files test_contained_class ]
|
||||
[ test-bsl-run_files test_cyclic_ptrs ]
|
||||
[ test-bsl-run_files test_delete_pointer ]
|
||||
|
||||
57
test/test_complex.cpp
Normal file
57
test/test_complex.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// test_complex.cpp
|
||||
|
||||
// (C) Copyright 2005 Matthias Troyer .
|
||||
// Use, modification and distribution is subject to 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)
|
||||
|
||||
// should pass compilation and execution
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include <cstdio> // remove
|
||||
#include <boost/config.hpp>
|
||||
#if defined(BOOST_NO_STDC_NAMESPACE)
|
||||
namespace std{
|
||||
using ::remove;
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "test_tools.hpp"
|
||||
#include <boost/preprocessor/stringize.hpp>
|
||||
#include BOOST_PP_STRINGIZE(BOOST_ARCHIVE_TEST)
|
||||
|
||||
#include <boost/serialization/complex.hpp>
|
||||
|
||||
int test_main( int /* argc */, char* /* argv */[] )
|
||||
{
|
||||
const char * testfile = boost::archive::tmpnam(NULL);
|
||||
BOOST_REQUIRE(NULL != testfile);
|
||||
|
||||
// test array of objects
|
||||
std::complex<float> a(std::rand(),std::rand());
|
||||
std::complex<double> b(std::rand(),std::rand());
|
||||
{
|
||||
test_ostream os(testfile, TEST_STREAM_FLAGS);
|
||||
test_oarchive oa(os);
|
||||
oa << boost::serialization::make_nvp("afloatcomplex", a);
|
||||
oa << boost::serialization::make_nvp("adoublecomplex", b);
|
||||
}
|
||||
std::complex<float> a1;
|
||||
std::complex<double> b1;
|
||||
{
|
||||
test_istream is(testfile, TEST_STREAM_FLAGS);
|
||||
test_iarchive ia(is);
|
||||
ia >> boost::serialization::make_nvp("afloatcomplex", a1);
|
||||
ia >> boost::serialization::make_nvp("adoublecomplex", b1);
|
||||
}
|
||||
bool equal = (std::abs(a-a1) <= 2.*std::numeric_limits<float>::round_error()
|
||||
&& std::abs(b-b1) <= 2.*std::numeric_limits<double>::round_error() );
|
||||
|
||||
BOOST_CHECK(equal);
|
||||
std::remove(testfile);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
// EOF
|
||||
Reference in New Issue
Block a user