OSDN Git Service

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