diff --git a/src/SerializedObject.cpp b/src/SerializedObject.cpp index c8d243952..a7ce22ba4 100644 --- a/src/SerializedObject.cpp +++ b/src/SerializedObject.cpp @@ -396,6 +396,19 @@ bool STObject::isFieldPresent(SField::ref field) const return peekAtIndex(index).getSType() != STI_NOTPRESENT; } +STObject& STObject::peekFieldObject(SField::ref field) +{ + SerializedType* rf = getPField(field, true); + if (!rf) + throw std::runtime_error("Field not found"); + if (rf->getSType() == STI_NOTPRESENT) + rf = makeFieldPresent(field); + STObject* cf = dynamic_cast(rf); + if (!cf) + throw std::runtime_error("Wrong field type"); + return *cf; +} + bool STObject::setFlag(uint32 f) { STUInt32* t = dynamic_cast(getPField(sfFlags, true)); diff --git a/src/SerializedObject.h b/src/SerializedObject.h index f2c389f09..69683ed49 100644 --- a/src/SerializedObject.h +++ b/src/SerializedObject.h @@ -132,6 +132,8 @@ public: void setFieldPathSet(SField::ref field, const STPathSet&); void setFieldV256(SField::ref field, const STVector256& v); + STObject& peekFieldObject(SField::ref field); + bool isFieldPresent(SField::ref field) const; SerializedType* makeFieldPresent(SField::ref field); void makeFieldAbsent(SField::ref field); @@ -199,6 +201,7 @@ public: void pop_back() { value.pop_back(); } bool empty() const { return value.empty(); } void clear() { value.clear(); } + void swap(STArray& a) { value.swap(a.value); } virtual std::string getFullText() const; virtual std::string getText() const;