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:
Zheng, Lei
2022-09-15 13:37:39 +02:00
committed by Uwe
parent 50f6650fac
commit 9f200d4404
2 changed files with 15 additions and 1 deletions
+8 -1
View File
@@ -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();
}
+7
View File
@@ -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;