Allow to use libgit2 for unified diff
[TortoiseGit.git] / src / TortoiseProc / lanes.h
blob7cadbccfa493250fcb7c2125cd20ed1e7208802f
1 /*
2 Author: Marco Costalba (C) 2005-2007
3 Author: TortoiseGit (C) 2013
5 Copyright: See COPYING file that comes with this distribution
7 */
8 #ifndef LANES_H
9 #define LANES_H
11 //#include <CGitHash>
12 //#include <QVector>
13 #include "githash.h"
15 #define QVector vector
16 using namespace std;
18 typedef vector<CGitHash> CGitHashList ;
20 class Lanes {
21 public:
22 // graph elements
23 enum LaneType {
24 EMPTY,
25 ACTIVE,
26 NOT_ACTIVE,
27 MERGE_FORK,
28 MERGE_FORK_R,
29 MERGE_FORK_L,
30 JOIN,
31 JOIN_R,
32 JOIN_L,
33 HEAD,
34 HEAD_R,
35 HEAD_L,
36 TAIL,
37 TAIL_R,
38 TAIL_L,
39 CROSS,
40 CROSS_EMPTY,
41 INITIAL,
42 BRANCH,
43 UNAPPLIED,
44 APPLIED,
45 BOUNDARY,
46 BOUNDARY_C, // corresponds to MERGE_FORK
47 BOUNDARY_R, // corresponds to MERGE_FORK_R
48 BOUNDARY_L, // corresponds to MERGE_FORK_L
50 LANE_TYPES_NUM,
51 COLORS_NUM=8
54 // graph helpers
55 static inline bool isHead(int x) { return (x == HEAD || x == HEAD_R || x == HEAD_L); }
56 static inline bool isTail(int x) { return (x == TAIL || x == TAIL_R || x == TAIL_L); }
57 static inline bool isJoin(int x) { return (x == JOIN || x == JOIN_R || x == JOIN_L); }
58 static inline bool isFreeLane(int x) { return (x == NOT_ACTIVE || x == CROSS || isJoin(x)); }
59 static inline bool isBoundary(int x) { return (x == BOUNDARY || x == BOUNDARY_C ||
60 x == BOUNDARY_R || x == BOUNDARY_L); }
61 static inline bool isMerge(int x) { return (x == MERGE_FORK || x == MERGE_FORK_R ||
62 x == MERGE_FORK_L || isBoundary(x)); }
63 static inline bool isActive(int x) { return (x == ACTIVE || x == INITIAL || x == BRANCH ||
64 isMerge(x)); }
66 Lanes() // init() will setup us later, when data is available
67 : activeLane(0)
68 , boundary(false)
69 , NODE(0)
70 , NODE_L(0)
71 , NODE_R(0)
73 bool isEmpty() { return typeVec.empty(); }
74 void init(const CGitHash& expectedSha);
75 void clear();
76 bool isFork(const CGitHash& sha, bool& isDiscontinuity);
77 void setBoundary(bool isBoundary);
78 void setFork(const CGitHash& sha);
79 void setMerge(const CGitHashList& parents);
80 void setInitial();
81 void setApplied();
82 void changeActiveLane(const CGitHash& sha);
83 void afterMerge();
84 void afterFork();
85 bool isBranch();
86 void afterBranch();
87 void afterApplied();
88 void nextParent(const CGitHash& sha);
89 void getLanes(QVector<int> &ln) { ln = typeVec; } // O(1) vector is implicitly shared
91 private:
92 int findNextSha(const CGitHash& next, int pos);
93 int findType(int type, int pos);
94 int add(int type, const CGitHash& next, int pos);
96 int activeLane;
97 QVector<int> typeVec;
98 QVector<CGitHash> nextShaVec;
99 bool boundary;
100 int NODE, NODE_L, NODE_R;
103 #endif