From 84d7c981dc52cc738053f9ec48648ab6fbf9311b Mon Sep 17 00:00:00 2001 From: s_nakamoto Date: Sat, 27 Nov 2010 23:12:41 +0000 Subject: [PATCH] added boost tuples to serialize.h git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@192 1a98c847-1fd6-4fd8-948a-caf3550aa51b --- db.cpp | 4 +-- serialize.h | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 81 insertions(+), 3 deletions(-) diff --git a/db.cpp b/db.cpp index c768778c5f..2833a8be91 100644 --- a/db.cpp +++ b/db.cpp @@ -592,7 +592,7 @@ bool CWalletDB::WriteAccount(const string& strAccount, const CAccount& account) bool CWalletDB::WriteAccountingEntry(const string& strAccount, const CAccountingEntry& acentry) { - return Write(make_pair(string("acentry"), make_pair(strAccount, ++nAccountingEntryNumber)), acentry); + return Write(make_tuple(string("acentry"), strAccount, ++nAccountingEntryNumber), acentry); } int64 CWalletDB::GetAccountCreditDebit(const string& strAccount) @@ -608,7 +608,7 @@ int64 CWalletDB::GetAccountCreditDebit(const string& strAccount) // Read next record CDataStream ssKey; if (fFlags == DB_SET_RANGE) - ssKey << make_pair(string("acentry"), make_pair(strAccount, uint64(0))); + ssKey << make_tuple(string("acentry"), strAccount, uint64(0)); CDataStream ssValue; int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags); fFlags = DB_NEXT; diff --git a/serialize.h b/serialize.h index 5bf2fb63d0..3debdf08e1 100644 --- a/serialize.h +++ b/serialize.h @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include #if defined(_MSC_VER) || defined(__BORLANDC__) typedef __int64 int64; typedef unsigned __int64 uint64; @@ -22,7 +25,7 @@ class CDataStream; class CAutoFile; static const unsigned int MAX_SIZE = 0x02000000; -static const int VERSION = 31700; +static const int VERSION = 31701; static const char* pszSubVer = ""; @@ -338,6 +341,16 @@ template unsigned int GetSerializeSize(const std::pair void Serialize(Stream& os, const std::pair& item, int nType, int nVersion=VERSION); template void Unserialize(Stream& is, std::pair& item, int nType, int nVersion=VERSION); +// 3 tuple +template unsigned int GetSerializeSize(const boost::tuple& item, int nType, int nVersion=VERSION); +template void Serialize(Stream& os, const boost::tuple& item, int nType, int nVersion=VERSION); +template void Unserialize(Stream& is, boost::tuple& item, int nType, int nVersion=VERSION); + +// 4 tuple +template unsigned int GetSerializeSize(const boost::tuple& item, int nType, int nVersion=VERSION); +template void Serialize(Stream& os, const boost::tuple& item, int nType, int nVersion=VERSION); +template void Unserialize(Stream& is, boost::tuple& item, int nType, int nVersion=VERSION); + // map template unsigned int GetSerializeSize(const std::map& m, int nType, int nVersion=VERSION); template void Serialize(Stream& os, const std::map& m, int nType, int nVersion=VERSION); @@ -554,6 +567,71 @@ void Unserialize(Stream& is, std::pair& item, int nType, int nVersion) +// +// 3 tuple +// +template +unsigned int GetSerializeSize(const boost::tuple& item, int nType, int nVersion) +{ + unsigned int nSize = 0; + nSize += GetSerializeSize(get<0>(item), nType, nVersion); + nSize += GetSerializeSize(get<1>(item), nType, nVersion); + nSize += GetSerializeSize(get<2>(item), nType, nVersion); + return nSize; +} + +template +void Serialize(Stream& os, const boost::tuple& item, int nType, int nVersion) +{ + Serialize(os, get<0>(item), nType, nVersion); + Serialize(os, get<1>(item), nType, nVersion); + Serialize(os, get<2>(item), nType, nVersion); +} + +template +void Unserialize(Stream& is, boost::tuple& item, int nType, int nVersion) +{ + Unserialize(is, get<0>(item), nType, nVersion); + Unserialize(is, get<1>(item), nType, nVersion); + Unserialize(is, get<2>(item), nType, nVersion); +} + + + +// +// 4 tuple +// +template +unsigned int GetSerializeSize(const boost::tuple& item, int nType, int nVersion) +{ + unsigned int nSize = 0; + nSize += GetSerializeSize(get<0>(item), nType, nVersion); + nSize += GetSerializeSize(get<1>(item), nType, nVersion); + nSize += GetSerializeSize(get<2>(item), nType, nVersion); + nSize += GetSerializeSize(get<3>(item), nType, nVersion); + return nSize; +} + +template +void Serialize(Stream& os, const boost::tuple& item, int nType, int nVersion) +{ + Serialize(os, get<0>(item), nType, nVersion); + Serialize(os, get<1>(item), nType, nVersion); + Serialize(os, get<2>(item), nType, nVersion); + Serialize(os, get<3>(item), nType, nVersion); +} + +template +void Unserialize(Stream& is, boost::tuple& item, int nType, int nVersion) +{ + Unserialize(is, get<0>(item), nType, nVersion); + Unserialize(is, get<1>(item), nType, nVersion); + Unserialize(is, get<2>(item), nType, nVersion); + Unserialize(is, get<3>(item), nType, nVersion); +} + + + // // map //