X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=blobdiff_plain;f=src%2Fserialize.h;h=bdcd830591d570dbde8aacb9d4ab8312b0cc406f;hp=a1f8a0ee67d0d4e522dc1f24f42516ebf768b424;hb=415da519893e8fef7a10007fc82934385addd03d;hpb=5b1a3f0a5efd2d87368de586ccf685449b2af847 diff --git a/src/serialize.h b/src/serialize.h index a1f8a0e..bdcd830 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -56,13 +56,12 @@ enum SER_DISK = (1 << 1), SER_GETHASH = (1 << 2), - // modifiers - SER_SKIPSIG = (1 << 16), - SER_BLOCKHEADERONLY = (1 << 17), + // modifiers + SER_SKIPSIG = (1 << 16), + SER_BLOCKHEADERONLY = (1 << 17) }; -#ifdef _MSC_VER #define IMPLEMENT_SERIALIZE(statements) \ unsigned int GetSerializeSize(int nType, int nVersion) const \ { \ @@ -75,7 +74,6 @@ enum assert(fGetSize||fWrite||fRead); /* suppress warning */ \ s.nType = nType; \ s.nVersion = nVersion; \ - std::map mapUnkIds; \ {statements} \ return nSerSize; \ } \ @@ -88,7 +86,6 @@ enum const bool fRead = false; \ unsigned int nSerSize = 0; \ assert(fGetSize||fWrite||fRead); /* suppress warning */ \ - std::map mapUnkIds; \ {statements} \ } \ template \ @@ -99,53 +96,10 @@ enum const bool fWrite = false; \ const bool fRead = true; \ unsigned int nSerSize = 0; \ - std::map mapUnkIds; \ assert(fGetSize||fWrite||fRead); /* suppress warning */ \ {statements} \ } -#else - -#define IMPLEMENT_SERIALIZE(statements) \ - unsigned int GetSerializeSize(int nType, int nVersion) const \ - { \ - CSerActionGetSerializeSize ser_action; \ - const bool fGetSize = true; \ - const bool fWrite = false; \ - const bool fRead = false; \ - unsigned int nSerSize = 0; \ - ser_streamplaceholder s; \ - assert(fGetSize||fWrite||fRead); /* suppress warning */ \ - s.nType = nType; \ - s.nVersion = nVersion; \ - {statements} \ - return nSerSize; \ - } \ - template \ - void Serialize(Stream& s, int nType, int nVersion) const \ - { \ - CSerActionSerialize ser_action; \ - const bool fGetSize = false; \ - const bool fWrite = true; \ - const bool fRead = false; \ - unsigned int nSerSize = 0; \ - assert(fGetSize||fWrite||fRead); /* suppress warning */ \ - {statements} \ - } \ - template \ - void Unserialize(Stream& s, int nType, int nVersion) \ - { \ - CSerActionUnserialize ser_action; \ - const bool fGetSize = false; \ - const bool fWrite = false; \ - const bool fRead = true; \ - unsigned int nSerSize = 0; \ - assert(fGetSize||fWrite||fRead); /* suppress warning */ \ - {statements} \ - } - -#endif - #define READWRITE(obj) (nSerSize += ::SerReadWrite(s, (obj), nType, nVersion, ser_action)) @@ -316,7 +270,7 @@ template inline unsigned int GetSizeOfVarInt(I n) { int nRet = 0; - while(true) { + for ( ; ; ) { nRet++; if (n <= 0x7F) break; @@ -330,7 +284,7 @@ void WriteVarInt(Stream& os, I n) { unsigned char tmp[(sizeof(n)*8+6)/7]; int len=0; - while(true) { + for ( ; ; ) { tmp[len] = (n & 0x7F) | (len ? 0x80 : 0x00); if (n <= 0x7F) break; @@ -346,7 +300,7 @@ template I ReadVarInt(Stream& is) { I n = 0; - while(true) { + for ( ; ; ) { unsigned char chData; READDATA(is, chData); n = (n << 7) | (chData & 0x7F); @@ -1106,10 +1060,7 @@ public: if (nReadPosNext >= vch.size()) { if (nReadPosNext > vch.size()) - { setstate(std::ios::failbit, "CDataStream::ignore() : end of data"); - nSize = (int)(vch.size() - nReadPos); - } nReadPos = 0; vch.clear(); return (*this); @@ -1334,7 +1285,7 @@ public: int nVersion; CBufferedFile(FILE *fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nTypeIn, int nVersionIn) : - src(fileIn), nSrcPos(0), nReadPos(0), nReadLimit((uint64_t)(-1)), nRewind(nRewindIn), vchBuf(nBufSize, 0), + src(fileIn), nSrcPos(0), nReadPos(0), nReadLimit(std::numeric_limits::max()), nRewind(nRewindIn), vchBuf(nBufSize, 0), state(0), exceptmask(std::ios_base::badbit | std::ios_base::failbit), nType(nTypeIn), nVersion(nVersionIn) { } @@ -1360,7 +1311,7 @@ public: unsigned int pos = (unsigned int)(nReadPos % vchBuf.size()); size_t nNow = nSize; if (nNow + pos > vchBuf.size()) - nNow = (size_t)(vchBuf.size() - pos); + nNow = vchBuf.size() - pos; if (nNow + nReadPos > nSrcPos) nNow = (size_t)(nSrcPos - nReadPos); memcpy(pch, &vchBuf[pos], nNow); @@ -1405,7 +1356,7 @@ public: // prevent reading beyond a certain position // no argument removes the limit - bool SetLimit(uint64_t nPos = (uint64_t)(-1)) { + bool SetLimit(uint64_t nPos = std::numeric_limits::max()) { if (nPos < nReadPos) return false; nReadLimit = nPos; @@ -1421,7 +1372,7 @@ public: // search for a given byte in the stream, and remain positioned on it void FindByte(char ch) { - while (true) { + for ( ; ; ) { if (nReadPos == nSrcPos) Fill(); if (vchBuf[nReadPos % vchBuf.size()] == ch)