X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fuint256.h;h=6215b9630e900ddd411231f315d22ff905009792;hb=66116c3847eeb3f0619bc084d96f5add41a156c8;hp=bbdba995334fa4bdd6fdf4cedc04c8f58a4a447e;hpb=774e9b6dbb2c967ec979351cc4dba82fc0102ee1;p=novacoin.git diff --git a/src/uint256.h b/src/uint256.h index bbdba99..6215b96 100644 --- a/src/uint256.h +++ b/src/uint256.h @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2011 The Bitcoin developers +// Copyright (c) 2009-2012 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file license.txt or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_UINT256_H @@ -8,27 +8,21 @@ #include "serialize.h" #include +#include #include #include -#if defined(_MSC_VER) || defined(__BORLANDC__) -typedef __int64 int64; -typedef unsigned __int64 uint64; -#else typedef long long int64; typedef unsigned long long uint64; -#endif -#if defined(_MSC_VER) && _MSC_VER < 1300 -#define for if (false) ; else for -#endif inline int Testuint256AdHoc(std::vector vArg); -// We have to keep a separate base class without constructors -// so the compiler will let us use it in a union +/** Base class without constructors for uint256 and uint160. + * This makes the compiler let u use it in a union. + */ template class base_uint { @@ -313,7 +307,7 @@ public: psz += 2; // hex string to uint - static char phexdigit[256] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0 }; + static unsigned char phexdigit[256] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0 }; const char* pbegin = psz; while (phexdigit[(unsigned char)*psz] || *psz == '0') psz++; @@ -356,20 +350,24 @@ public: return sizeof(pn); } + uint64 Get64(int n=0) const + { + return pn[2*n] | (uint64)pn[2*n+1] << 32; + } - unsigned int GetSerializeSize(int nType=0, int nVersion=VERSION) const + unsigned int GetSerializeSize(int nType=0, int nVersion=PROTOCOL_VERSION) const { return sizeof(pn); } template - void Serialize(Stream& s, int nType=0, int nVersion=VERSION) const + void Serialize(Stream& s, int nType=0, int nVersion=PROTOCOL_VERSION) const { s.write((char*)pn, sizeof(pn)); } template - void Unserialize(Stream& s, int nType=0, int nVersion=VERSION) + void Unserialize(Stream& s, int nType=0, int nVersion=PROTOCOL_VERSION) { s.read((char*)pn, sizeof(pn)); } @@ -397,6 +395,7 @@ typedef base_uint<256> base_uint256; // uint160 // +/** 160-bit unsigned integer */ class uint160 : public base_uint160 { public: @@ -511,6 +510,7 @@ inline const uint160 operator-(const uint160& a, const uint160& b) { return // uint256 // +/** 256-bit unsigned integer */ class uint256 : public base_uint256 { public: @@ -624,7 +624,7 @@ inline const uint256 operator-(const uint256& a, const uint256& b) { return - +#ifdef TEST_UINT256 inline int Testuint256AdHoc(std::vector vArg) { @@ -757,3 +757,5 @@ inline int Testuint256AdHoc(std::vector vArg) } #endif + +#endif