diff options
author | Kamil Domanski <kdomanski@kdemail.net> | 2014-08-20 22:44:38 +0200 |
---|---|---|
committer | Kamil Domanski <kdomanski@kdemail.net> | 2014-08-31 02:16:17 +0200 |
commit | 84881f8c472cc67dc757686eb7dc3b495b13cab8 (patch) | |
tree | 9aa2ae012cc4817464cb60e9d838fa92464a9477 /src/main.h | |
parent | 5d96b4ae0188fcad36105642c5d69249d37fdbb5 (diff) |
rework overhauled serialization methods to non-static
Thanks to Pieter Wuille for most of the work on this commit.
I did not fixup the overhaul commit, because a rebase conflicted
with "remove fields of ser_streamplaceholder".
I prefer not to risk making a mistake while resolving it.
Diffstat (limited to 'src/main.h')
-rw-r--r-- | src/main.h | 112 |
1 files changed, 56 insertions, 56 deletions
diff --git a/src/main.h b/src/main.h index 88e3159e3f..8a5fa0e7e0 100644 --- a/src/main.h +++ b/src/main.h @@ -197,13 +197,13 @@ struct CDiskBlockPos int nFile; unsigned int nPos; - IMPLEMENT_SERIALIZE + IMPLEMENT_SERIALIZE; - template <typename T, typename Stream, typename Operation> - inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { + template <typename Stream, typename Operation> + inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { size_t nSerSize = 0; - READWRITE(VARINT(thisPtr->nFile)); - READWRITE(VARINT(thisPtr->nPos)); + READWRITE(VARINT(nFile)); + READWRITE(VARINT(nPos)); return nSerSize; } @@ -232,13 +232,13 @@ struct CDiskTxPos : public CDiskBlockPos { unsigned int nTxOffset; // after header - IMPLEMENT_SERIALIZE + IMPLEMENT_SERIALIZE; - template <typename T, typename Stream, typename Operation> - inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { + template <typename Stream, typename Operation> + inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { size_t nSerSize = 0; - READWRITE(*(CDiskBlockPos*)thisPtr); - READWRITE(VARINT(thisPtr->nTxOffset)); + READWRITE(*(CDiskBlockPos*)this); + READWRITE(VARINT(nTxOffset)); return nSerSize; } @@ -317,12 +317,12 @@ class CBlockUndo public: std::vector<CTxUndo> vtxundo; // for all but the coinbase - IMPLEMENT_SERIALIZE + IMPLEMENT_SERIALIZE; - template <typename T, typename Stream, typename Operation> - inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { + template <typename Stream, typename Operation> + inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { size_t nSerSize = 0; - READWRITE(thisPtr->vtxundo); + READWRITE(vtxundo); return nSerSize; } @@ -426,27 +426,27 @@ protected: public: // serialization implementation - IMPLEMENT_SERIALIZE + IMPLEMENT_SERIALIZE; - template <typename T, typename Stream, typename Operation> - inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { + template <typename Stream, typename Operation> + inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { size_t nSerSize = 0; bool fRead = boost::is_same<Operation, CSerActionUnserialize>(); - READWRITE(thisPtr->nTransactions); - READWRITE(thisPtr->vHash); + READWRITE(nTransactions); + READWRITE(vHash); std::vector<unsigned char> vBytes; if (fRead) { READWRITE(vBytes); - CPartialMerkleTree &us = *(const_cast<CPartialMerkleTree*>(thisPtr)); + CPartialMerkleTree &us = *(const_cast<CPartialMerkleTree*>(this)); us.vBits.resize(vBytes.size() * 8); for (unsigned int p = 0; p < us.vBits.size(); p++) us.vBits[p] = (vBytes[p / 8] & (1 << (p % 8))) != 0; us.fBad = false; } else { - vBytes.resize((thisPtr->vBits.size()+7)/8); - for (unsigned int p = 0; p < thisPtr->vBits.size(); p++) - vBytes[p / 8] |= thisPtr->vBits[p] << (p % 8); + vBytes.resize((vBits.size()+7)/8); + for (unsigned int p = 0; p < vBits.size(); p++) + vBytes[p / 8] |= vBits[p] << (p % 8); READWRITE(vBytes); } @@ -507,19 +507,19 @@ public: uint64_t nTimeFirst; // earliest time of block in file uint64_t nTimeLast; // latest time of block in file - IMPLEMENT_SERIALIZE + IMPLEMENT_SERIALIZE; - template <typename T, typename Stream, typename Operation> - inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { + template <typename Stream, typename Operation> + inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { size_t nSerSize = 0; - READWRITE(VARINT(thisPtr->nBlocks)); - READWRITE(VARINT(thisPtr->nSize)); - READWRITE(VARINT(thisPtr->nUndoSize)); - READWRITE(VARINT(thisPtr->nHeightFirst)); - READWRITE(VARINT(thisPtr->nHeightLast)); - READWRITE(VARINT(thisPtr->nTimeFirst)); - READWRITE(VARINT(thisPtr->nTimeLast)); + READWRITE(VARINT(nBlocks)); + READWRITE(VARINT(nSize)); + READWRITE(VARINT(nUndoSize)); + READWRITE(VARINT(nHeightFirst)); + READWRITE(VARINT(nHeightLast)); + READWRITE(VARINT(nTimeFirst)); + READWRITE(VARINT(nTimeLast)); return nSerSize; } @@ -785,32 +785,32 @@ public: hashPrev = (pprev ? pprev->GetBlockHash() : 0); } - IMPLEMENT_SERIALIZE + IMPLEMENT_SERIALIZE; - template <typename T, typename Stream, typename Operation> - inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { + template <typename Stream, typename Operation> + inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { size_t nSerSize = 0; if (!(nType & SER_GETHASH)) READWRITE(VARINT(nVersion)); - READWRITE(VARINT(thisPtr->nHeight)); - READWRITE(VARINT(thisPtr->nStatus)); - READWRITE(VARINT(thisPtr->nTx)); - if (thisPtr->nStatus & (BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO)) - READWRITE(VARINT(thisPtr->nFile)); - if (thisPtr->nStatus & BLOCK_HAVE_DATA) - READWRITE(VARINT(thisPtr->nDataPos)); - if (thisPtr->nStatus & BLOCK_HAVE_UNDO) - READWRITE(VARINT(thisPtr->nUndoPos)); + READWRITE(VARINT(nHeight)); + READWRITE(VARINT(nStatus)); + READWRITE(VARINT(nTx)); + if (nStatus & (BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO)) + READWRITE(VARINT(nFile)); + if (nStatus & BLOCK_HAVE_DATA) + READWRITE(VARINT(nDataPos)); + if (nStatus & BLOCK_HAVE_UNDO) + READWRITE(VARINT(nUndoPos)); // block header - READWRITE(thisPtr->nVersion); - READWRITE(thisPtr->hashPrev); - READWRITE(thisPtr->hashMerkleRoot); - READWRITE(thisPtr->nTime); - READWRITE(thisPtr->nBits); - READWRITE(thisPtr->nNonce); + READWRITE(this->nVersion); + READWRITE(hashPrev); + READWRITE(hashMerkleRoot); + READWRITE(nTime); + READWRITE(nBits); + READWRITE(nNonce); return nSerSize; } @@ -1011,13 +1011,13 @@ public: // thus the filter will likely be modified. CMerkleBlock(const CBlock& block, CBloomFilter& filter); - IMPLEMENT_SERIALIZE + IMPLEMENT_SERIALIZE; - template <typename T, typename Stream, typename Operation> - inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { + template <typename Stream, typename Operation> + inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { size_t nSerSize = 0; - READWRITE(thisPtr->header); - READWRITE(thisPtr->txn); + READWRITE(header); + READWRITE(txn); return nSerSize; } }; |