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