diff --git a/src/SerializedObject.h b/src/SerializedObject.h index e6245853fa..6fd64274cf 100644 --- a/src/SerializedObject.h +++ b/src/SerializedObject.h @@ -27,20 +27,19 @@ protected: boost::ptr_vector 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& peekData() const { return data; } diff --git a/src/SerializedTypes.cpp b/src/SerializedTypes.cpp index fa9b23a28e..acdb2d1a28 100644 --- a/src/SerializedTypes.cpp +++ b/src/SerializedTypes.cpp @@ -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::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::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::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::const_iterator it=data.begin(), end=data.end(); it!=end; ++it) + { + if(!first) + { + ret+=", "; + first=false; + } + ret+=it->getText(); + } + ret+="}"; + return ret; +} diff --git a/src/SerializedTypes.h b/src/SerializedTypes.h index 3fe9126004..81ac8154c7 100644 --- a/src/SerializedTypes.h +++ b/src/SerializedTypes.h @@ -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; }