From c10ff5bac9b67ddf5549fce7e1a31c93b7454877 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 26 Sep 2012 14:22:04 -0700 Subject: [PATCH] More serialization rework. --- src/Amount.cpp | 18 +++++++++--------- src/FieldNames.cpp | 12 ++++++------ src/FieldNames.h | 4 ++-- src/SerializedTypes.h | 6 +++--- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Amount.cpp b/src/Amount.cpp index 7af2d28e71..9b45507502 100644 --- a/src/Amount.cpp +++ b/src/Amount.cpp @@ -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(v)); + return STAmount(getFName(), getSNValue() + static_cast(v)); } STAmount STAmount::operator-(uint64 v) const { - return STAmount(fName, getSNValue() - static_cast(v)); + return STAmount(getFName(), getSNValue() - static_cast(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; diff --git a/src/FieldNames.cpp b/src/FieldNames.cpp index 483694c2d2..316410ffb6 100644 --- a/src/FieldNames.cpp +++ b/src/FieldNames.cpp @@ -15,7 +15,7 @@ SField sfInvalid(-1), sfGeneric(0); #undef FIELD #undef TYPE -std::map SField::codeToField; +std::map 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 it = codeToField.find(code); + std::map::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; diff --git a/src/FieldNames.h b/src/FieldNames.h index cd035f1330..cfcb649f06 100644 --- a/src/FieldNames.h +++ b/src/FieldNames.h @@ -40,8 +40,8 @@ public: typedef SField const * ptr; protected: - static std::map codeToField; - static boost::mutex mapMutex; + static std::map codeToField; + static boost::mutex mapMutex; public: diff --git a/src/SerializedTypes.h b/src/SerializedTypes.h index 64dae0d73b..5df8b6fada 100644 --- a/src/SerializedTypes.h +++ b/src/SerializedTypes.h @@ -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;