diff options
author | Cory Fields <cory-nospam-@coryfields.com> | 2014-10-08 14:27:07 -0400 |
---|---|---|
committer | Cory Fields <cory-nospam-@coryfields.com> | 2014-10-15 15:13:19 -0400 |
commit | 1d9b86d584542fbc34bf49726badaba2ca764228 (patch) | |
tree | c4707cfbfa2d6c5374b0edd665d74d897867a3af /src | |
parent | 992ab87114b8c9ea8230e97a9c8d8bd71939074d (diff) |
boost: drop dependency on is_fundamental in serialization
There's only one case where a vector containing a fundamental type is
serialized all-at-once, unsigned char. Anything else would lead to
strange results.
Use a dummy argument to overload in that case.
Diffstat (limited to 'src')
-rw-r--r-- | src/serialize.h | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/src/serialize.h b/src/serialize.h index ff11edc06c..8220fecb9c 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -21,7 +21,6 @@ #include <vector> #include <boost/tuple/tuple.hpp> -#include <boost/type_traits/is_fundamental.hpp> class CAutoFile; class CDataStream; @@ -432,14 +431,15 @@ template<typename Stream, typename C> void Serialize(Stream& os, const std::basi template<typename Stream, typename C> void Unserialize(Stream& is, std::basic_string<C>& str, int, int=0); // vector -template<typename T, typename A> unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const boost::true_type&); -template<typename T, typename A> unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const boost::false_type&); +// vectors of unsigned char are a special case and are intended to be serialized as a single opaque blob. +template<typename T, typename A> unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const unsigned char&); +template<typename T, typename A, typename V> unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const V&); template<typename T, typename A> inline unsigned int GetSerializeSize(const std::vector<T, A>& v, int nType, int nVersion); -template<typename Stream, typename T, typename A> void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVersion, const boost::true_type&); -template<typename Stream, typename T, typename A> void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVersion, const boost::false_type&); +template<typename Stream, typename T, typename A> void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVersion, const unsigned char&); +template<typename Stream, typename T, typename A, typename V> void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVersion, const V&); template<typename Stream, typename T, typename A> inline void Serialize(Stream& os, const std::vector<T, A>& v, int nType, int nVersion); -template<typename Stream, typename T, typename A> void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const boost::true_type&); -template<typename Stream, typename T, typename A> void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const boost::false_type&); +template<typename Stream, typename T, typename A> void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const unsigned char&); +template<typename Stream, typename T, typename A, typename V> void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const V&); template<typename Stream, typename T, typename A> inline void Unserialize(Stream& is, std::vector<T, A>& v, int nType, int nVersion); // others derived from vector @@ -536,13 +536,13 @@ void Unserialize(Stream& is, std::basic_string<C>& str, int, int) // vector // template<typename T, typename A> -unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const boost::true_type&) +unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const unsigned char&) { return (GetSizeOfCompactSize(v.size()) + v.size() * sizeof(T)); } -template<typename T, typename A> -unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const boost::false_type&) +template<typename T, typename A, typename V> +unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const V&) { unsigned int nSize = GetSizeOfCompactSize(v.size()); for (typename std::vector<T, A>::const_iterator vi = v.begin(); vi != v.end(); ++vi) @@ -553,20 +553,20 @@ unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nV template<typename T, typename A> inline unsigned int GetSerializeSize(const std::vector<T, A>& v, int nType, int nVersion) { - return GetSerializeSize_impl(v, nType, nVersion, boost::is_fundamental<T>()); + return GetSerializeSize_impl(v, nType, nVersion, T()); } template<typename Stream, typename T, typename A> -void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVersion, const boost::true_type&) +void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVersion, const unsigned char&) { WriteCompactSize(os, v.size()); if (!v.empty()) os.write((char*)&v[0], v.size() * sizeof(T)); } -template<typename Stream, typename T, typename A> -void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVersion, const boost::false_type&) +template<typename Stream, typename T, typename A, typename V> +void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVersion, const V&) { WriteCompactSize(os, v.size()); for (typename std::vector<T, A>::const_iterator vi = v.begin(); vi != v.end(); ++vi) @@ -576,12 +576,12 @@ void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVers template<typename Stream, typename T, typename A> inline void Serialize(Stream& os, const std::vector<T, A>& v, int nType, int nVersion) { - Serialize_impl(os, v, nType, nVersion, boost::is_fundamental<T>()); + Serialize_impl(os, v, nType, nVersion, T()); } template<typename Stream, typename T, typename A> -void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const boost::true_type&) +void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const unsigned char&) { // Limit size per read so bogus size value won't cause out of memory v.clear(); @@ -596,8 +596,8 @@ void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, } } -template<typename Stream, typename T, typename A> -void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const boost::false_type&) +template<typename Stream, typename T, typename A, typename V> +void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const V&) { v.clear(); unsigned int nSize = ReadCompactSize(is); @@ -617,7 +617,7 @@ void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, template<typename Stream, typename T, typename A> inline void Unserialize(Stream& is, std::vector<T, A>& v, int nType, int nVersion) { - Unserialize_impl(is, v, nType, nVersion, boost::is_fundamental<T>()); + Unserialize_impl(is, v, nType, nVersion, T()); } |