]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/mathml_editor/src/Diff.hh
* this is a large commit
[helm.git] / helm / DEVEL / mathml_editor / src / Diff.hh
diff --git a/helm/DEVEL/mathml_editor/src/Diff.hh b/helm/DEVEL/mathml_editor/src/Diff.hh
new file mode 100644 (file)
index 0000000..099314b
--- /dev/null
@@ -0,0 +1,53 @@
+
+#ifndef __Diff_hh__
+#define __Diff_hh__
+
+#include <GdomeSmartDOM.hh>
+
+#define XMLNS_NS_URI "http://www.w3.org/2000/xmlns/"
+#define DDIFF_NS_URI "http://helm.cs.unibo.it/2002/DDIFF"
+
+namespace GdomeSmartDOMExt
+{
+  using namespace GdomeSmartDOM;
+
+  class Diff
+  {
+  public:
+    typedef bool (*flatNodeEq)(const Node&, const Node&);
+    static bool defaultFlatNodeEq(const Node&, const Node&);
+
+  private:
+    Diff(const Node& n, const Document& d, flatNodeEq e) : dest(n), doc(d), eq(e) { };
+
+  public:
+    static Diff diff(const Document&, const Document&, flatNodeEq = defaultFlatNodeEq);
+    static Diff diff(const Element&, const Element&, flatNodeEq = defaultFlatNodeEq);
+
+    Document document(void) const { return doc; };
+    Node     node(void) const { return dest; };
+
+    void patch(void) const;
+
+    struct BADDiff
+    {
+      BADDiff(const std::string& s) : msg(s) { };
+      const std::string msg;
+    };
+
+  private:
+    Node diffNodes(const Node&, const Node&) const;
+    bool diffChildren(const Node&, const Node&, const Node&) const;
+    void sameChunk(const Node&, unsigned long) const;
+    void patchRootNode(const Node&, const Element&) const;
+    void patchChildren(const Node&, const Element&) const;
+
+    Document   doc;
+    Node       dest;
+    flatNodeEq eq;
+  };
+
+}
+
+#endif // __ddiff_hh__