Cleanups.

This commit is contained in:
JoelKatz
2012-09-26 00:28:58 -07:00
parent 11d8d481ff
commit fbb0baaca0
6 changed files with 31 additions and 3 deletions

View File

@@ -49,6 +49,20 @@ SField::ref SField::getField(int code);
return *(new SField(code, static_cast<SerializedTypeID>(type), field, NULL)); return *(new SField(code, static_cast<SerializedTypeID>(type), field, NULL));
} }
int SField::compare(SField::ref f1, SField::ref f2)
{ // -1 = f1 comes before f2, 0 = illegal combination, 1 = f1 comes after f2
if ((f1.fieldCode <= 0) || (f2.fieldCode <= 0))
return 0;
if (f1.fieldCode < f2.fieldCode)
return -1;
if (f2.fieldCode < f1.fieldCode)
return 1;
return 0;
}
SField::ref SField::getField(int type, int value) SField::ref SField::getField(int type, int value)
{ {
return getField(FIELD_CODE(type, value)); return getField(FIELD_CODE(type, value));

View File

@@ -69,6 +69,8 @@ public:
bool operator==(const SField& f) const { return fieldCode == f.fieldCode; } bool operator==(const SField& f) const { return fieldCode == f.fieldCode; }
bool operator!=(const SField& f) const { return fieldCode != f.fieldCode; } bool operator!=(const SField& f) const { return fieldCode != f.fieldCode; }
static int compare(SField::ref f1, SField::ref f2);
}; };
extern SField sfInvalid, sfGeneric; extern SField sfInvalid, sfGeneric;

View File

@@ -192,9 +192,9 @@ std::string STObject::getFullText() const
{ {
std::string ret; std::string ret;
bool first = true; bool first = true;
if (name != NULL) if (fName->hasName())
{ {
ret = name; ret = fName->getName();
ret += " = {"; ret += " = {";
} }
else ret = "{"; else ret = "{";
@@ -213,6 +213,13 @@ std::string STObject::getFullText() const
void STObject::add(Serializer& s) const void STObject::add(Serializer& s) const
{ {
addFieldID(s);
addRaw(s);
s.addFieldID(STI_OBJECT, 1);
}
void STObject::addRaw(Serializer& s) const
{ // FIXME: need to add in sorted order
BOOST_FOREACH(const SerializedType& it, mData) BOOST_FOREACH(const SerializedType& it, mData)
it.add(s); it.add(s);
} }

View File

@@ -56,7 +56,8 @@ public:
virtual SerializedTypeID getSType() const { return STI_OBJECT; } virtual SerializedTypeID getSType() const { return STI_OBJECT; }
virtual bool isEquivalent(const SerializedType& t) const; virtual bool isEquivalent(const SerializedType& t) const;
void add(Serializer& s) const; void add(Serializer& s) const; // with start/end of object
virtual void addRaw(Serializer& s) const; // just inner elements
Serializer getSerializer() const { Serializer s; add(s); return s; } Serializer getSerializer() const { Serializer s; add(s); return s; }
std::string getFullText() const; std::string getFullText() const;
std::string getText() const; std::string getText() const;

View File

@@ -66,6 +66,8 @@ public:
virtual bool isEquivalent(const SerializedType& t) const virtual bool isEquivalent(const SerializedType& t) const
{ assert(getSType() == STI_NOTPRESENT); return t.getSType() == STI_NOTPRESENT; } { assert(getSType() == STI_NOTPRESENT); return t.getSType() == STI_NOTPRESENT; }
void addFieldID(Serializer& s) const { s.addFieldID(fName->fieldType, fName->fieldValue); }
SerializedType& operator=(const SerializedType& t) SerializedType& operator=(const SerializedType& t)
{ if (!fName->fieldCode) fName = t.fName; return *this; } { if (!fName->fieldCode) fName = t.fName; return *this; }
bool operator==(const SerializedType& t) const bool operator==(const SerializedType& t) const

View File

@@ -9,6 +9,7 @@
#include "key.h" #include "key.h"
#include "uint256.h" #include "uint256.h"
#include "FieldNames.h"
typedef std::pair<int, std::vector<unsigned char> > TaggedListItem; typedef std::pair<int, std::vector<unsigned char> > TaggedListItem;
@@ -69,6 +70,7 @@ public:
bool getFieldID(int& type, int& name, int offset) const; bool getFieldID(int& type, int& name, int offset) const;
int addFieldID(int type, int name); int addFieldID(int type, int name);
int addFieldID(SerializedTypeID type, int name);
// normal hash functions // normal hash functions
uint160 getRIPEMD160(int size=-1) const; uint160 getRIPEMD160(int size=-1) const;