Provide (experimental) clang-format file
[TortoiseGit.git] / src / TortoiseProc / lanes.h
blobae45828842861bd4d1321ec42bbfb4f93774d696
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 MERGE_FORK_L_INITIAL,
28 JOIN,
29 JOIN_R,
30 JOIN_L,
31 HEAD,
32 HEAD_R,
33 HEAD_L,
34 TAIL,
35 TAIL_R,
36 TAIL_L,
37 CROSS,
38 CROSS_EMPTY,
39 INITIAL,
40 BRANCH,
41 UNAPPLIED,
42 APPLIED,
43 BOUNDARY,
44 BOUNDARY_C, // corresponds to MERGE_FORK
45 BOUNDARY_R, // corresponds to MERGE_FORK_R
46 BOUNDARY_L, // corresponds to MERGE_FORK_L
48 LANE_TYPES_NUM,
49 COLORS_NUM=8
52 // graph helpers
53 static inline bool isHead(int x) { return (x == HEAD || x == HEAD_R || x == HEAD_L); }
54 static inline bool isTail(int x) { return (x == TAIL || x == TAIL_R || x == TAIL_L); }
55 static inline bool isJoin(int x) { return (x == JOIN || x == JOIN_R || x == JOIN_L); }
56 static inline bool isFreeLane(int x) { return (x == NOT_ACTIVE || x == CROSS || isJoin(x)); }
57 static inline bool isBoundary(int x) { return (x == BOUNDARY || x == BOUNDARY_C || x == BOUNDARY_R || x == BOUNDARY_L); }
58 static inline bool isMerge(int x) { return (x == MERGE_FORK || x == MERGE_FORK_R || x == MERGE_FORK_L || isBoundary(x)); }
59 static inline bool isActive(int x) { return (x == ACTIVE || x == INITIAL || x == BRANCH || isMerge(x)); }
61 Lanes() // init() will setup us later, when data is available
62 : activeLane(0)
63 , boundary(false)
64 , NODE(0)
65 , NODE_L(0)
66 , NODE_R(0)
68 bool isEmpty() { return typeVec.empty(); }
69 void init(const CGitHash& expectedSha);
70 void clear();
71 bool isFork(const CGitHash& sha, bool& isDiscontinuity);
72 void setBoundary(bool isBoundary, bool isInitial);
73 void setFork(const CGitHash& sha);
74 void setMerge(const CGitHashList& parents);
75 void setInitial();
76 void setApplied();
77 void changeActiveLane(const CGitHash& sha);
78 void afterMerge();
79 void afterFork();
80 bool isBranch();
81 void afterBranch();
82 void afterApplied();
83 void nextParent(const CGitHash& sha);
84 void getLanes(QVector<int> &ln) { ln = typeVec; } // O(1) vector is implicitly shared
86 private:
87 int findNextSha(const CGitHash& next, int pos);
88 int findType(int type, int pos);
89 int add(int type, const CGitHash& next, int pos, bool& wasEmptyCross);
91 int activeLane;
92 QVector<int> typeVec;
93 QVector<CGitHash> nextShaVec;
94 bool boundary;
95 int NODE, NODE_L, NODE_R;
98 #endif