Skip to content

Commit

Permalink
Added PropertyContainer::handleMissingProperty(...) and PropertyConta…
Browse files Browse the repository at this point in the history
…iner::handleChangedPropertyType(...).

These are helper functions to simplify migrating older files.
  • Loading branch information
Eivind Kvedalen authored and wwmayer committed Jul 23, 2017
1 parent f8a7606 commit a2cdd52
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
43 changes: 41 additions & 2 deletions src/App/PropertyContainer.cpp
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/App/PropertyContainer.h
Expand Up @@ -196,6 +196,10 @@ class AppExport PropertyContainer: public Base::Persistence
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&);
Expand Down

0 comments on commit a2cdd52

Please sign in to comment.