@@ -723,6 +723,20 @@ inline void Unserialize(Stream& is, T&& a)
723
723
a.Unserialize (is);
724
724
}
725
725
726
+ /* * Default formatter. Serializes objects as themselves.
727
+ *
728
+ * The vector/prevector serialization code passes this to VectorFormatter
729
+ * to enable reusing that logic. It shouldn't be needed elsewhere.
730
+ */
731
+ struct DefaultFormatter
732
+ {
733
+ template <typename Stream, typename T>
734
+ static void Ser (Stream& s, const T& t) { Serialize (s, t); }
735
+
736
+ template <typename Stream, typename T>
737
+ static void Unser (Stream& s, T& t) { Unserialize (s, t); }
738
+ };
739
+
726
740
727
741
728
742
@@ -763,9 +777,7 @@ void Serialize_impl(Stream& os, const prevector<N, T>& v, const unsigned char&)
763
777
template <typename Stream, unsigned int N, typename T, typename V>
764
778
void Serialize_impl (Stream& os, const prevector<N, T>& v, const V&)
765
779
{
766
- WriteCompactSize (os, v.size ());
767
- for (typename prevector<N, T>::const_iterator vi = v.begin (); vi != v.end (); ++vi)
768
- ::Serialize (os, (*vi));
780
+ Serialize (os, Using<VectorFormatter<DefaultFormatter>>(v));
769
781
}
770
782
771
783
template <typename Stream, unsigned int N, typename T>
@@ -794,19 +806,7 @@ void Unserialize_impl(Stream& is, prevector<N, T>& v, const unsigned char&)
794
806
template <typename Stream, unsigned int N, typename T, typename V>
795
807
void Unserialize_impl (Stream& is, prevector<N, T>& v, const V&)
796
808
{
797
- v.clear ();
798
- unsigned int nSize = ReadCompactSize (is);
799
- unsigned int i = 0 ;
800
- unsigned int nMid = 0 ;
801
- while (nMid < nSize)
802
- {
803
- nMid += MAX_VECTOR_ALLOCATE / sizeof (T);
804
- if (nMid > nSize)
805
- nMid = nSize;
806
- v.resize_uninitialized (nMid);
807
- for (; i < nMid; ++i)
808
- Unserialize (is, v[i]);
809
- }
809
+ Unserialize (is, Using<VectorFormatter<DefaultFormatter>>(v));
810
810
}
811
811
812
812
template <typename Stream, unsigned int N, typename T>
@@ -843,9 +843,7 @@ void Serialize_impl(Stream& os, const std::vector<T, A>& v, const bool&)
843
843
template <typename Stream, typename T, typename A, typename V>
844
844
void Serialize_impl (Stream& os, const std::vector<T, A>& v, const V&)
845
845
{
846
- WriteCompactSize (os, v.size ());
847
- for (typename std::vector<T, A>::const_iterator vi = v.begin (); vi != v.end (); ++vi)
848
- ::Serialize (os, (*vi));
846
+ Serialize (os, Using<VectorFormatter<DefaultFormatter>>(v));
849
847
}
850
848
851
849
template <typename Stream, typename T, typename A>
@@ -874,19 +872,7 @@ void Unserialize_impl(Stream& is, std::vector<T, A>& v, const unsigned char&)
874
872
template <typename Stream, typename T, typename A, typename V>
875
873
void Unserialize_impl (Stream& is, std::vector<T, A>& v, const V&)
876
874
{
877
- v.clear ();
878
- unsigned int nSize = ReadCompactSize (is);
879
- unsigned int i = 0 ;
880
- unsigned int nMid = 0 ;
881
- while (nMid < nSize)
882
- {
883
- nMid += MAX_VECTOR_ALLOCATE / sizeof (T);
884
- if (nMid > nSize)
885
- nMid = nSize;
886
- v.resize (nMid);
887
- for (; i < nMid; i++)
888
- Unserialize (is, v[i]);
889
- }
875
+ Unserialize (is, Using<VectorFormatter<DefaultFormatter>>(v));
890
876
}
891
877
892
878
template <typename Stream, typename T, typename A>
0 commit comments