Merge branch 'master' of github.com:jedmccaleb/NewCoin

This commit is contained in:
Arthur Britto
2013-03-02 23:58:03 -08:00
5 changed files with 25 additions and 6 deletions

View File

@@ -12,6 +12,7 @@
// These must stay at the top of this file
std::map<int, SField::ptr> SField::codeToField;
boost::mutex SField::mapMutex;
int SField::num = 0;
SField sfInvalid(-1), sfGeneric(0);
SField sfLedgerEntry(STI_LEDGERENTRY, 1, "LedgerEntry");

View File

@@ -51,6 +51,7 @@ public:
protected:
static std::map<int, ptr> codeToField;
static boost::mutex mapMutex;
static int num;
SField(SerializedTypeID id, int val);
@@ -61,6 +62,7 @@ public:
const int fieldValue; // Code number for protocol
std::string fieldName;
int fieldMeta;
int fieldNum;
bool signingField;
SField(int fc, SerializedTypeID tid, int fv, const char* fn) :
@@ -68,6 +70,7 @@ public:
{
boost::mutex::scoped_lock sl(mapMutex);
codeToField[fieldCode] = this;
fieldNum = ++num;
}
SField(SerializedTypeID tid, int fv, const char *fn) :
@@ -76,9 +79,14 @@ public:
{
boost::mutex::scoped_lock sl(mapMutex);
codeToField[fieldCode] = this;
fieldNum = ++num;
}
SField(int fc) : fieldCode(fc), fieldType(STI_UNKNOWN), fieldValue(0), fieldMeta(sMD_Never) { ; }
SField(int fc) : fieldCode(fc), fieldType(STI_UNKNOWN), fieldValue(0), fieldMeta(sMD_Never)
{
boost::mutex::scoped_lock sl(mapMutex);
fieldNum = ++num;
}
~SField();
@@ -97,6 +105,8 @@ public:
bool isBinary() const { return fieldValue < 256; }
bool isDiscardable() const { return fieldValue > 256; }
int getCode() const { return fieldCode; }
int getNum() const { return fieldNum; }
static int getNumFields() { return num; }
bool isSigningField() const { return signingField; }
void notSigningField() { signingField = false; }

View File

@@ -50,6 +50,11 @@ public:
sMultiThreaded = true;
}
static bool isMultiThread()
{
return sMultiThreaded;
}
void addInstance()
{
if (sMultiThreaded)

View File

@@ -132,15 +132,18 @@ std::auto_ptr<SerializedType> STObject::makeDeserializedObject(SerializedTypeID
void SOTemplate::push_back(const SOElement &r)
{
assert(mMap.find(r.e_field.getCode()) == mMap.end());
mMap[r.e_field.getCode()] = mTypes.size();
if (mIndex.empty())
mIndex.resize(SField::getNumFields() + 1, -1);
assert(r.e_field.getNum() < mIndex.size());
assert(getIndex(r.e_field) == -1);
mIndex[r.e_field.getNum()] = mTypes.size();
mTypes.push_back(new SOElement(r));
}
int SOTemplate::getIndex(SField::ref f) const
{
std::map<int, int>::const_iterator it = mMap.find(f.getCode());
return (it == mMap.end()) ? -1 : it->second;
assert(f.getNum() < mIndex.size());
return mIndex[f.getNum()];
}
void STObject::set(const SOTemplate& type)

View File

@@ -28,7 +28,7 @@ class SOTemplate
{
protected:
std::vector<const SOElement*> mTypes;
std::map<int, int> mMap; // field code -> index
std::vector<int> mIndex; // field num -> index
public:
SOTemplate() { ; }