@@ -74,61 +74,53 @@ OverrideStream<S> WithOrVersion(S* s, int nVersionFlag)
7474 * >> and << read and write unformatted data using the above serialization templates.
7575 * Fills with data in linear time; some stringstream implementations take N^2 time.
7676 */
77- class CDataStream
77+ template <typename VecType>
78+ class CBaseDataStream
7879{
7980protected:
80- typedef CSerializeData vector_type;
81+ typedef VecType vector_type;
8182 vector_type vch;
8283 unsigned int nReadPos;
8384
8485 int nType;
8586 int nVersion;
8687public:
8788
88- typedef vector_type::allocator_type allocator_type;
89- typedef vector_type::size_type size_type;
90- typedef vector_type::difference_type difference_type;
91- typedef vector_type::reference reference;
92- typedef vector_type::const_reference const_reference;
93- typedef vector_type::value_type value_type;
94- typedef vector_type::iterator iterator;
95- typedef vector_type::const_iterator const_iterator;
96- typedef vector_type::reverse_iterator reverse_iterator;
89+ typedef typename vector_type::allocator_type allocator_type;
90+ typedef typename vector_type::size_type size_type;
91+ typedef typename vector_type::difference_type difference_type;
92+ typedef typename vector_type::reference reference;
93+ typedef typename vector_type::const_reference const_reference;
94+ typedef typename vector_type::value_type value_type;
95+ typedef typename vector_type::iterator iterator;
96+ typedef typename vector_type::const_iterator const_iterator;
97+ typedef typename vector_type::reverse_iterator reverse_iterator;
9798
98- explicit CDataStream (int nTypeIn, int nVersionIn)
99+ explicit CBaseDataStream (int nTypeIn, int nVersionIn)
99100 {
100101 Init (nTypeIn, nVersionIn);
101102 }
102103
103- CDataStream (const_iterator pbegin, const_iterator pend, int nTypeIn, int nVersionIn) : vch(pbegin, pend)
104+ CBaseDataStream (const_iterator pbegin, const_iterator pend, int nTypeIn, int nVersionIn) : vch(pbegin, pend)
104105 {
105106 Init (nTypeIn, nVersionIn);
106107 }
107108
108109#if !defined(_MSC_VER) || _MSC_VER >= 1300
109- CDataStream (const char * pbegin, const char * pend, int nTypeIn, int nVersionIn) : vch(pbegin, pend)
110+ CBaseDataStream (const char * pbegin, const char * pend, int nTypeIn, int nVersionIn) : vch(pbegin, pend)
110111 {
111112 Init (nTypeIn, nVersionIn);
112113 }
113114#endif
114115
115- CDataStream (const vector_type& vchIn, int nTypeIn, int nVersionIn) : vch(vchIn.begin(), vchIn.end())
116- {
117- Init (nTypeIn, nVersionIn);
118- }
119-
120- CDataStream (const std::vector<char >& vchIn, int nTypeIn, int nVersionIn) : vch(vchIn.begin(), vchIn.end())
121- {
122- Init (nTypeIn, nVersionIn);
123- }
124-
125- CDataStream (const std::vector<unsigned char >& vchIn, int nTypeIn, int nVersionIn) : vch(vchIn.begin(), vchIn.end())
116+ template <typename T>
117+ CBaseDataStream (const T& vchIn, int nTypeIn, int nVersionIn) : vch(vchIn.begin(), vchIn.end())
126118 {
127119 Init (nTypeIn, nVersionIn);
128120 }
129121
130122 template <typename ... Args>
131- CDataStream (int nTypeIn, int nVersionIn, Args&&... args)
123+ CBaseDataStream (int nTypeIn, int nVersionIn, Args&&... args)
132124 {
133125 Init (nTypeIn, nVersionIn);
134126 ::SerializeMany (*this , std::forward<Args>(args)...);
@@ -141,15 +133,15 @@ class CDataStream
141133 nVersion = nVersionIn;
142134 }
143135
144- CDataStream & operator +=(const CDataStream & b)
136+ CBaseDataStream & operator +=(const CBaseDataStream & b)
145137 {
146138 vch.insert (vch.end (), b.begin (), b.end ());
147139 return *this ;
148140 }
149141
150- friend CDataStream operator +(const CDataStream & a, const CDataStream & b)
142+ friend CBaseDataStream operator +(const CBaseDataStream & a, const CBaseDataStream & b)
151143 {
152- CDataStream ret = a;
144+ CBaseDataStream ret = a;
153145 ret += b;
154146 return (ret);
155147 }
@@ -262,7 +254,7 @@ class CDataStream
262254 // Stream subset
263255 //
264256 bool eof () const { return size () == 0 ; }
265- CDataStream * rdbuf () { return this ; }
257+ CBaseDataStream * rdbuf () { return this ; }
266258 int in_avail () { return size (); }
267259
268260 void SetType (int n) { nType = n; }
@@ -278,7 +270,7 @@ class CDataStream
278270 {
279271 if (nReadPosNext > vch.size ())
280272 {
281- throw std::ios_base::failure (" CDataStream ::read(): end of data" );
273+ throw std::ios_base::failure (" CBaseDataStream ::read(): end of data" );
282274 }
283275 memcpy (pch, &vch[nReadPos], nSize);
284276 nReadPos = 0 ;
@@ -293,13 +285,13 @@ class CDataStream
293285 {
294286 // Ignore from the beginning of the buffer
295287 if (nSize < 0 ) {
296- throw std::ios_base::failure (" CDataStream ::ignore(): nSize negative" );
288+ throw std::ios_base::failure (" CBaseDataStream ::ignore(): nSize negative" );
297289 }
298290 unsigned int nReadPosNext = nReadPos + nSize;
299291 if (nReadPosNext >= vch.size ())
300292 {
301293 if (nReadPosNext > vch.size ())
302- throw std::ios_base::failure (" CDataStream ::ignore(): end of data" );
294+ throw std::ios_base::failure (" CBaseDataStream ::ignore(): end of data" );
303295 nReadPos = 0 ;
304296 vch.clear ();
305297 return ;
@@ -322,15 +314,15 @@ class CDataStream
322314 }
323315
324316 template <typename T>
325- CDataStream & operator <<(const T& obj)
317+ CBaseDataStream & operator <<(const T& obj)
326318 {
327319 // Serialize to this stream
328320 ::Serialize (*this , obj);
329321 return (*this );
330322 }
331323
332324 template <typename T>
333- CDataStream & operator >>(T& obj)
325+ CBaseDataStream & operator >>(T& obj)
334326 {
335327 // Unserialize from this stream
336328 ::Unserialize (*this , obj);
@@ -367,7 +359,8 @@ class CDataStream
367359};
368360
369361
370-
362+ using CDataStream = CBaseDataStream<std::vector<char >>;
363+ using CClearingDataStream = CBaseDataStream<CSerializeData>;
371364
372365
373366
0 commit comments