Added PropertyContainer::handleMissingProperty(...) and PropertyContainer::handleChangedPropertyType(...).

These are helper functions to simplify migrating older files.
This commit is contained in:
Eivind Kvedalen
2017-07-21 19:02:43 +02:00
committed by wmayer
parent f8a76066da
commit a2cdd52019
2 changed files with 45 additions and 2 deletions

View File

@@ -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

View File

@@ -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&);