File: Allocation.cpp

package info (click to toggle)
taskjuggler 2.3.0-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 8,764 kB
  • ctags: 3,700
  • sloc: cpp: 36,852; sh: 12,761; xml: 5,541; perl: 5,207; makefile: 269; python: 258; lisp: 67
file content (105 lines) | stat: -rw-r--r-- 2,582 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
 * Allocation.cpp - TaskJuggler
 *
 * Copyright (c) 2001, 2002, 2003, 2004 by Chris Schlaeger <cs@kde.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * $Id: Allocation.cpp 1259 2006-01-31 12:04:00Z cs $
 */

#include "qdom.h"

#include "Resource.h"
#include "ResourceTreeIterator.h"
#include "Allocation.h"
#include "ReportXML.h"
#include "UsageLimits.h"

#define KW(a) a

/* -- DTD --
    <!ELEMENT Allocation (Load, Persistent)>
    <!ELEMENT Load       (#PCDATA)>
    <!ELEMENT Persistent (#PCDATA)>
    <!ATTLIST Allocation ResourceID CDATA #REQUIRED>
  /-- DTD --/
*/

Allocation::Allocation() :
    lockedResource(0)
{
    shifts.setAutoDelete(TRUE);
    selectionMode = minAllocationProbability;
    limits = 0;
    persistent = mandatory = FALSE;
}

Allocation::~Allocation()
{
    delete limits;
}

Allocation::Allocation(const Allocation& a)
{
    shifts.setAutoDelete(TRUE);

    persistent = a.persistent;
    mandatory = a.mandatory;
    lockedResource = a.lockedResource;
    selectionMode = a.selectionMode;

    for (QPtrListIterator<ShiftSelection> sli(a.shifts); *sli; ++sli)
        shifts.append(new ShiftSelection(**sli));

    candidates = a.candidates;
    if (a.limits)
        limits = new UsageLimits(*a.limits);
    else
        limits = 0;
}

bool
Allocation::isWorker() const
{
    /* For an allocation to be a worker, all allocated resources must have an
     * non zero efficiency. */
    for (QPtrListIterator<Resource> cli(candidates); *cli; ++cli)
        if (!(*cli)->isWorker())
            return false;

    return true;
}

/* Creation of the XML Reprsentation of the Allocation */
QDomElement Allocation::xmlElement( QDomDocument& doc )
{
   QDomElement elem = doc.createElement( "Allocation" );
   elem.appendChild(ReportXML::createXMLElem( doc, "Persistent", isPersistent() ? "Yes":"No" ));
   elem.setAttribute( "ResourceID", candidates.getFirst()->getId());

   /* candidates are missing TODO */
   return elem;

}

bool
Allocation::setSelectionMode(const QString& smt)
{
    if (smt == KW("order"))
        selectionMode = order;
    else if (smt == KW("minallocated"))
        selectionMode = minAllocationProbability;
    else if (smt == KW("minloaded"))
        selectionMode = minLoaded;
    else if (smt == KW("maxloaded"))
        selectionMode = maxLoaded;
    else if (smt == KW("random"))
        selectionMode = random;
    else
        return FALSE;
    return TRUE;
}