App/Part: add API Property::isSameContent()
A generate implementation of comparing property of any type. Note, in the future, isSame() will be promoted to be an abstract API in Property, and every type of property will have to provide an implementation. isSameContent() can be used as a not so efficient fallback.
This commit is contained in:
@@ -322,13 +322,20 @@ void Property::setStatus(Status pos, bool on) {
|
||||
}
|
||||
|
||||
bool Property::isSame(const Property &other) const {
|
||||
return isSameContent(other);
|
||||
}
|
||||
|
||||
bool Property::isSameContent(const Property &other) const {
|
||||
if(&other == this)
|
||||
return true;
|
||||
|
||||
if(other.getTypeId() != getTypeId() || getMemSize() != other.getMemSize())
|
||||
return false;
|
||||
|
||||
Base::StringWriter writer,writer2;
|
||||
FC_STATIC Base::StringWriter writer,writer2;
|
||||
writer.clear();
|
||||
Save(writer);
|
||||
writer2.clear();
|
||||
other.Save(writer2);
|
||||
return writer.getString() == writer2.getString();
|
||||
}
|
||||
|
||||
@@ -32,6 +32,10 @@
|
||||
#include <string>
|
||||
#include <FCGlobal.h>
|
||||
|
||||
// NOTE! define this to static thread_local if FreeCAD ever decides to use
|
||||
// multi-threading recomputation.
|
||||
#define FC_STATIC static
|
||||
|
||||
namespace Py {
|
||||
class Object;
|
||||
}
|
||||
@@ -266,6 +270,9 @@ public:
|
||||
*/
|
||||
int64_t getID() const {return _id;}
|
||||
|
||||
/// Compare property by comparing their XML content
|
||||
bool isSameContent(const Property &other) const;
|
||||
|
||||
virtual void beforeSave() const {}
|
||||
|
||||
friend class PropertyContainer;
|
||||
|
||||
Reference in New Issue
Block a user