1 #ifndef diff_hh 2 #define diff_hh 3 4 #include <string> 5 #include <libxml/tree.h> 6 #include "compare.hh" 7 #include "lcs.hh" 8 #include "target.hh" 9 #include "xdoc.hh" 10 11 namespace std { 12 13 template<> 14 struct less<xmlNodePtr> 15 { operator ()std::less16 bool operator()(xmlNodePtr m, xmlNodePtr n) const 17 { 18 return compare(m, n, true) < 0; 19 } 20 }; 21 22 template<> 23 struct equal_to<xmlNodePtr> 24 { operator ()std::equal_to25 bool operator()(xmlNodePtr m, xmlNodePtr n) 26 { 27 return compare(m, n, true) == 0; 28 } 29 }; 30 31 } 32 33 class Diff : private Target, private LCS<xmlNodePtr> 34 { 35 public: 36 Diff(const std::string &nsprefix, const std::string &nsurl); 37 38 // call at most once per Diff instance 39 xmlDocPtr diff_nodes(xmlNodePtr m, xmlNodePtr n); 40 41 protected: 42 virtual std::string get_ns_prefix() const; 43 virtual XDoc get_dest(); 44 45 private: 46 virtual void on_match(); 47 virtual void on_insert(xmlNodePtr n); 48 virtual void on_delete(xmlNodePtr n); 49 50 const std::string nsprefix; 51 52 XDoc dest; 53 xmlNsPtr dest_ns; 54 xmlNodePtr dest_point; 55 56 void diff(xmlNodePtr m, xmlNodePtr n); 57 bool do_diff_nodes(xmlNodePtr m, xmlNodePtr n, bool use_upd_attr); 58 59 void descend(xmlNodePtr m, xmlNodePtr n); 60 void replace(xmlNodePtr m, xmlNodePtr n); 61 bool combine_pair(xmlNodePtr n, bool reverse); 62 63 bool combine_first_child(xmlNodePtr first_child, 64 const std::string &checked_name); 65 66 void append_insert(xmlNodePtr n); 67 void append_delete(xmlNodePtr n); 68 void append_copy(); 69 70 xmlNodePtr new_dm_node(const char *name); 71 }; 72 73 #endif 74 75