OSDN Git Service

adjust integer's signedness
[tjqt4port/tj2qt4.git] / taskjuggler / Allocation.cpp
1 /*
2  * Allocation.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 "Allocation.h"
14
15 #include "tjlib-internal.h"
16 #include "Resource.h"
17 #include "ResourceTreeIterator.h"
18 #include "ReportXML.h"
19 #include "UsageLimits.h"
20
21 /* -- DTD --
22     <!ELEMENT Allocation (Load, Persistent)>
23     <!ELEMENT Load       (#PCDATA)>
24     <!ELEMENT Persistent (#PCDATA)>
25     <!ATTLIST Allocation ResourceID CDATA #REQUIRED>
26   /-- DTD --/
27 */
28
29 Allocation::Allocation() :
30     limits(0),
31     shifts(),
32     persistent(false),
33     mandatory(false),
34     lockedResource(0),
35     conflictStart(0),
36     candidates(),
37     selectionMode(minAllocationProbability)
38 {
39     shifts.setAutoDelete(true);
40 }
41
42 Allocation::~Allocation()
43 {
44     delete limits;
45 }
46
47 Allocation::Allocation(const Allocation& a) :
48     limits(a.limits ? new UsageLimits(*a.limits) : 0),
49     shifts(),
50     persistent(a.persistent),
51     mandatory(a.mandatory),
52     lockedResource(a.lockedResource),
53     conflictStart(0),
54     candidates(a.candidates),
55     selectionMode(a.selectionMode)
56 {
57     shifts.setAutoDelete(true);
58
59     for (Q3PtrListIterator<ShiftSelection> sli(a.shifts); *sli; ++sli)
60         shifts.append(new ShiftSelection(**sli));
61 }
62
63 void
64 Allocation::setLimits(UsageLimits* l)
65 {
66     delete limits;
67     limits = l;
68 }
69
70 bool
71 Allocation::isWorker() const
72 {
73     /* For an allocation to be a worker, all allocated resources must have an
74      * non zero efficiency. */
75     for (Q3PtrListIterator<Resource> cli(candidates); *cli; ++cli)
76         if (!(*cli)->isWorker())
77             return false;
78
79     return true;
80 }
81
82 /* Creation of the XML Reprsentation of the Allocation */
83 QDomElement Allocation::xmlElement( QDomDocument& doc )
84 {
85    QDomElement elem = doc.createElement( "Allocation" );
86    elem.appendChild(ReportXML::createXMLElem( doc, "Persistent", isPersistent() ? "Yes":"No" ));
87    elem.setAttribute( "ResourceID", candidates.getFirst()->getId());
88
89    /* candidates are missing TODO */
90    return elem;
91
92 }
93
94 bool
95 Allocation::setSelectionMode(const QString& smt)
96 {
97     if (smt == KW("order"))
98         selectionMode = order;
99     else if (smt == KW("minallocated"))
100         selectionMode = minAllocationProbability;
101     else if (smt == KW("minloaded"))
102         selectionMode = minLoaded;
103     else if (smt == KW("maxloaded"))
104         selectionMode = maxLoaded;
105     else if (smt == KW("random"))
106         selectionMode = random;
107     else
108         return false;
109     return true;
110 }
111