From 15547ce839d2af4e40a52a48e018ab61ad53389c Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 26 Oct 2012 13:31:24 -0700 Subject: [PATCH] Type STObject helper functions, 'empty' and 'hasMatchingEntry'. A small 'isFieldAllowed' bugfix. --- src/SerializedObject.cpp | 10 ++++++++++ src/SerializedObject.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/SerializedObject.cpp b/src/SerializedObject.cpp index afd876410..1477a2393 100644 --- a/src/SerializedObject.cpp +++ b/src/SerializedObject.cpp @@ -206,6 +206,8 @@ bool STObject::isValidForType() bool STObject::isFieldAllowed(SField::ref field) { + if (isFree()) + return true; BOOST_FOREACH(SOElement::ptr elem, mType) { // are any required elemnents missing if (elem->e_field == field) @@ -242,6 +244,14 @@ std::auto_ptr STObject::deserialize(SerializerIterator& sit, SFi return object; } +bool STObject::hasMatchingEntry(const SerializedType& t) +{ + const SerializedType* o = peekAtPField(t.getFName()); + if (!o) + return false; + return t == *o; +} + std::string STObject::getFullText() const { std::string ret; diff --git a/src/SerializedObject.h b/src/SerializedObject.h index 02587d36b..75d9ca64c 100644 --- a/src/SerializedObject.h +++ b/src/SerializedObject.h @@ -156,6 +156,9 @@ public: iterator end() { return mData.end(); } const_iterator begin() const { return mData.begin(); } const_iterator end() const { return mData.end(); } + bool empty() const { return mData.empty(); } + + bool hasMatchingEntry(const SerializedType&); bool operator==(const STObject& o) const; bool operator!=(const STObject& o) const { return ! (*this == o); }