Skip to content

v0.2.53..v0.2.54 changeset ElementComparer.h

Garret Voltz edited this page Mar 31, 2020 · 1 revision
diff --git a/hoot-core/src/main/cpp/hoot/core/elements/ElementComparer.h b/hoot-core/src/main/cpp/hoot/core/elements/ElementComparer.h
index a5db195..30e5c32 100644
--- a/hoot-core/src/main/cpp/hoot/core/elements/ElementComparer.h
+++ b/hoot-core/src/main/cpp/hoot/core/elements/ElementComparer.h
@@ -28,15 +28,18 @@
 #define ELEMENTCOMPARER_H
 
 // Hoot
-#include <hoot/core/elements/Element.h>
+#include <hoot/core/elements/OsmMap.h>
+#include <hoot/core/elements/OsmMapConsumer.h>
 
 namespace hoot
 {
 
 /**
  * Compares two elements of the same type for similarity
+ *
+ * Note that if element IDs are ignore, the comparison may be a little more expensive
  */
-class ElementComparer
+class ElementComparer : public OsmMapConsumer
 {
 
 public:
@@ -45,14 +48,38 @@ public:
 
   explicit ElementComparer(Meters threshold = 0.05);
 
+  /**
+   * Determines if two elements are the same
+   *
+   * The only reason the inputs are const is b/c we auto update nodes with a hash if they don't
+   * already have one.
+   *
+   * @param e1 the first element to compare
+   * @param e2 the second element to compare
+   * @return true if they are the same; false otherwise
+   */
   bool isSame(ElementPtr e1, ElementPtr e2) const;
 
+  void setIgnoreElementId(bool ignore) { _ignoreElementId = ignore; }
+
+  /**
+   * @see OsmMapConsumer
+   *
+   * This only needs to be set if _ignoreElementId = true. The reason a const map isn't used here
+   * is for the same reason isSame doesn't take in const elements.
+   */
+  virtual void setOsmMap(OsmMap* map) { _map = map->shared_from_this(); }
+
 private:
 
   //currently, this threshold applies only to non-node circular error checks and the var would
   //eventually go away completely if all element types were converted over to uses hashes for
   //comparisons
   Meters _threshold;
+  // enabling this allows for element comparisons to ignore the element ID
+  bool _ignoreElementId;
+  // a map is needed when comparing child elements if ignoring element IDs
+  OsmMapPtr _map;
 
   bool _compareNode(const std::shared_ptr<const Element>& re,
                     const std::shared_ptr<const Element>& e) const;
Clone this wiki locally