@@ -187,7 +187,7 @@ class CDataStream
187187protected:
188188 using vector_type = SerializeData;
189189 vector_type vch;
190- vector_type::size_type nReadPos {0 };
190+ vector_type::size_type m_read_pos {0 };
191191
192192 int nType;
193193 int nVersion;
@@ -230,37 +230,37 @@ class CDataStream
230230 //
231231 // Vector subset
232232 //
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 ; }
235235 const_iterator end () const { return vch.end (); }
236236 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 ; }
246246
247247 inline void Compact ()
248248 {
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 ;
251251 }
252252
253253 bool Rewind (std::optional<size_type> n = std::nullopt )
254254 {
255255 // Total rewind if no size is passed
256256 if (!n) {
257- nReadPos = 0 ;
257+ m_read_pos = 0 ;
258258 return true ;
259259 }
260260 // Rewind by n characters if the buffer hasn't been compacted yet
261- if (*n > nReadPos )
261+ if (*n > m_read_pos )
262262 return false ;
263- nReadPos -= *n;
263+ m_read_pos -= *n;
264264 return true ;
265265 }
266266
@@ -282,32 +282,32 @@ class CDataStream
282282 if (dst.size () == 0 ) return ;
283283
284284 // 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 ())};
286286 if (!next_read_pos.has_value () || next_read_pos.value () > vch.size ()) {
287287 throw std::ios_base::failure (" CDataStream::read(): end of data" );
288288 }
289- memcpy (dst.data (), &vch[nReadPos ], dst.size ());
289+ memcpy (dst.data (), &vch[m_read_pos ], dst.size ());
290290 if (next_read_pos.value () == vch.size ()) {
291- nReadPos = 0 ;
291+ m_read_pos = 0 ;
292292 vch.clear ();
293293 return ;
294294 }
295- nReadPos = next_read_pos.value ();
295+ m_read_pos = next_read_pos.value ();
296296 }
297297
298298 void ignore (size_t num_ignore)
299299 {
300300 // 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)};
302302 if (!next_read_pos.has_value () || next_read_pos.value () > vch.size ()) {
303303 throw std::ios_base::failure (" CDataStream::ignore(): end of data" );
304304 }
305305 if (next_read_pos.value () == vch.size ()) {
306- nReadPos = 0 ;
306+ m_read_pos = 0 ;
307307 vch.clear ();
308308 return ;
309309 }
310- nReadPos = next_read_pos.value ();
310+ m_read_pos = next_read_pos.value ();
311311 }
312312
313313 void write (Span<const value_type> src)
@@ -591,7 +591,7 @@ class CBufferedFile
591591
592592 FILE *src; // !< source file
593593 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
595595 uint64_t nReadLimit; // !< up to which position we're allowed to read
596596 uint64_t nRewind; // !< how many bytes we guarantee to rewind
597597 std::vector<std::byte> vchBuf; // !< the buffer
@@ -601,7 +601,7 @@ class CBufferedFile
601601 bool Fill () {
602602 unsigned int pos = nSrcPos % vchBuf.size ();
603603 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;
605605 if (nAvail < readNow)
606606 readNow = nAvail;
607607 if (readNow == 0 )
@@ -616,7 +616,7 @@ class CBufferedFile
616616
617617public:
618618 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 })
620620 {
621621 if (nRewindIn >= nBufSize)
622622 throw std::ios_base::failure (" Rewind limit must be less than buffer size" );
@@ -645,56 +645,56 @@ class CBufferedFile
645645
646646 // ! check whether we're at the end of the source file
647647 bool eof () const {
648- return nReadPos == nSrcPos && feof (src);
648+ return m_read_pos == nSrcPos && feof (src);
649649 }
650650
651651 // ! read a number of bytes
652652 void read (Span<std::byte> dst)
653653 {
654- if (dst.size () + nReadPos > nReadLimit) {
654+ if (dst.size () + m_read_pos > nReadLimit) {
655655 throw std::ios_base::failure (" Read attempted past buffer limit" );
656656 }
657657 while (dst.size () > 0 ) {
658- if (nReadPos == nSrcPos)
658+ if (m_read_pos == nSrcPos)
659659 Fill ();
660- unsigned int pos = nReadPos % vchBuf.size ();
660+ unsigned int pos = m_read_pos % vchBuf.size ();
661661 size_t nNow = dst.size ();
662662 if (nNow + pos > vchBuf.size ())
663663 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 ;
666666 memcpy (dst.data (), &vchBuf[pos], nNow);
667- nReadPos += nNow;
667+ m_read_pos += nNow;
668668 dst = dst.subspan (nNow);
669669 }
670670 }
671671
672672 // ! return the current reading position
673673 uint64_t GetPos () const {
674- return nReadPos ;
674+ return m_read_pos ;
675675 }
676676
677677 // ! rewind to a given reading position
678678 bool SetPos (uint64_t nPos) {
679679 size_t bufsize = vchBuf.size ();
680680 if (nPos + bufsize < nSrcPos) {
681681 // rewinding too far, rewind as far as possible
682- nReadPos = nSrcPos - bufsize;
682+ m_read_pos = nSrcPos - bufsize;
683683 return false ;
684684 }
685685 if (nPos > nSrcPos) {
686686 // can't go this far forward, go as far as possible
687- nReadPos = nSrcPos;
687+ m_read_pos = nSrcPos;
688688 return false ;
689689 }
690- nReadPos = nPos;
690+ m_read_pos = nPos;
691691 return true ;
692692 }
693693
694694 // ! prevent reading beyond a certain position
695695 // ! no argument removes the limit
696696 bool SetLimit (uint64_t nPos = std::numeric_limits<uint64_t >::max()) {
697- if (nPos < nReadPos )
697+ if (nPos < m_read_pos )
698698 return false ;
699699 nReadLimit = nPos;
700700 return true ;
@@ -711,12 +711,12 @@ class CBufferedFile
711711 void FindByte (uint8_t ch)
712712 {
713713 while (true ) {
714- if (nReadPos == nSrcPos)
714+ if (m_read_pos == nSrcPos)
715715 Fill ();
716- if (vchBuf[nReadPos % vchBuf.size ()] == std::byte{ch}) {
716+ if (vchBuf[m_read_pos % vchBuf.size ()] == std::byte{ch}) {
717717 break ;
718718 }
719- nReadPos ++;
719+ m_read_pos ++;
720720 }
721721 }
722722};
0 commit comments