Use the variable name _ for unused return values
[bitcoinplatinum.git] / src / uint256.cpp
blobc4c7b716fea38e9ba09e156581665c13d20a69cf
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #include "uint256.h"
8 #include "utilstrencodings.h"
10 #include <stdio.h>
11 #include <string.h>
13 template <unsigned int BITS>
14 base_blob<BITS>::base_blob(const std::vector<unsigned char>& vch)
16 assert(vch.size() == sizeof(data));
17 memcpy(data, &vch[0], sizeof(data));
20 template <unsigned int BITS>
21 std::string base_blob<BITS>::GetHex() const
23 return HexStr(std::reverse_iterator<const uint8_t*>(data + sizeof(data)), std::reverse_iterator<const uint8_t*>(data));
26 template <unsigned int BITS>
27 void base_blob<BITS>::SetHex(const char* psz)
29 memset(data, 0, sizeof(data));
31 // skip leading spaces
32 while (isspace(*psz))
33 psz++;
35 // skip 0x
36 if (psz[0] == '0' && tolower(psz[1]) == 'x')
37 psz += 2;
39 // hex string to uint
40 const char* pbegin = psz;
41 while (::HexDigit(*psz) != -1)
42 psz++;
43 psz--;
44 unsigned char* p1 = (unsigned char*)data;
45 unsigned char* pend = p1 + WIDTH;
46 while (psz >= pbegin && p1 < pend) {
47 *p1 = ::HexDigit(*psz--);
48 if (psz >= pbegin) {
49 *p1 |= ((unsigned char)::HexDigit(*psz--) << 4);
50 p1++;
55 template <unsigned int BITS>
56 void base_blob<BITS>::SetHex(const std::string& str)
58 SetHex(str.c_str());
61 template <unsigned int BITS>
62 std::string base_blob<BITS>::ToString() const
64 return (GetHex());
67 // Explicit instantiations for base_blob<160>
68 template base_blob<160>::base_blob(const std::vector<unsigned char>&);
69 template std::string base_blob<160>::GetHex() const;
70 template std::string base_blob<160>::ToString() const;
71 template void base_blob<160>::SetHex(const char*);
72 template void base_blob<160>::SetHex(const std::string&);
74 // Explicit instantiations for base_blob<256>
75 template base_blob<256>::base_blob(const std::vector<unsigned char>&);
76 template std::string base_blob<256>::GetHex() const;
77 template std::string base_blob<256>::ToString() const;
78 template void base_blob<256>::SetHex(const char*);
79 template void base_blob<256>::SetHex(const std::string&);