| 1 |
/* |
| 2 |
* TaskDependency.cpp - TaskJuggler |
| 3 |
* |
| 4 |
* SPDX-FileCopyrightText: 2001, 2002, 2003, 2004 Chris Schlaeger <[email protected]> |
| 5 |
* SPDX-FileCopyrightText: 2011 Dag Andersen <[email protected]> |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of version 2 of the GNU General Public License as |
| 9 |
* published by the Free Software Foundation. |
| 10 |
* |
| 11 |
* $Id$ |
| 12 |
*/ |
| 13 |
|
| 14 |
// clazy:excludeall=qstring-arg |
| 15 |
#include "TaskDependency.h" |
| 16 |
|
| 17 |
#include <assert.h> |
| 18 |
|
| 19 |
#include "Project.h" |
| 20 |
#include "Task.h" |
| 21 |
#include "Scenario.h" |
| 22 |
|
| 23 |
namespace TJ |
| 24 |
{ |
| 25 |
|
| 26 |
TaskDependency::TaskDependency(QString tri, int maxScenarios) : |
| 27 |
taskRefId(tri), |
| 28 |
taskRef(nullptr), |
| 29 |
gapDuration(new long[maxScenarios]), |
| 30 |
gapLength(new long[maxScenarios]) |
| 31 |
{ |
| 32 |
for (int sc = 0; sc < maxScenarios; ++sc) |
| 33 |
gapDuration[sc] = gapLength[sc] = (sc == 0 ? 0 : -1); |
| 34 |
} |
| 35 |
|
| 36 |
TaskDependency::~TaskDependency() |
| 37 |
{ |
| 38 |
delete [] gapDuration; |
| 39 |
delete [] gapLength; |
| 40 |
} |
| 41 |
|
| 42 |
long |
| 43 |
TaskDependency::getGapDuration(int sc) const |
| 44 |
{ |
| 45 |
for (; ;) |
| 46 |
{ |
| 47 |
if (gapDuration[sc] >= 0) |
| 48 |
return gapDuration[sc]; |
| 49 |
Project* p = taskRef->getProject(); |
| 50 |
Scenario* parent = p->getScenario(sc)->getParent(); |
| 51 |
assert(parent); |
| 52 |
sc = p->getScenarioIndex(parent->getId()) - 1; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
long |
| 57 |
TaskDependency::getGapLength(int sc) const |
| 58 |
{ |
| 59 |
for (; ;) |
| 60 |
{ |
| 61 |
if (gapLength[sc] >= 0) |
| 62 |
return gapLength[sc]; |
| 63 |
Project* p = taskRef->getProject(); |
| 64 |
Scenario* parent = p->getScenario(sc)->getParent(); |
| 65 |
assert(parent); |
| 66 |
sc = p->getScenarioIndex(parent->getId()) - 1; |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
} // namespace TJ |
| 71 |
|
| 72 |
QDebug operator<<(QDebug dbg, const TJ::TaskDependency *dep) |
| 73 |
{ |
| 74 |
return dep == nullptr ? (dbg<<0x000000) : operator<<(dbg, *dep); |
| 75 |
} |
| 76 |
QDebug operator<<(QDebug dbg, const TJ::TaskDependency &dep) |
| 77 |
{ |
| 78 |
dbg<<"TaskDependency["; |
| 79 |
if (dep.getTaskRef()) { |
| 80 |
dbg.nospace()<<"ref="<<dep.getTaskRef()->getId(); |
| 81 |
} else { |
| 82 |
dbg.nospace()<<"id="<<dep.getTaskRefId(); |
| 83 |
} |
| 84 |
dbg << ']'; |
| 85 |
return dbg; |
| 86 |
} |