Skip to content

Commit a2cdd52

Browse files
Eivind Kvedalenwwmayer
authored andcommitted
Added PropertyContainer::handleMissingProperty(...) and PropertyContainer::handleChangedPropertyType(...).
These are helper functions to simplify migrating older files.
1 parent f8a7606 commit a2cdd52

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/App/PropertyContainer.cpp

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,36 @@ const char* PropertyContainer::getPropertyName(const Property* prop)const
152152
const PropertyData * PropertyContainer::getPropertyDataPtr(void){return &propertyData;}
153153
const PropertyData & PropertyContainer::getPropertyData(void) const{return propertyData;}
154154

155+
/**
156+
* @brief PropertyContainer::handleMissingProperty is called during restore to possibly
157+
* fix reading of older versions of this property container.
158+
*
159+
* The default implementation does nothing.
160+
*
161+
* @param reader The XML stream to read from.
162+
* @param PropName Name of property on file that does not exist in the container anymore.
163+
*/
164+
165+
void PropertyContainer::handleMissingProperty(XMLReader &reader, const char *PropName)
166+
{
167+
}
168+
169+
/**
170+
* @brief PropertyContainer::handleChangedPropertyType is called during restore to possibly
171+
* fix reading of older versions of the property container. This method is typically called
172+
* if the property on file has changed its type in more recent versions.
173+
*
174+
* The default implementation does nothing.
175+
*
176+
* @param reader The XML stream to read from.
177+
* @param TypeName Name of property type on file.
178+
* @param prop Pointer to property to restore. Its type differs from TypeName.
179+
*/
180+
181+
void PropertyContainer::handleChangedPropertyType(XMLReader &reader, const char *TypeName, Property *prop)
182+
{
183+
}
184+
155185
PropertyData PropertyContainer::propertyData;
156186

157187
/**
@@ -234,8 +264,17 @@ void PropertyContainer::Restore(Base::XMLReader &reader)
234264
// not its name. In this case we would force to read-in a wrong property
235265
// type and the behaviour would be undefined.
236266
try {
237-
if (prop && strcmp(prop->getTypeId().getName(), TypeName) == 0)
238-
prop->Restore(reader);
267+
268+
// Property not found in container, but one file?
269+
if (!prop)
270+
handleMissingProperty(reader, PropName);
271+
else {
272+
// Has the type changed?
273+
if (strcmp(prop->getTypeId().getName(), TypeName) != 0)
274+
handleChangedPropertyType(reader, TypeName, prop);
275+
else
276+
prop->Restore(reader); // All as before
277+
}
239278
}
240279
catch (const Base::XMLParseException&) {
241280
throw; // re-throw

src/App/PropertyContainer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ class AppExport PropertyContainer: public Base::Persistence
196196
static const PropertyData * getPropertyDataPtr(void);
197197
virtual const PropertyData& getPropertyData(void) const;
198198

199+
virtual void handleMissingProperty(Base::XMLReader &reader, const char *PropName);
200+
201+
virtual void handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, Property * prop);
202+
199203
private:
200204
// forbidden
201205
PropertyContainer(const PropertyContainer&);

0 commit comments

Comments
 (0)