| 1 |
/* |
| 2 |
* LoopDetectorInfo.h - TaskJuggler |
| 3 |
* |
| 4 |
* SPDX-FileCopyrightText: 2002, 2003, 2004, 2005, 2006 Chris Schlaeger <[email protected]> |
| 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 |
namespace TJ |
| 17 |
{ |
| 18 |
|
| 19 |
|
| 20 |
class LoopDetectorInfo; |
| 21 |
|
| 22 |
/** |
| 23 |
* This class stores information about a waypoint the dependency loop |
| 24 |
* detector passes when looking for loops. |
| 25 |
* |
| 26 |
* @short Utility class for the dependency loop detector. |
| 27 |
* @author Chris Schlaeger <[email protected]> |
| 28 |
*/ |
| 29 |
class LoopDetectorInfo |
| 30 |
{ |
| 31 |
friend class LDIList; |
| 32 |
public: |
| 33 |
LoopDetectorInfo() : |
| 34 |
nextLDI(nullptr), |
| 35 |
prevLDI(nullptr), |
| 36 |
t(nullptr), |
| 37 |
atEnd(false) |
| 38 |
{ } |
| 39 |
|
| 40 |
LoopDetectorInfo(const Task* _t, bool ae) : |
| 41 |
nextLDI(nullptr), |
| 42 |
prevLDI(nullptr), |
| 43 |
t(_t), |
| 44 |
atEnd(ae) |
| 45 |
{ } |
| 46 |
|
| 47 |
~LoopDetectorInfo() { } |
| 48 |
|
| 49 |
bool operator==(const LoopDetectorInfo& ldi) const |
| 50 |
{ |
| 51 |
return t == ldi.t && atEnd == ldi.atEnd; |
| 52 |
} |
| 53 |
bool operator!=(const LoopDetectorInfo& ldi) const |
| 54 |
{ |
| 55 |
return t != ldi.t || atEnd != ldi.atEnd; |
| 56 |
} |
| 57 |
const Task* getTask() const { return t; } |
| 58 |
bool getAtEnd() const { return atEnd; } |
| 59 |
LoopDetectorInfo* next() const { return nextLDI; } |
| 60 |
LoopDetectorInfo* prev() const { return prevLDI; } |
| 61 |
protected: |
| 62 |
LoopDetectorInfo* nextLDI; |
| 63 |
LoopDetectorInfo* prevLDI; |
| 64 |
private: |
| 65 |
const Task* t; |
| 66 |
bool atEnd; |
| 67 |
} ; |
| 68 |
|
| 69 |
/** |
| 70 |
* This class stores the waypoints the dependency loop detector passes when |
| 71 |
* looking for loops. Since it is very performance critical we use a |
| 72 |
* handrolled list class instead of a Qt class. |
| 73 |
* |
| 74 |
* @short Waypoint list of the dependency loop detector. |
| 75 |
* @author Chris Schlaeger <[email protected]> |
| 76 |
*/ |
| 77 |
class LDIList |
| 78 |
{ |
| 79 |
public: |
| 80 |
LDIList() : |
| 81 |
items(0), |
| 82 |
root(nullptr), |
| 83 |
leaf(nullptr) |
| 84 |
{ } |
| 85 |
|
| 86 |
LDIList(const LDIList& list) : |
| 87 |
items(0), |
| 88 |
root(nullptr), |
| 89 |
leaf(nullptr) |
| 90 |
{ |
| 91 |
for (LoopDetectorInfo* p = list.root; p; p = p->nextLDI) |
| 92 |
append(new LoopDetectorInfo(p->t, p->atEnd)); |
| 93 |
} |
| 94 |
|
| 95 |
virtual ~LDIList() |
| 96 |
{ |
| 97 |
for (LoopDetectorInfo* p = root; p; p = root) |
| 98 |
{ |
| 99 |
root = p->nextLDI; |
| 100 |
delete p; |
| 101 |
} |
| 102 |
} |
| 103 |
LoopDetectorInfo* first() const { return root; } |
| 104 |
LoopDetectorInfo* last() const { return leaf; } |
| 105 |
long count() const { return items; } |
| 106 |
|
| 107 |
bool find(const LoopDetectorInfo* ref) const |
| 108 |
{ |
| 109 |
for (LoopDetectorInfo* p = root; p; p = p->nextLDI) |
| 110 |
if (*p == *ref) |
| 111 |
return true; |
| 112 |
|
| 113 |
return false; |
| 114 |
} |
| 115 |
|
| 116 |
void append(LoopDetectorInfo* p) |
| 117 |
{ |
| 118 |
if (root == nullptr) |
| 119 |
{ |
| 120 |
root = leaf = p; |
| 121 |
leaf->prevLDI = nullptr; |
| 122 |
} |
| 123 |
else |
| 124 |
{ |
| 125 |
leaf->nextLDI = p; |
| 126 |
p->prevLDI = leaf; |
| 127 |
leaf = leaf->nextLDI; |
| 128 |
} |
| 129 |
leaf->nextLDI = nullptr; |
| 130 |
++items; |
| 131 |
} |
| 132 |
void removeLast() |
| 133 |
{ |
| 134 |
if (leaf == root) |
| 135 |
{ |
| 136 |
delete leaf; |
| 137 |
root = leaf = nullptr; |
| 138 |
} |
| 139 |
else |
| 140 |
{ |
| 141 |
leaf = leaf->prevLDI; |
| 142 |
delete leaf->nextLDI; |
| 143 |
leaf->nextLDI = nullptr; |
| 144 |
} |
| 145 |
--items; |
| 146 |
} |
| 147 |
LoopDetectorInfo* popLast() |
| 148 |
{ |
| 149 |
LoopDetectorInfo* lst = leaf; |
| 150 |
if (leaf == root) |
| 151 |
root = leaf = nullptr; |
| 152 |
else |
| 153 |
{ |
| 154 |
leaf = leaf->prevLDI; |
| 155 |
leaf->nextLDI = nullptr; |
| 156 |
} |
| 157 |
--items; |
| 158 |
lst->prevLDI = lst->nextLDI = nullptr; |
| 159 |
return lst; |
| 160 |
} |
| 161 |
private: |
| 162 |
long items; |
| 163 |
LoopDetectorInfo* root; |
| 164 |
LoopDetectorInfo* leaf; |
| 165 |
} ; |
| 166 |
|
| 167 |
} // namespace TJ |
| 168 |
|
| 169 |
#endif |
| 170 |
|