From a2cdd5201917577e9c75a67396509e98ad8ac382 Mon Sep 17 00:00:00 2001 From: Eivind Kvedalen Date: Fri, 21 Jul 2017 19:02:43 +0200 Subject: [PATCH] Added PropertyContainer::handleMissingProperty(...) and PropertyContainer::handleChangedPropertyType(...). These are helper functions to simplify migrating older files. --- src/App/PropertyContainer.cpp | 43 +++++++++++++++++++++++++++++++++-- src/App/PropertyContainer.h | 4 ++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/App/PropertyContainer.cpp b/src/App/PropertyContainer.cpp index fc154f3b5a..ebce3ace32 100644 --- a/src/App/PropertyContainer.cpp +++ b/src/App/PropertyContainer.cpp @@ -152,6 +152,36 @@ const char* PropertyContainer::getPropertyName(const Property* prop)const const PropertyData * PropertyContainer::getPropertyDataPtr(void){return &propertyData;} const PropertyData & PropertyContainer::getPropertyData(void) const{return propertyData;} +/** + * @brief PropertyContainer::handleMissingProperty is called during restore to possibly + * fix reading of older versions of this property container. + * + * The default implementation does nothing. + * + * @param reader The XML stream to read from. + * @param PropName Name of property on file that does not exist in the container anymore. + */ + +void PropertyContainer::handleMissingProperty(XMLReader &reader, const char *PropName) +{ +} + +/** + * @brief PropertyContainer::handleChangedPropertyType is called during restore to possibly + * fix reading of older versions of the property container. This method is typically called + * if the property on file has changed its type in more recent versions. + * + * The default implementation does nothing. + * + * @param reader The XML stream to read from. + * @param TypeName Name of property type on file. + * @param prop Pointer to property to restore. Its type differs from TypeName. + */ + +void PropertyContainer::handleChangedPropertyType(XMLReader &reader, const char *TypeName, Property *prop) +{ +} + PropertyData PropertyContainer::propertyData; /** @@ -234,8 +264,17 @@ void PropertyContainer::Restore(Base::XMLReader &reader) // not its name. In this case we would force to read-in a wrong property // type and the behaviour would be undefined. try { - if (prop && strcmp(prop->getTypeId().getName(), TypeName) == 0) - prop->Restore(reader); + + // Property not found in container, but one file? + if (!prop) + handleMissingProperty(reader, PropName); + else { + // Has the type changed? + if (strcmp(prop->getTypeId().getName(), TypeName) != 0) + handleChangedPropertyType(reader, TypeName, prop); + else + prop->Restore(reader); // All as before + } } catch (const Base::XMLParseException&) { throw; // re-throw diff --git a/src/App/PropertyContainer.h b/src/App/PropertyContainer.h index 33e99d1924..752f20b342 100644 --- a/src/App/PropertyContainer.h +++ b/src/App/PropertyContainer.h @@ -196,6 +196,10 @@ protected: static const PropertyData * getPropertyDataPtr(void); virtual const PropertyData& getPropertyData(void) const; + virtual void handleMissingProperty(Base::XMLReader &reader, const char *PropName); + + virtual void handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, Property * prop); + private: // forbidden PropertyContainer(const PropertyContainer&);