Fix base_uint ctor to disambiguate void const*

This commit is contained in:
Vinnie Falco
2013-07-25 11:43:24 -07:00
parent 492e61649b
commit 8b342d9859
6 changed files with 21 additions and 7 deletions

View File

@@ -14,6 +14,9 @@ Vinnie's Short List (Changes day to day)
--------------------------------------------------------------------------------
- Use static creation member functions instead of endless constructor
variations in base_uint, uint256, and family.
- Take away the "I" prefix from abstract interface classes, in both the class
name and the file name. It is messing up sorting in the IDE. Use "Imp" or
suffix for implementations.

View File

@@ -176,7 +176,7 @@ public:
else
{
// Uh oh, corrupted data!
WriteLog (lsFATAL, NodeObject) << "Corrupt NodeObject #" << uint256 (it->key ().data ());
WriteLog (lsFATAL, NodeObject) << "Corrupt NodeObject #" << uint256::fromVoid (it->key ().data ());
}
}
else

View File

@@ -28,7 +28,7 @@ public:
Status fetch (void const* key, NodeObject::Ptr* pObject)
{
uint256 const hash (key);
uint256 const hash (uint256::fromVoid (key));
Map::iterator iter = m_map.find (hash);

View File

@@ -71,7 +71,7 @@ NodeObject::Ptr NodeStore::DecodedBlob::createObject ()
memcpy (data.data (), m_objectData, m_dataBytes);
object = NodeObject::createObject (
m_objectType, m_ledgerIndex, data, uint256 (m_key));
m_objectType, m_ledgerIndex, data, uint256::fromVoid (m_key));
}
return object;

View File

@@ -66,7 +66,7 @@ public:
{
ScopedLock sl (m_db->getDBLock());
uint256 const hash (key);
uint256 const hash (uint256::fromVoid (key));
static SqliteStatement pSt (m_db->getDB()->getSqliteDB(),
"SELECT ObjType,LedgerIndex,Object FROM CommittedObjects WHERE Hash = ?;");

View File

@@ -38,17 +38,22 @@ public:
{
}
protected:
// This is to disambiguate from other 1 parameter ctors
struct FromVoid { };
/** Construct from a raw pointer.
The buffer pointed to by `data` must be at least 32 bytes.
*/
explicit base_uint (void const* data)
base_uint (void const* data, FromVoid)
{
// BITS must be a multiple of 32
static_bassert ((BITS % 32) == 0);
memcpy (&pn [0], data, BITS / 8);
}
public:
bool isZero () const
{
@@ -504,10 +509,16 @@ public:
*this = b;
}
explicit uint256 (void const* data)
: base_uint256 (data)
private:
uint256 (void const* data, FromVoid)
: base_uint256 (data, FromVoid ())
{
}
public:
static uint256 fromVoid (void const* data)
{
return uint256 (data, FromVoid ());
}
uint256& operator= (uint64 uHost)
{