1 | // |
---|
2 | // sector.cpp |
---|
3 | // PSPA |
---|
4 | // |
---|
5 | // Created by Garnier Laurent on 10/12/13. |
---|
6 | // Copyright (c) 2013 Garnier Laurent. All rights reserved. |
---|
7 | // |
---|
8 | |
---|
9 | #include "sector.h" |
---|
10 | |
---|
11 | #include "sectionToExecute.h" |
---|
12 | #include "dataManager.h" |
---|
13 | |
---|
14 | sector::sector(dataManager* data, std::string name): |
---|
15 | reflected_(false), |
---|
16 | duplicatedFrom_(NULL), |
---|
17 | repetitionNumber_(1), |
---|
18 | name_(name), |
---|
19 | dataManager_(data), |
---|
20 | sectorParam_(this) |
---|
21 | { |
---|
22 | |
---|
23 | } |
---|
24 | |
---|
25 | sector::~sector() { |
---|
26 | } |
---|
27 | |
---|
28 | void sector::addElementAfter(abstractElement* currentElement ,abstractElement* previousElement){ |
---|
29 | // if the previous element is NULL, it will try to add at the beginning of the first section |
---|
30 | |
---|
31 | if (previousElement == NULL) { |
---|
32 | if (sectionToExecute_.size() == 0) { |
---|
33 | sectionToExecute_.push_back(new sectionToExecute(currentElement,NULL)); |
---|
34 | } else { |
---|
35 | sectionToExecute* section = sectionToExecute_.front(); |
---|
36 | section->insertAtFirst(currentElement); |
---|
37 | } |
---|
38 | } else { |
---|
39 | |
---|
40 | for (unsigned int i=0; i<sectionToExecute_.size(); i++) { |
---|
41 | sectionToExecute* section = sectionToExecute_[i]; |
---|
42 | if (section->insertAfter(previousElement,currentElement)) { |
---|
43 | return; |
---|
44 | } |
---|
45 | } |
---|
46 | } |
---|
47 | } |
---|
48 | |
---|
49 | void sector::clearSectionToExecute() |
---|
50 | { |
---|
51 | unsigned k; |
---|
52 | for(k = 0; k < sectionToExecute_.size(); k++) |
---|
53 | { |
---|
54 | if ( sectionToExecute_[k] != NULL ) clearSectionToExecute(k); |
---|
55 | } |
---|
56 | sectionToExecute_.clear(); |
---|
57 | } |
---|
58 | |
---|
59 | void sector::clearSectionToExecute(int a) |
---|
60 | { |
---|
61 | cout << " dataManager::clearSectionToExecute : effacement de la section d'index = " << a << endl; |
---|
62 | if (a < 0) return; |
---|
63 | if (a >= (int)sectionToExecute_.size()) return; |
---|
64 | |
---|
65 | // lors de la creation de la section on a fait un 'new' d'un |
---|
66 | // softwareXXXX : on fait ici le 'delete' |
---|
67 | |
---|
68 | const abstractSoftware* soft = sectionToExecute_.at(a)->getSoftware(); |
---|
69 | if ( soft != NULL ) delete soft; |
---|
70 | sectionToExecute_.erase (sectionToExecute_.begin()+a); |
---|
71 | } |
---|