Having a function in a base class that's widely overloaded called 'getType'

is a bad idea. Change it to 'getSType'.
This commit is contained in:
JoelKatz
2012-04-08 19:56:48 -07:00
parent d7669944de
commit 21bb574e96
5 changed files with 44 additions and 44 deletions

View File

@@ -175,7 +175,7 @@ bool STObject::isEquivalent(const SerializedType& t) const
boost::ptr_vector<SerializedType>::const_iterator it2=v->mData.begin(), end2=v->mData.end();
while((it1!=end1) && (it2!=end2))
{
if(it1->getType() != it2->getType()) return false;
if(it1->getSType() != it2->getSType()) return false;
if(!it1->isEquivalent(*it2)) return false;
++it1;
++it2;
@@ -223,7 +223,7 @@ bool STObject::isFieldPresent(SOE_Field field) const
{
int index=getFieldIndex(field);
if(index==-1) return false;
return peekAtIndex(field).getType()==STI_OBJECT;
return peekAtIndex(field).getSType()==STI_OBJECT;
}
bool STObject::setFlag(int f)
@@ -256,7 +256,7 @@ void STObject::makeFieldPresent(SOE_Field field)
{
int index=getFieldIndex(field);
if(index==-1) throw std::runtime_error("Field not found");
if(peekAtIndex(field).getType()!=STI_OBJECT) return;
if(peekAtIndex(field).getSType()!=STI_OBJECT) return;
mData.replace(index, makeDefaultObject(mType[index]->e_id, mType[index]->e_name));
setFlag(mType[index]->e_flags);
}
@@ -265,7 +265,7 @@ void STObject::makeFieldAbsent(SOE_Field field)
{
int index=getFieldIndex(field);
if(index==-1) throw std::runtime_error("Field not found");
if(peekAtIndex(field).getType()==STI_OBJECT) return;
if(peekAtIndex(field).getSType()==STI_OBJECT) return;
mData.replace(index, new STObject(mType[index]->e_name));
clearFlag(mType[index]->e_flags);
}
@@ -281,7 +281,7 @@ unsigned char STObject::getValueFieldU8(SOE_Field field) const
{
const SerializedType* rf=peekAtPField(field);
if(!rf) throw std::runtime_error("Field not found");
SerializedTypeID id=rf->getType();
SerializedTypeID id=rf->getSType();
if(id==STI_OBJECT) return 0; // optional field not present
const STUInt8 *cf=dynamic_cast<const STUInt8 *>(rf);
if(!cf) throw std::runtime_error("Wrong field type");
@@ -292,7 +292,7 @@ uint16 STObject::getValueFieldU16(SOE_Field field) const
{
const SerializedType* rf=peekAtPField(field);
if(!rf) throw std::runtime_error("Field not found");
SerializedTypeID id=rf->getType();
SerializedTypeID id=rf->getSType();
if(id==STI_OBJECT) return 0; // optional field not present
const STUInt16 *cf=dynamic_cast<const STUInt16 *>(rf);
if(!cf) throw std::runtime_error("Wrong field type");
@@ -303,7 +303,7 @@ uint32 STObject::getValueFieldU32(SOE_Field field) const
{
const SerializedType* rf=peekAtPField(field);
if(!rf) throw std::runtime_error("Field not found");
SerializedTypeID id=rf->getType();
SerializedTypeID id=rf->getSType();
if(id==STI_OBJECT) return 0; // optional field not present
const STUInt32 *cf=dynamic_cast<const STUInt32 *>(rf);
if(!cf) throw std::runtime_error("Wrong field type");
@@ -314,7 +314,7 @@ uint64 STObject::getValueFieldU64(SOE_Field field) const
{
const SerializedType* rf=peekAtPField(field);
if(!rf) throw std::runtime_error("Field not found");
SerializedTypeID id=rf->getType();
SerializedTypeID id=rf->getSType();
if(id==STI_OBJECT) return 0; // optional field not present
const STUInt64 *cf=dynamic_cast<const STUInt64 *>(rf);
if(!cf) throw std::runtime_error("Wrong field type");
@@ -325,7 +325,7 @@ uint160 STObject::getValueFieldH160(SOE_Field field) const
{
const SerializedType* rf=peekAtPField(field);
if(!rf) throw std::runtime_error("Field not found");
SerializedTypeID id=rf->getType();
SerializedTypeID id=rf->getSType();
if(id==STI_OBJECT) return uint160(); // optional field not present
const STHash160 *cf=dynamic_cast<const STHash160 *>(rf);
if(!cf) throw std::runtime_error("Wrong field type");
@@ -336,7 +336,7 @@ uint256 STObject::getValueFieldH256(SOE_Field field) const
{
const SerializedType* rf=peekAtPField(field);
if(!rf) throw std::runtime_error("Field not found");
SerializedTypeID id=rf->getType();
SerializedTypeID id=rf->getSType();
if(id==STI_OBJECT) return uint256(); // optional field not present
const STHash256 *cf=dynamic_cast<const STHash256 *>(rf);
if(!cf) throw std::runtime_error("Wrong field type");
@@ -347,7 +347,7 @@ std::vector<unsigned char> STObject::getValueFieldVL(SOE_Field field) const
{
const SerializedType* rf=peekAtPField(field);
if(!rf) throw std::runtime_error("Field not found");
SerializedTypeID id=rf->getType();
SerializedTypeID id=rf->getSType();
if(id==STI_OBJECT) return std::vector<unsigned char>(); // optional field not present
const STVariableLength *cf=dynamic_cast<const STVariableLength *>(rf);
if(!cf) throw std::runtime_error("Wrong field type");
@@ -358,7 +358,7 @@ std::vector<TaggedListItem> STObject::getValueFieldTL(SOE_Field field) const
{
const SerializedType* rf=peekAtPField(field);
if(!rf) throw std::runtime_error("Field not found");
SerializedTypeID id=rf->getType();
SerializedTypeID id=rf->getSType();
if(id==STI_OBJECT) return std::vector<TaggedListItem>(); // optional field not present
const STTaggedList *cf=dynamic_cast<const STTaggedList *>(rf);
if(!cf) throw std::runtime_error("Wrong field type");
@@ -369,12 +369,12 @@ void STObject::setValueFieldU8(SOE_Field field, unsigned char v)
{
SerializedType* rf=getPField(field);
if(!rf) throw std::runtime_error("Field not found");
SerializedTypeID id=rf->getType();
SerializedTypeID id=rf->getSType();
if(id==STI_OBJECT)
{
makeFieldPresent(field);
rf=getPField(field);
id=rf->getType();
id=rf->getSType();
}
STUInt8* cf=dynamic_cast<STUInt8*>(rf);
if(!cf) throw(std::runtime_error("Wrong field type"));
@@ -385,12 +385,12 @@ void STObject::setValueFieldU16(SOE_Field field, uint16 v)
{
SerializedType* rf=getPField(field);
if(!rf) throw std::runtime_error("Field not found");
SerializedTypeID id=rf->getType();
SerializedTypeID id=rf->getSType();
if(id==STI_OBJECT)
{
makeFieldPresent(field);
rf=getPField(field);
id=rf->getType();
id=rf->getSType();
}
STUInt16* cf=dynamic_cast<STUInt16*>(rf);
if(!cf) throw(std::runtime_error("Wrong field type"));
@@ -401,12 +401,12 @@ void STObject::setValueFieldU32(SOE_Field field, uint32 v)
{
SerializedType* rf=getPField(field);
if(!rf) throw std::runtime_error("Field not found");
SerializedTypeID id=rf->getType();
SerializedTypeID id=rf->getSType();
if(id==STI_OBJECT)
{
makeFieldPresent(field);
rf=getPField(field);
id=rf->getType();
id=rf->getSType();
}
STUInt32* cf=dynamic_cast<STUInt32*>(rf);
if(!cf) throw(std::runtime_error("Wrong field type"));
@@ -417,12 +417,12 @@ void STObject::setValueFieldU64(SOE_Field field, uint64 v)
{
SerializedType* rf=getPField(field);
if(!rf) throw std::runtime_error("Field not found");
SerializedTypeID id=rf->getType();
SerializedTypeID id=rf->getSType();
if(id==STI_OBJECT)
{
makeFieldPresent(field);
rf=getPField(field);
id=rf->getType();
id=rf->getSType();
}
STUInt64* cf=dynamic_cast<STUInt64*>(rf);
if(!cf) throw(std::runtime_error("Wrong field type"));
@@ -433,12 +433,12 @@ void STObject::setValueFieldH160(SOE_Field field, const uint160& v)
{
SerializedType* rf=getPField(field);
if(!rf) throw std::runtime_error("Field not found");
SerializedTypeID id=rf->getType();
SerializedTypeID id=rf->getSType();
if(id==STI_OBJECT)
{
makeFieldPresent(field);
rf=getPField(field);
id=rf->getType();
id=rf->getSType();
}
STHash160* cf=dynamic_cast<STHash160*>(rf);
if(!cf) throw(std::runtime_error("Wrong field type"));
@@ -449,12 +449,12 @@ void STObject::setValueFieldVL(SOE_Field field, const std::vector<unsigned char>
{
SerializedType* rf=getPField(field);
if(!rf) throw std::runtime_error("Field not found");
SerializedTypeID id=rf->getType();
SerializedTypeID id=rf->getSType();
if(id==STI_OBJECT)
{
makeFieldPresent(field);
rf=getPField(field);
id=rf->getType();
id=rf->getSType();
}
STVariableLength* cf=dynamic_cast<STVariableLength*>(rf);
if(!cf) throw(std::runtime_error("Wrong field type"));
@@ -465,12 +465,12 @@ void STObject::setValueFieldTL(SOE_Field field, const std::vector<TaggedListItem
{
SerializedType* rf=getPField(field);
if(!rf) throw std::runtime_error("Field not found");
SerializedTypeID id=rf->getType();
SerializedTypeID id=rf->getSType();
if(id==STI_OBJECT)
{
makeFieldPresent(field);
rf=getPField(field);
id=rf->getType();
id=rf->getSType();
}
STTaggedList* cf=dynamic_cast<STTaggedList*>(rf);
if(!cf) throw(std::runtime_error("Wrong field type"));
@@ -483,7 +483,7 @@ Json::Value STObject::getJson(int options) const
int index=1;
for(boost::ptr_vector<SerializedType>::const_iterator it=mData.begin(), end=mData.end(); it!=end; ++it, ++index)
{
if(it->getType()!=STI_NOTPRESENT)
if(it->getSType()!=STI_NOTPRESENT)
{
if(it->getName()==NULL)
ret[boost::lexical_cast<std::string>(index)]=it->getText();

View File

@@ -56,7 +56,7 @@ public:
virtual ~STObject() { ; }
int getLength() const;
SerializedTypeID getType() const { return STI_OBJECT; }
SerializedTypeID getSType() const { return STI_OBJECT; }
STObject* duplicate() const { return new STObject(*this); }
virtual bool isEquivalent(const SerializedType& t) const;

View File

@@ -26,7 +26,7 @@ public:
// STObject functions
int getLength() const;
SerializedTypeID getType() const { return STI_TRANSACTION; }
SerializedTypeID getSType() const { return STI_TRANSACTION; }
SerializedTransaction* duplicate() const { return new SerializedTransaction(*this); }
std::string getFullText() const;
std::string getText() const;
@@ -63,7 +63,7 @@ public:
// inner transaction field functions
int getITFieldIndex(SOE_Field field) const;
int getITFieldCount() const;
const SerializedType& peekITField(SOE_Field field);
const SerializedType& peekITField(SOE_Field field) const;
SerializedType& getITField(SOE_Field field);
// inner transaction field value functions

View File

@@ -9,7 +9,7 @@
std::string SerializedType::getFullText() const
{
std::string ret;
if(getType()!=STI_NOTPRESENT)
if(getSType()!=STI_NOTPRESENT)
{
if(name!=NULL)
{

View File

@@ -35,7 +35,7 @@ public:
const char *getName() const { return name; }
virtual int getLength() const { return 0; }
virtual SerializedTypeID getType() const { return STI_NOTPRESENT; }
virtual SerializedTypeID getSType() const { return STI_NOTPRESENT; }
virtual SerializedType* duplicate() const { return new SerializedType(name); }
virtual std::string getFullText() const;
@@ -50,9 +50,9 @@ public:
virtual bool isEquivalent(const SerializedType& t) const { return true; }
bool operator==(const SerializedType& t) const
{ return (getType()==t.getType()) && isEquivalent(t); }
{ return (getSType()==t.getSType()) && isEquivalent(t); }
bool operator!=(const SerializedType& t) const
{ return (getType()!=t.getType()) || !isEquivalent(t); }
{ return (getSType()!=t.getSType()) || !isEquivalent(t); }
};
class STUInt8 : public SerializedType
@@ -67,7 +67,7 @@ public:
static STUInt8* construct(SerializerIterator&, const char *name=NULL);
int getLength() const { return 1; }
SerializedTypeID getType() const { return STI_UINT8; }
SerializedTypeID getSType() const { return STI_UINT8; }
STUInt8* duplicate() const { return new STUInt8(name, value); }
std::string getText() const;
void add(Serializer& s) const { s.add8(value); }
@@ -92,7 +92,7 @@ public:
static STUInt16* construct(SerializerIterator&, const char *name=NULL);
int getLength() const { return 2; }
SerializedTypeID getType() const { return STI_UINT16; }
SerializedTypeID getSType() const { return STI_UINT16; }
STUInt16* duplicate() const { return new STUInt16(name, value); }
std::string getText() const;
void add(Serializer& s) const { s.add16(value); }
@@ -117,7 +117,7 @@ public:
static STUInt32* construct(SerializerIterator&, const char *name=NULL);
int getLength() const { return 4; }
SerializedTypeID getType() const { return STI_UINT32; }
SerializedTypeID getSType() const { return STI_UINT32; }
STUInt32* duplicate() const { return new STUInt32(name, value); }
std::string getText() const;
void add(Serializer& s) const { s.add32(value); }
@@ -142,7 +142,7 @@ public:
static STUInt64* construct(SerializerIterator&, const char *name=NULL);
int getLength() const { return 8; }
SerializedTypeID getType() const { return STI_UINT64; }
SerializedTypeID getSType() const { return STI_UINT64; }
STUInt64* duplicate() const { return new STUInt64(name, value); }
std::string getText() const;
void add(Serializer& s) const { s.add64(value); }
@@ -168,7 +168,7 @@ public:
static STHash128* construct(SerializerIterator&, const char *name=NULL);
int getLength() const { return 20; }
SerializedTypeID getType() const { return STI_HASH128; }
SerializedTypeID getSType() const { return STI_HASH128; }
STHash128* duplicate() const { return new STHash128(name, value); }
virtual std::string getText() const;
void add(Serializer& s) const { s.add128(value); }
@@ -194,7 +194,7 @@ public:
static STHash160* construct(SerializerIterator&, const char *name=NULL);
int getLength() const { return 20; }
SerializedTypeID getType() const { return STI_HASH160; }
SerializedTypeID getSType() const { return STI_HASH160; }
STHash160* duplicate() const { return new STHash160(name, value); }
virtual std::string getText() const;
void add(Serializer& s) const { s.add160(value); }
@@ -220,7 +220,7 @@ public:
static STHash256* construct(SerializerIterator&, const char *name=NULL);
int getLength() const { return 32; }
SerializedTypeID getType() const { return STI_HASH256; }
SerializedTypeID getSType() const { return STI_HASH256; }
STHash256* duplicate() const { return new STHash256(name, value); }
std::string getText() const;
void add(Serializer& s) const { s.add256(value); }
@@ -247,7 +247,7 @@ public:
static STVariableLength* construct(SerializerIterator&, const char *name=NULL);
int getLength() const;
virtual SerializedTypeID getType() const { return STI_VL; }
virtual SerializedTypeID getSType() const { return STI_VL; }
virtual STVariableLength* duplicate() const { return new STVariableLength(name, value); }
virtual std::string getText() const;
void add(Serializer& s) const { s.addVL(value); }
@@ -272,7 +272,7 @@ public:
STAccount() { ; }
static STAccount* construct(SerializerIterator&, const char *name=NULL);
SerializedTypeID getType() const { return STI_ACCOUNT; }
SerializedTypeID getSType() const { return STI_ACCOUNT; }
virtual STAccount* duplicate() const { return new STAccount(name, value); }
std::string getText() const;
@@ -295,7 +295,7 @@ public:
static STTaggedList* construct(SerializerIterator&, const char *name=NULL);
int getLength() const;
SerializedTypeID getType() const { return STI_TL; }
SerializedTypeID getSType() const { return STI_TL; }
STTaggedList* duplicate() const { return new STTaggedList(name, value); }
std::string getText() const;
void add(Serializer& s) const { if(s.addTaggedList(value)<0) throw(0); }