diff --git a/src/FieldNames.cpp b/src/FieldNames.cpp index 66fc525585..7872f87c2e 100644 --- a/src/FieldNames.cpp +++ b/src/FieldNames.cpp @@ -14,9 +14,10 @@ std::map SField::codeToField; boost::mutex SField::mapMutex; SField sfInvalid(-1), sfGeneric(0); -SField sfLedgerEntry(FIELD_CODE(STI_LEDGERENTRY, 1), STI_LEDGERENTRY, 1, "LedgerEntry"); -SField sfTransaction(FIELD_CODE(STI_TRANSACTION, 1), STI_TRANSACTION, 1, "Transaction"); -SField sfValidation(FIELD_CODE(STI_VALIDATION, 1), STI_VALIDATION, 1, "Validation"); +SField sfLedgerEntry(STI_LEDGERENTRY, 1, "LedgerEntry"); +SField sfTransaction(STI_TRANSACTION, 1, "Transaction"); +SField sfValidation(STI_VALIDATION, 1, "Validation"); +SField sfID(STI_HASH256, 257, "id"); #define FIELD(name, type, index) SField sf##name(FIELD_CODE(STI_##type, index), STI_##type, index, #name); #define TYPE(name, type, index) @@ -97,3 +98,13 @@ SField::ref SField::getField(const std::string& fieldName) } return sfInvalid; } + +SField::~SField() +{ + boost::mutex::scoped_lock sl(mapMutex); + std::map::iterator it = codeToField.find(fieldCode); + if ((it != codeToField.end()) && (it->second == this)) + codeToField.erase(it); +} + +// vim:ts=4 diff --git a/src/FieldNames.h b/src/FieldNames.h index 443ae50086..3316ae492d 100644 --- a/src/FieldNames.h +++ b/src/FieldNames.h @@ -54,12 +54,14 @@ public: fieldCode(fc), fieldType(tid), fieldValue(fv), fieldName(fn) { codeToField[fieldCode] = this; } - SField(SerializedTypeID tid, int fv, const char *fn, bool temporary) : + SField(SerializedTypeID tid, int fv, const char *fn) : fieldCode(FIELD_CODE(tid, fv)), fieldType(tid), fieldValue(fv), fieldName(fn) - { if (!temporary) codeToField[fieldCode] = this; } + { codeToField[fieldCode] = this; } SField(int fc) : fieldCode(fc), fieldType(STI_UNKNOWN), fieldValue(0) { ; } + ~SField(); + static SField::ref getField(int fieldCode); static SField::ref getField(int fieldType, int fieldValue); static SField::ref getField(const std::string& fieldName); @@ -71,6 +73,7 @@ public: bool isGeneric() const { return fieldCode == 0; } bool isInvalid() const { return fieldCode == -1; } bool isKnown() const { return fieldType != STI_UNKNOWN; } + bool isBinary() const { return fieldValue < 256; } bool operator==(const SField& f) const { return fieldCode == f.fieldCode; } bool operator!=(const SField& f) const { return fieldCode != f.fieldCode; }