OSDN Git Service

Automatically align underspecified tasks boundaries on project boundaries when possible.
[tjqt4port/tj2qt4.git] / taskjuggler / LoopDetectorInfo.h
1 /*
2  * LoopDetectorInfo.h - TaskJuggler
3  *
4  * Copyright (c) 2002, 2003, 2004, 2005, 2006 by Chris Schlaeger <cs@kde.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of version 2 of the GNU General Public License as
8  * published by the Free Software Foundation.
9  *
10  * $Id$
11  */
12
13 #ifndef _LoopDetectorInfo_h_
14 #define _LoopDetectorInfo_h_
15
16 class LoopDetectorInfo;
17
18 /**
19  * This class stores information about a waypoint the dependency loop
20  * detector passes when looking for loops.
21  *
22  * @short Utility class for the dependency loop detector.
23  * @author Chris Schlaeger <cs@kde.org>
24  */
25 class LoopDetectorInfo
26 {
27     friend class LDIList;
28 public:
29     LoopDetectorInfo() :
30         nextLDI(0),
31         prevLDI(0),
32         t(0),
33         atEnd(false)
34     { }
35
36     LoopDetectorInfo(const Task* _t, bool ae) :
37         nextLDI(0),
38         prevLDI(0),
39         t(_t),
40         atEnd(ae)
41     { }
42
43     ~LoopDetectorInfo() { }
44
45     bool operator==(const LoopDetectorInfo& ldi) const
46     {
47         return t == ldi.t && atEnd == ldi.atEnd;
48     }
49     bool operator!=(const LoopDetectorInfo& ldi) const
50     {
51         return t != ldi.t || atEnd != ldi.atEnd;
52     }
53     const Task* getTask() const { return t; }
54     bool getAtEnd() const { return atEnd; }
55     LoopDetectorInfo* next() const { return nextLDI; }
56     LoopDetectorInfo* prev() const { return prevLDI; }
57 protected:
58     LoopDetectorInfo* nextLDI;
59     LoopDetectorInfo* prevLDI;
60 private:
61     const Task* t;
62     bool atEnd;
63 } ;
64
65 /**
66  * This class stores the waypoints the dependency loop detector passes when
67  * looking for loops. Since it is very performance critical we use a
68  * handrolled list class instead of a Qt class.
69  *
70  * @short Waypoint list of the dependency loop detector.
71  * @author Chris Schlaeger <cs@kde.org>
72  */
73 class LDIList
74 {
75 public:
76     LDIList() :
77         items(0),
78         root(0),
79         leaf(0)
80     { }
81
82     LDIList(LDIList& list) :
83         items(0),
84         root(0),
85         leaf(0)
86     {
87         for (LoopDetectorInfo* p = list.root; p; p = p->nextLDI)
88             append(new LoopDetectorInfo(p->t, p->atEnd));
89     }
90
91     virtual ~LDIList()
92     {
93         for (LoopDetectorInfo* p = root; p; p = root)
94         {
95             root = p->nextLDI;
96             delete p;
97         }
98     }
99     LoopDetectorInfo* first() const { return root; }
100     LoopDetectorInfo* last() const { return leaf; }
101     long count() const { return items; }
102
103     bool find(const LoopDetectorInfo* ref) const
104     {
105         for (LoopDetectorInfo* p = root; p; p = p->nextLDI)
106             if (*p == *ref)
107                 return true;
108
109         return false;
110     }
111
112     void append(LoopDetectorInfo* p)
113     {
114         if (root == 0)
115         {
116             root = leaf = p;
117             leaf->prevLDI = 0;
118         }
119         else
120         {
121             leaf->nextLDI = p;
122             p->prevLDI = leaf;
123             leaf = leaf->nextLDI;
124         }
125         leaf->nextLDI = 0;
126         ++items;
127     }
128     void removeLast()
129     {
130         if (leaf == root)
131         {
132             delete leaf;
133             root = leaf = 0;
134         }
135         else
136         {
137             leaf = leaf->prevLDI;
138             delete leaf->nextLDI;
139             leaf->nextLDI = 0;
140         }
141         --items;
142     }
143     LoopDetectorInfo* popLast()
144     {
145         LoopDetectorInfo* lst = leaf;
146         if (leaf == root)
147             root = leaf = 0;
148         else
149         {
150             leaf = leaf->prevLDI;
151             leaf->nextLDI = 0;
152         }
153         --items;
154         lst->prevLDI = lst->nextLDI = 0;
155         return lst;
156     }
157 private:
158     long items;
159     LoopDetectorInfo* root;
160     LoopDetectorInfo* leaf;
161 } ;
162
163 #endif
164