More serialization rework.

This commit is contained in:
JoelKatz
2012-09-26 14:22:04 -07:00
parent ba77d3e438
commit c10ff5bac9
4 changed files with 20 additions and 20 deletions

View File

@@ -519,7 +519,7 @@ STAmount& STAmount::operator-=(const STAmount& a)
STAmount STAmount::operator-(void) const
{
if (mValue == 0) return *this;
return STAmount(fName, mCurrency, mIssuer, mValue, mOffset, mIsNative, !mIsNegative);
return STAmount(getFName(), mCurrency, mIssuer, mValue, mOffset, mIsNative, !mIsNegative);
}
STAmount& STAmount::operator=(uint64 v)
@@ -572,12 +572,12 @@ bool STAmount::operator>=(uint64 v) const
STAmount STAmount::operator+(uint64 v) const
{
return STAmount(fName, getSNValue() + static_cast<int64>(v));
return STAmount(getFName(), getSNValue() + static_cast<int64>(v));
}
STAmount STAmount::operator-(uint64 v) const
{
return STAmount(fName, getSNValue() - static_cast<int64>(v));
return STAmount(getFName(), getSNValue() - static_cast<int64>(v));
}
STAmount::operator double() const
@@ -595,7 +595,7 @@ STAmount operator+(const STAmount& v1, const STAmount& v2)
v1.throwComparable(v2);
if (v1.mIsNative)
return STAmount(v1.fName, v1.getSNValue() + v2.getSNValue());
return STAmount(v1.getFName(), v1.getSNValue() + v2.getSNValue());
int ov1 = v1.mOffset, ov2 = v2.mOffset;
@@ -617,9 +617,9 @@ STAmount operator+(const STAmount& v1, const STAmount& v2)
int64 fv = vv1 + vv2;
if (fv >= 0)
return STAmount(v1.fName, v1.mCurrency, v1.mIssuer, fv, ov1, false);
return STAmount(v1.getFName(), v1.mCurrency, v1.mIssuer, fv, ov1, false);
else
return STAmount(v1.fName, v1.mCurrency, v1.mIssuer, -fv, ov1, true);
return STAmount(v1.getFName(), v1.mCurrency, v1.mIssuer, -fv, ov1, true);
}
STAmount operator-(const STAmount& v1, const STAmount& v2)
@@ -649,9 +649,9 @@ STAmount operator-(const STAmount& v1, const STAmount& v2)
int64 fv = vv1 - vv2;
if (fv >= 0)
return STAmount(v1.fName, v1.mCurrency, v1.mIssuer, fv, ov1, false);
return STAmount(v1.getFName(), v1.mCurrency, v1.mIssuer, fv, ov1, false);
else
return STAmount(v1.fName, v1.mCurrency, v1.mIssuer, -fv, ov1, true);
return STAmount(v1.getFName(), v1.mCurrency, v1.mIssuer, -fv, ov1, true);
}
STAmount STAmount::divide(const STAmount& num, const STAmount& den, const uint160& uCurrencyID, const uint160& uIssuerID)
@@ -703,7 +703,7 @@ STAmount STAmount::multiply(const STAmount& v1, const STAmount& v2, const uint16
return STAmount(uCurrencyID, uIssuerID);
if (v1.mIsNative && v2.mIsNative) // FIXME: overflow
return STAmount(v1.fName, v1.getSNValue() * v2.getSNValue());
return STAmount(v1.getFName(), v1.getSNValue() * v2.getSNValue());
uint64 value1 = v1.mValue, value2 = v2.mValue;
int offset1 = v1.mOffset, offset2 = v2.mOffset;

View File

@@ -15,7 +15,7 @@ SField sfInvalid(-1), sfGeneric(0);
#undef FIELD
#undef TYPE
std::map<int, SField*> SField::codeToField;
std::map<int, SField::ptr> SField::codeToField;
boost::mutex SField::mapMutex;
SField::ref SField::getField(int code)
@@ -28,15 +28,15 @@ SField::ref SField::getField(int code)
boost::mutex::scoped_lock sl(mapMutex);
std::map<int, SField*> it = codeToField.find(code);
std::map<int, SField::ptr>::iterator it = codeToField.find(code);
if (it != codeToField.end())
return *(it->second);
switch(type)
switch (type)
{ // types we are willing to dynamically extend
#define FIELD(name, type, index) case sf##name:
#define TYPE(name, type, index)
#define FIELD(name, type, index)
#define TYPE(name, type, index) case STI_##type:
#include "SerializeProto.h"
#undef FIELD
#undef TYPE
@@ -68,7 +68,7 @@ SField::ref SField::getField(int type, int value)
return getField(FIELD_CODE(type, value));
}
std::string SField::getName() cosnt
std::string SField::getName() const
{
if (fieldName != NULL)
return fieldName;

View File

@@ -40,8 +40,8 @@ public:
typedef SField const * ptr;
protected:
static std::map<int, SField*> codeToField;
static boost::mutex mapMutex;
static std::map<int, ptr> codeToField;
static boost::mutex mapMutex;
public:

View File

@@ -218,11 +218,11 @@ protected:
STAmount(bool isNeg, uint64 value) : mValue(value), mOffset(0), mIsNative(true), mIsNegative(isNeg) { ; }
STAmount(SField *name, uint64 value, bool isNegative)
STAmount(SField::ref name, uint64 value, bool isNegative)
: SerializedType(fName), mValue(value), mOffset(0), mIsNative(true), mIsNegative(isNegative)
{ ; }
STAmount(SField *n, const uint160& cur, const uint160& iss, uint64 val, int off, bool isNat, bool isNeg)
: SerializedType(n), mCurrency(cur), mIssuer(iss), mValue(val), mOffset(off),
STAmount(SField::ref name, const uint160& cur, const uint160& iss, uint64 val, int off, bool isNat, bool isNeg)
: SerializedType(name), mCurrency(cur), mIssuer(iss), mValue(val), mOffset(off),
mIsNative(isNat), mIsNegative(isNeg) { ; }
uint64 toUInt64() const;