OSDN Git Service

Merge branch 'post-2.4.2'
[tjqt4port/tj2qt4.git] / taskjuggler / TaskDependency.cpp
1 /*
2  * TaskDependency.cpp - TaskJuggler
3  *
4  * Copyright (c) 2001, 2002, 2003, 2004 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 #include "TaskDependency.h"
14
15 #include <assert.h>
16
17 #include "Project.h"
18 #include "Task.h"
19 #include "Scenario.h"
20
21 TaskDependency::TaskDependency(QString tri, int maxScenarios) :
22     taskRefId(tri),
23     taskRef(0),
24     gapDuration(new long[maxScenarios]),
25     gapLength(new long[maxScenarios])
26 {
27     for (int sc = 0; sc < maxScenarios; ++sc)
28         gapDuration[sc] = gapLength[sc] = (sc == 0 ? 0 : -1);
29 }
30
31 TaskDependency::~TaskDependency()
32 {
33     delete [] gapDuration;
34     delete [] gapLength;
35 }
36
37 long
38 TaskDependency::getGapDuration(int sc) const
39 {
40     for ( ; ; )
41     {
42         if (gapDuration[sc] >= 0)
43             return gapDuration[sc];
44         Project* p = taskRef->getProject();
45         Scenario* parent = p->getScenario(sc)->getParent();
46         assert(parent);
47         sc = p->getScenarioIndex(parent->getId()) - 1;
48     }
49 }
50
51 long
52 TaskDependency::getGapLength(int sc) const
53 {
54     for ( ; ; )
55     {
56         if (gapLength[sc] >= 0)
57             return gapLength[sc];
58         Project* p = taskRef->getProject();
59         Scenario* parent = p->getScenario(sc)->getParent();
60         assert(parent);
61         sc = p->getScenarioIndex(parent->getId()) - 1;
62     }
63 }