X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fserialize.h;h=3fa3ddf3eb42f4d62913af97470c5aab334f1a53;hb=77a43545b4491b9703d803765da9059d2bdd5aaa;hp=7feb976ec8ef2a2401ff48b3744c29285b1dfe38;hpb=18770118e846622f59a86f9937a33da0bb761775;p=novacoin.git diff --git a/src/serialize.h b/src/serialize.h index 7feb976..3fa3ddf 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -14,10 +14,12 @@ #include #include +#ifndef Q_MOC_RUN #include #include #include #include +#endif #include "allocators.h" #include "version.h" @@ -26,8 +28,7 @@ #undef max #endif -typedef long long int64; -typedef unsigned long long uint64; +#include class CScript; class CDataStream; @@ -165,10 +166,10 @@ inline unsigned int GetSerializeSize(signed short a, int, int=0) { return size inline unsigned int GetSerializeSize(unsigned short a, int, int=0) { return sizeof(a); } inline unsigned int GetSerializeSize(signed int a, int, int=0) { return sizeof(a); } inline unsigned int GetSerializeSize(unsigned int a, int, int=0) { return sizeof(a); } -inline unsigned int GetSerializeSize(signed long a, int, int=0) { return sizeof(a); } -inline unsigned int GetSerializeSize(unsigned long a, int, int=0) { return sizeof(a); } -inline unsigned int GetSerializeSize(int64 a, int, int=0) { return sizeof(a); } -inline unsigned int GetSerializeSize(uint64 a, int, int=0) { return sizeof(a); } +//inline unsigned int GetSerializeSize(signed long a, int, int=0) { return sizeof(a); } +//inline unsigned int GetSerializeSize(unsigned long a, int, int=0) { return sizeof(a); } +inline unsigned int GetSerializeSize(int64_t a, int, int=0) { return sizeof(a); } +inline unsigned int GetSerializeSize(uint64_t a, int, int=0) { return sizeof(a); } inline unsigned int GetSerializeSize(float a, int, int=0) { return sizeof(a); } inline unsigned int GetSerializeSize(double a, int, int=0) { return sizeof(a); } @@ -179,10 +180,10 @@ template inline void Serialize(Stream& s, signed short a, int template inline void Serialize(Stream& s, unsigned short a, int, int=0) { WRITEDATA(s, a); } template inline void Serialize(Stream& s, signed int a, int, int=0) { WRITEDATA(s, a); } template inline void Serialize(Stream& s, unsigned int a, int, int=0) { WRITEDATA(s, a); } -template inline void Serialize(Stream& s, signed long a, int, int=0) { WRITEDATA(s, a); } -template inline void Serialize(Stream& s, unsigned long a, int, int=0) { WRITEDATA(s, a); } -template inline void Serialize(Stream& s, int64 a, int, int=0) { WRITEDATA(s, a); } -template inline void Serialize(Stream& s, uint64 a, int, int=0) { WRITEDATA(s, a); } +//template inline void Serialize(Stream& s, signed long a, int, int=0) { WRITEDATA(s, a); } +//template inline void Serialize(Stream& s, unsigned long a, int, int=0) { WRITEDATA(s, a); } +template inline void Serialize(Stream& s, int64_t a, int, int=0) { WRITEDATA(s, a); } +template inline void Serialize(Stream& s, uint64_t a, int, int=0) { WRITEDATA(s, a); } template inline void Serialize(Stream& s, float a, int, int=0) { WRITEDATA(s, a); } template inline void Serialize(Stream& s, double a, int, int=0) { WRITEDATA(s, a); } @@ -193,10 +194,10 @@ template inline void Unserialize(Stream& s, signed short& a, template inline void Unserialize(Stream& s, unsigned short& a, int, int=0) { READDATA(s, a); } template inline void Unserialize(Stream& s, signed int& a, int, int=0) { READDATA(s, a); } template inline void Unserialize(Stream& s, unsigned int& a, int, int=0) { READDATA(s, a); } -template inline void Unserialize(Stream& s, signed long& a, int, int=0) { READDATA(s, a); } -template inline void Unserialize(Stream& s, unsigned long& a, int, int=0) { READDATA(s, a); } -template inline void Unserialize(Stream& s, int64& a, int, int=0) { READDATA(s, a); } -template inline void Unserialize(Stream& s, uint64& a, int, int=0) { READDATA(s, a); } +//template inline void Unserialize(Stream& s, signed long& a, int, int=0) { READDATA(s, a); } +//template inline void Unserialize(Stream& s, unsigned long& a, int, int=0) { READDATA(s, a); } +template inline void Unserialize(Stream& s, int64_t& a, int, int=0) { READDATA(s, a); } +template inline void Unserialize(Stream& s, uint64_t& a, int, int=0) { READDATA(s, a); } template inline void Unserialize(Stream& s, float& a, int, int=0) { READDATA(s, a); } template inline void Unserialize(Stream& s, double& a, int, int=0) { READDATA(s, a); } @@ -216,16 +217,16 @@ template inline void Unserialize(Stream& s, bool& a, int, int=0 // size <= UINT_MAX -- 5 bytes (254 + 4 bytes) // size > UINT_MAX -- 9 bytes (255 + 8 bytes) // -inline unsigned int GetSizeOfCompactSize(uint64 nSize) +inline unsigned int GetSizeOfCompactSize(uint64_t nSize) { if (nSize < 253) return sizeof(unsigned char); else if (nSize <= std::numeric_limits::max()) return sizeof(unsigned char) + sizeof(unsigned short); else if (nSize <= std::numeric_limits::max()) return sizeof(unsigned char) + sizeof(unsigned int); - else return sizeof(unsigned char) + sizeof(uint64); + else return sizeof(unsigned char) + sizeof(uint64_t); } template -void WriteCompactSize(Stream& os, uint64 nSize) +void WriteCompactSize(Stream& os, uint64_t nSize) { if (nSize < 253) { @@ -249,7 +250,7 @@ void WriteCompactSize(Stream& os, uint64 nSize) else { unsigned char chSize = 255; - uint64 xSize = nSize; + uint64_t xSize = nSize; WRITEDATA(os, chSize); WRITEDATA(os, xSize); } @@ -257,11 +258,11 @@ void WriteCompactSize(Stream& os, uint64 nSize) } template -uint64 ReadCompactSize(Stream& is) +uint64_t ReadCompactSize(Stream& is) { unsigned char chSize; READDATA(is, chSize); - uint64 nSizeRet = 0; + uint64_t nSizeRet = 0; if (chSize < 253) { nSizeRet = chSize; @@ -280,11 +281,11 @@ uint64 ReadCompactSize(Stream& is) } else { - uint64 xSize; + uint64_t xSize; READDATA(is, xSize); nSizeRet = xSize; } - if (nSizeRet > (uint64)MAX_SIZE) + if (nSizeRet > (uint64_t)MAX_SIZE) throw std::ios_base::failure("ReadCompactSize() : size too large"); return nSizeRet; } @@ -950,6 +951,7 @@ public: iterator insert(iterator it, const char& x=char()) { return vch.insert(it, x); } void insert(iterator it, size_type n, const char& x) { vch.insert(it, n, x); } +#ifdef _MSC_VER void insert(iterator it, const_iterator first, const_iterator last) { assert(last - first >= 0); @@ -962,6 +964,7 @@ public: else vch.insert(it, first, last); } +#endif #ifndef _MSC_VER void insert(iterator it, std::vector::const_iterator first, std::vector::const_iterator last) @@ -1291,10 +1294,10 @@ class CBufferedFile { private: FILE *src; // source file - uint64 nSrcPos; // how many bytes have been read from source - uint64 nReadPos; // how many bytes have been read from this - uint64 nReadLimit; // up to which position we're allowed to read - uint64 nRewind; // how many bytes we guarantee to rewind + uint64_t nSrcPos; // how many bytes have been read from source + uint64_t nReadPos; // how many bytes have been read from this + uint64_t nReadLimit; // up to which position we're allowed to read + uint64_t nRewind; // how many bytes we guarantee to rewind std::vector vchBuf; // the buffer short state; @@ -1330,8 +1333,8 @@ public: int nType; int nVersion; - CBufferedFile(FILE *fileIn, uint64 nBufSize, uint64 nRewindIn, int nTypeIn, int nVersionIn) : - src(fileIn), nSrcPos(0), nReadPos(0), nReadLimit((uint64)(-1)), nRewind(nRewindIn), vchBuf(nBufSize, 0), + 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), state(0), exceptmask(std::ios_base::badbit | std::ios_base::failbit), nType(nTypeIn), nVersion(nVersionIn) { } @@ -1369,12 +1372,12 @@ public: } // return the current reading position - uint64 GetPos() { + uint64_t GetPos() { return nReadPos; } // rewind to a given reading position - bool SetPos(uint64 nPos) { + bool SetPos(uint64_t nPos) { nReadPos = nPos; if (nReadPos + nRewind < nSrcPos) { nReadPos = nSrcPos - nRewind; @@ -1387,9 +1390,9 @@ public: } } - bool Seek(uint64 nPos) { + bool Seek(uint64_t nPos) { long nLongPos = nPos; - if (nPos != (uint64)nLongPos) + if (nPos != (uint64_t)nLongPos) return false; if (fseek(src, nLongPos, SEEK_SET)) return false; @@ -1402,7 +1405,7 @@ public: // prevent reading beyond a certain position // no argument removes the limit - bool SetLimit(uint64 nPos = (uint64)(-1)) { + bool SetLimit(uint64_t nPos = (uint64_t)(-1)) { if (nPos < nReadPos) return false; nReadLimit = nPos;