/home/tetron/hack/vos/libs/vos/extensions/revcontrol/list3waymerge.hh
Go to the documentation of this file.00001 #ifndef _LIST3WAYMERGE_HH_
00002 #define _LIST3WAYMERGE_HH_
00003
00004 #include <vector>
00005 #include <deque>
00006 #include <string>
00007 #include <iostream>
00008
00009 struct Entry
00010 {
00011 unsigned int pos;
00012 std::string name;
00013 std::string child;
00014
00015 Entry(){}
00016 Entry(const Entry& c)
00017 : pos(c.pos),
00018 name(c.name),
00019 child(c.child)
00020 { }
00021 Entry& operator=(const Entry& c) {
00022 pos = c.pos;
00023 name = c.name;
00024 child = c.child;
00025 return *this;
00026 }
00027 };
00028
00029 #undef NOOP
00030 #undef INSERT
00031 #undef DELETE
00032 #undef SET
00033
00034 struct Change
00035 {
00036 enum { NOOP, INSERT, DELETE, SET } type;
00037 unsigned int pos;
00038 std::string name;
00039 std::string child;
00040
00041 std::string oldname;
00042 std::string oldchild;
00043
00044 Change(){}
00045 Change(const Change& c)
00046 : type(c.type),
00047 pos(c.pos),
00048 name(c.name),
00049 child(c.child),
00050 oldname(c.oldname),
00051 oldchild(c.oldchild)
00052 { }
00053
00054 Change& operator=(const Change& c) {
00055 type = c.type;
00056 pos = c.pos;
00057 name = c.name;
00058 child = c.child;
00059 oldname = c.oldname;
00060 oldchild = c.oldchild;
00061 return *this;
00062 }
00063 };
00064
00065 struct ListMergeConflict
00066 {
00067 Change head;
00068 Change branch;
00069 };
00070
00071 inline bool operator==(const Entry& x, const Entry& y)
00072 {
00073 return (x.name == y.name && x.child == y.child);
00074 }
00075
00076 inline bool operator!=(const Entry& x, const Entry& y)
00077 {
00078 return !(x == y);
00079 }
00080
00081 inline bool operator==(const Change& x, const Change& y)
00082 {
00083 return (x.type == y.type && x.pos == y.pos && x.name == y.name && x.child == y.child);
00084 }
00085
00086 inline bool operator!=(const Change& x, const Change& y)
00087 {
00088 return !(x == y);
00089 }
00090
00091 void applyChanges(std::deque<Entry>& entries, std::deque<Change>& history);
00092 void undoChanges(std::deque<Entry>& entries, std::deque<Change>& history);
00093 void listIt(std::deque<Entry>& entries);
00094 void pushDelete(std::deque<Change>& history, int pos);
00095 void pushSet(std::deque<Change>& history, int pos, const std::string& name, const std::string& child);
00096 void pushInsert(std::deque<Change>& history, int pos, const std::string& name, const std::string& child);
00097 void diffEntries(std::deque<Entry>& entries, std::deque<Entry>& base_entries,
00098 std::deque<Change>& delete_list, std::deque<Change>& insert_list);
00099 void printChangelist(std::deque<Change>& clist);
00100 void mergeEntries(std::deque<Entry>& branchA,
00101 std::deque<Entry>& branchB,
00102 std::deque<Entry>& base_entries,
00103 std::deque<Change>& delete_listBtoM,
00104 std::deque<Change>& insert_listBtoM,
00105 std::deque<ListMergeConflict>& conflicts,
00106 bool printstuff = false);
00107
00108 #endif