Commit for Arthur.

getFullText, object layout.
STUObject code.
This commit is contained in:
JoelKatz
2012-03-16 17:04:18 -07:00
parent 672b976eb6
commit 99493c662a
3 changed files with 77 additions and 8 deletions

View File

@@ -27,20 +27,19 @@ protected:
boost::ptr_vector<SerializedType> data;
public:
STUObject() { ; }
virtual ~STUObject();
STUObject(const STUObject&);
STUObject& operator=(const STUObject&);
STUObject() : type(NULL) { ; }
STUObject(SOType *t) : type(t) { ; }
STUObject(SOType *t, SerializerIterator& u);
virtual ~STUObject() { ; }
int getLength() const;
SerializedTypeID getType() const { return STI_OBJECT; }
STUObject* duplicate() const { return new STUObject(*this); }
void add(Serializer& s) const;
std::string getFullText() const;
std::string getText() const;
void addObject(const SerializedType& t) { data.push_back(t.duplicate()); }
void giveObject(SerializedType* t) { data.push_back(t); }
const boost::ptr_vector<SerializedType>& peekData() const { return data; }

View File

@@ -4,6 +4,21 @@
#include "SerializedTypes.h"
#include "SerializedObject.h"
std::string SerializedType::getFullText() const
{
std::string ret;
if(getType()!=STI_NOTPRESENT)
{
if(name!=NULL)
{
ret=name;
ret+=" = ";
}
ret+=getText();
}
return ret;
}
STUInt8* STUInt8::construct(SerializerIterator& u)
{
return new STUInt8(u.get8());
@@ -111,3 +126,49 @@ int STUTaggedList::getLength() const
if(ret<0) throw(0);
return ret;
}
std::string STUObject::getFullText() const
{
std::string ret;
if(name!=NULL)
{
ret=name;
ret+=" = {";
}
else ret="{";
for(boost::ptr_vector<SerializedType>::const_iterator it=data.begin(), end=data.end(); it!=end; ++it)
ret+=it->getFullText();
ret+="}";
return ret;
}
int STUObject::getLength() const
{
int ret=0;
for(boost::ptr_vector<SerializedType>::const_iterator it=data.begin(), end=data.end(); it!=end; ++it)
ret+=it->getLength();
return ret;
}
void STUObject::add(Serializer& s) const
{
for(boost::ptr_vector<SerializedType>::const_iterator it=data.begin(), end=data.end(); it!=end; ++it)
it->add(s);
}
std::string STUObject::getText() const
{
std::string ret="{";
bool first=false;
for(boost::ptr_vector<SerializedType>::const_iterator it=data.begin(), end=data.end(); it!=end; ++it)
{
if(!first)
{
ret+=", ";
first=false;
}
ret+=it->getText();
}
ret+="}";
return ret;
}

View File

@@ -16,16 +16,25 @@ enum SerializedTypeID
class SerializedType
{
protected:
const char *name;
public:
SerializedType() { ; }
SerializedType() : name(NULL) { ; }
SerializedType(const char *n) : name(n) { ; }
virtual ~SerializedType() { ; }
void setName(const char *n) { name=n; }
const char *getName() { return name; }
virtual int getLength() const { return 0; }
virtual SerializedTypeID getType() const { return STI_NOTPRESENT; }
virtual SerializedType* duplicate() const { return new SerializedType(); }
virtual std::string getText() const { return std::string(); }
virtual std::string getFullText() const;
virtual std::string getText() const // just the value
{ return std::string(); }
virtual void add(Serializer& s) const { return; }