OSDN Git Service

68f06d4af23f1a1b025ba7620363984a02fadca4
[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
63         Lanes() {} // init() will setup us later, when data is available
64         bool isEmpty() { return typeVec.empty(); }
65         void init(const QString& expectedSha);
66         void clear();
67         bool isFork(const QString& sha, bool& isDiscontinuity);
68         void setBoundary(bool isBoundary);
69         void setFork(const QString& sha);
70         void setMerge(const QStringList& parents);
71         void setInitial();
72         void setApplied();
73         void changeActiveLane(const QString& sha);
74         void afterMerge();
75         void afterFork();
76         bool isBranch();
77         void afterBranch();
78         void afterApplied();
79         void nextParent(const QString& sha);
80         void getLanes(QVector<int> &ln) { ln = typeVec; } // O(1) vector is implicitly shared
81
82 private:
83         int findNextSha(const QString& next, int pos);
84         int findType(int type, int pos);
85         int add(int type, const QString& next, int pos);
86
87         int activeLane;
88         QVector<int> typeVec;
89         QVector<QString> nextShaVec;
90         bool boundary;
91         int NODE, NODE_L, NODE_R;
92 };
93
94 #endif