@@ -187,7 +187,7 @@ class CDataStream
187
187
protected:
188
188
using vector_type = SerializeData;
189
189
vector_type vch;
190
- vector_type::size_type nReadPos {0 };
190
+ vector_type::size_type m_read_pos {0 };
191
191
192
192
int nType;
193
193
int nVersion;
@@ -230,37 +230,37 @@ class CDataStream
230
230
//
231
231
// Vector subset
232
232
//
233
- const_iterator begin () const { return vch.begin () + nReadPos ; }
234
- iterator begin () { return vch.begin () + nReadPos ; }
233
+ const_iterator begin () const { return vch.begin () + m_read_pos ; }
234
+ iterator begin () { return vch.begin () + m_read_pos ; }
235
235
const_iterator end () const { return vch.end (); }
236
236
iterator end () { return vch.end (); }
237
- size_type size () const { return vch.size () - nReadPos ; }
238
- bool empty () const { return vch.size () == nReadPos ; }
239
- void resize (size_type n, value_type c = value_type{}) { vch.resize (n + nReadPos , c); }
240
- void reserve (size_type n) { vch.reserve (n + nReadPos ); }
241
- const_reference operator [](size_type pos) const { return vch[pos + nReadPos ]; }
242
- reference operator [](size_type pos) { return vch[pos + nReadPos ]; }
243
- void clear () { vch.clear (); nReadPos = 0 ; }
244
- value_type* data () { return vch.data () + nReadPos ; }
245
- const value_type* data () const { return vch.data () + nReadPos ; }
237
+ size_type size () const { return vch.size () - m_read_pos ; }
238
+ bool empty () const { return vch.size () == m_read_pos ; }
239
+ void resize (size_type n, value_type c = value_type{}) { vch.resize (n + m_read_pos , c); }
240
+ void reserve (size_type n) { vch.reserve (n + m_read_pos ); }
241
+ const_reference operator [](size_type pos) const { return vch[pos + m_read_pos ]; }
242
+ reference operator [](size_type pos) { return vch[pos + m_read_pos ]; }
243
+ void clear () { vch.clear (); m_read_pos = 0 ; }
244
+ value_type* data () { return vch.data () + m_read_pos ; }
245
+ const value_type* data () const { return vch.data () + m_read_pos ; }
246
246
247
247
inline void Compact ()
248
248
{
249
- vch.erase (vch.begin (), vch.begin () + nReadPos );
250
- nReadPos = 0 ;
249
+ vch.erase (vch.begin (), vch.begin () + m_read_pos );
250
+ m_read_pos = 0 ;
251
251
}
252
252
253
253
bool Rewind (std::optional<size_type> n = std::nullopt)
254
254
{
255
255
// Total rewind if no size is passed
256
256
if (!n) {
257
- nReadPos = 0 ;
257
+ m_read_pos = 0 ;
258
258
return true ;
259
259
}
260
260
// Rewind by n characters if the buffer hasn't been compacted yet
261
- if (*n > nReadPos )
261
+ if (*n > m_read_pos )
262
262
return false ;
263
- nReadPos -= *n;
263
+ m_read_pos -= *n;
264
264
return true ;
265
265
}
266
266
@@ -282,32 +282,32 @@ class CDataStream
282
282
if (dst.size () == 0 ) return ;
283
283
284
284
// Read from the beginning of the buffer
285
- auto next_read_pos{CheckedAdd (nReadPos , dst.size ())};
285
+ auto next_read_pos{CheckedAdd (m_read_pos , dst.size ())};
286
286
if (!next_read_pos.has_value () || next_read_pos.value () > vch.size ()) {
287
287
throw std::ios_base::failure (" CDataStream::read(): end of data" );
288
288
}
289
- memcpy (dst.data (), &vch[nReadPos ], dst.size ());
289
+ memcpy (dst.data (), &vch[m_read_pos ], dst.size ());
290
290
if (next_read_pos.value () == vch.size ()) {
291
- nReadPos = 0 ;
291
+ m_read_pos = 0 ;
292
292
vch.clear ();
293
293
return ;
294
294
}
295
- nReadPos = next_read_pos.value ();
295
+ m_read_pos = next_read_pos.value ();
296
296
}
297
297
298
298
void ignore (size_t num_ignore)
299
299
{
300
300
// Ignore from the beginning of the buffer
301
- auto next_read_pos{CheckedAdd (nReadPos , num_ignore)};
301
+ auto next_read_pos{CheckedAdd (m_read_pos , num_ignore)};
302
302
if (!next_read_pos.has_value () || next_read_pos.value () > vch.size ()) {
303
303
throw std::ios_base::failure (" CDataStream::ignore(): end of data" );
304
304
}
305
305
if (next_read_pos.value () == vch.size ()) {
306
- nReadPos = 0 ;
306
+ m_read_pos = 0 ;
307
307
vch.clear ();
308
308
return ;
309
309
}
310
- nReadPos = next_read_pos.value ();
310
+ m_read_pos = next_read_pos.value ();
311
311
}
312
312
313
313
void write (Span<const value_type> src)
@@ -591,7 +591,7 @@ class CBufferedFile
591
591
592
592
FILE *src; // !< source file
593
593
uint64_t nSrcPos; // !< how many bytes have been read from source
594
- uint64_t nReadPos ; // !< how many bytes have been read from this
594
+ uint64_t m_read_pos ; // !< how many bytes have been read from this
595
595
uint64_t nReadLimit; // !< up to which position we're allowed to read
596
596
uint64_t nRewind; // !< how many bytes we guarantee to rewind
597
597
std::vector<std::byte> vchBuf; // !< the buffer
@@ -601,7 +601,7 @@ class CBufferedFile
601
601
bool Fill () {
602
602
unsigned int pos = nSrcPos % vchBuf.size ();
603
603
unsigned int readNow = vchBuf.size () - pos;
604
- unsigned int nAvail = vchBuf.size () - (nSrcPos - nReadPos ) - nRewind;
604
+ unsigned int nAvail = vchBuf.size () - (nSrcPos - m_read_pos ) - nRewind;
605
605
if (nAvail < readNow)
606
606
readNow = nAvail;
607
607
if (readNow == 0 )
@@ -616,7 +616,7 @@ class CBufferedFile
616
616
617
617
public:
618
618
CBufferedFile (FILE* fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nTypeIn, int nVersionIn)
619
- : nType(nTypeIn), nVersion(nVersionIn), nSrcPos(0 ), nReadPos (0 ), nReadLimit(std::numeric_limits<uint64_t >::max()), nRewind(nRewindIn), vchBuf(nBufSize, std::byte{0 })
619
+ : nType(nTypeIn), nVersion(nVersionIn), nSrcPos(0 ), m_read_pos (0 ), nReadLimit(std::numeric_limits<uint64_t >::max()), nRewind(nRewindIn), vchBuf(nBufSize, std::byte{0 })
620
620
{
621
621
if (nRewindIn >= nBufSize)
622
622
throw std::ios_base::failure (" Rewind limit must be less than buffer size" );
@@ -645,56 +645,56 @@ class CBufferedFile
645
645
646
646
// ! check whether we're at the end of the source file
647
647
bool eof () const {
648
- return nReadPos == nSrcPos && feof (src);
648
+ return m_read_pos == nSrcPos && feof (src);
649
649
}
650
650
651
651
// ! read a number of bytes
652
652
void read (Span<std::byte> dst)
653
653
{
654
- if (dst.size () + nReadPos > nReadLimit) {
654
+ if (dst.size () + m_read_pos > nReadLimit) {
655
655
throw std::ios_base::failure (" Read attempted past buffer limit" );
656
656
}
657
657
while (dst.size () > 0 ) {
658
- if (nReadPos == nSrcPos)
658
+ if (m_read_pos == nSrcPos)
659
659
Fill ();
660
- unsigned int pos = nReadPos % vchBuf.size ();
660
+ unsigned int pos = m_read_pos % vchBuf.size ();
661
661
size_t nNow = dst.size ();
662
662
if (nNow + pos > vchBuf.size ())
663
663
nNow = vchBuf.size () - pos;
664
- if (nNow + nReadPos > nSrcPos)
665
- nNow = nSrcPos - nReadPos ;
664
+ if (nNow + m_read_pos > nSrcPos)
665
+ nNow = nSrcPos - m_read_pos ;
666
666
memcpy (dst.data (), &vchBuf[pos], nNow);
667
- nReadPos += nNow;
667
+ m_read_pos += nNow;
668
668
dst = dst.subspan (nNow);
669
669
}
670
670
}
671
671
672
672
// ! return the current reading position
673
673
uint64_t GetPos () const {
674
- return nReadPos ;
674
+ return m_read_pos ;
675
675
}
676
676
677
677
// ! rewind to a given reading position
678
678
bool SetPos (uint64_t nPos) {
679
679
size_t bufsize = vchBuf.size ();
680
680
if (nPos + bufsize < nSrcPos) {
681
681
// rewinding too far, rewind as far as possible
682
- nReadPos = nSrcPos - bufsize;
682
+ m_read_pos = nSrcPos - bufsize;
683
683
return false ;
684
684
}
685
685
if (nPos > nSrcPos) {
686
686
// can't go this far forward, go as far as possible
687
- nReadPos = nSrcPos;
687
+ m_read_pos = nSrcPos;
688
688
return false ;
689
689
}
690
- nReadPos = nPos;
690
+ m_read_pos = nPos;
691
691
return true ;
692
692
}
693
693
694
694
// ! prevent reading beyond a certain position
695
695
// ! no argument removes the limit
696
696
bool SetLimit (uint64_t nPos = std::numeric_limits<uint64_t >::max()) {
697
- if (nPos < nReadPos )
697
+ if (nPos < m_read_pos )
698
698
return false ;
699
699
nReadLimit = nPos;
700
700
return true ;
@@ -711,12 +711,12 @@ class CBufferedFile
711
711
void FindByte (uint8_t ch)
712
712
{
713
713
while (true ) {
714
- if (nReadPos == nSrcPos)
714
+ if (m_read_pos == nSrcPos)
715
715
Fill ();
716
- if (vchBuf[nReadPos % vchBuf.size ()] == std::byte{ch}) {
716
+ if (vchBuf[m_read_pos % vchBuf.size ()] == std::byte{ch}) {
717
717
break ;
718
718
}
719
- nReadPos ++;
719
+ m_read_pos ++;
720
720
}
721
721
}
722
722
};
0 commit comments