-
Notifications
You must be signed in to change notification settings - Fork 10
/
Seize.cpp
152 lines (126 loc) · 4.06 KB
/
Seize.cpp
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: Seize.cpp
* Author: cancian
*
* Created on 21 de Agosto de 2018, 16:17
*/
#include "Seize.h"
Seize::Seize(Model* model) : ModelComponent(model) {
_name = "Seize "+std::to_string(Util::_S_generateNewIdOfType(typeid(this).name()));
_queue = (Queue*)_model->getInfrastructure(typeid (Queue).name(), _name + "_Queue");
if (_queue == nullptr) {
_queue = new Queue();
_queue->setName(_name + "_Queue");
}
_resource = (Resource*)_model->getInfrastructure(typeid (Resource).name(), "Resource 1");
if (_resource == nullptr) {
_resource = new Resource();
_resource->setName("Resource 1");
}
}
Seize::Seize(const Seize& orig) : ModelComponent(orig) {
}
std::string Seize::show() {
return ModelComponent::show() + ", quantity=" + this->_quantity + ",...";
}
void Seize::_execute(Entity* entity) {
/* TODO +: not implemented yet */
_model->sendEntityToComponent(entity, this->getNextComponents()->first(), 0.0);
}
void Seize::setLastMemberSeized(unsigned int _lastMemberSeized) {
this->_lastMemberSeized = _lastMemberSeized;
}
unsigned int Seize::getLastMemberSeized() const {
return _lastMemberSeized;
}
void Seize::setSaveAttribute(std::string _saveAttribute) {
this->_saveAttribute = _saveAttribute;
}
std::string Seize::getSaveAttribute() const {
return _saveAttribute;
}
void Seize::setRule(Resource::ResourceRule _rule) {
this->_rule = _rule;
}
Resource::ResourceRule Seize::getRule() const {
return _rule;
}
void Seize::setQuantity(std::string _quantity) {
this->_quantity = _quantity;
}
std::string Seize::getQuantity() const {
return _quantity;
}
void Seize::setResourceType(Resource::ResourceType _resourceType) {
this->_resourceType = _resourceType;
}
Resource::ResourceType Seize::getResourceType() const {
return _resourceType;
}
void Seize::setPriority(unsigned short _priority) {
this->_priority = _priority;
}
unsigned short Seize::getPriority() const {
return _priority;
}
void Seize::setAllocationType(unsigned int _allocationType) {
this->_allocationType = _allocationType;
}
unsigned int Seize::getAllocationType() const {
return _allocationType;
}
void Seize::setQueueName(std::string _queueName) {
if (_queue->getName() != _queueName) {
Queue* queueNewName = (Queue*)_model->getInfrastructure(typeid (Queue).name(), _queueName);
if (queueNewName == nullptr) { // there is no queue with the new name
if (!_queue->isLinked()) { // no one else uses it. Only change the name
_queue->setName(_queueName);
} else { // it is linked. Create a new one
_queue = new Queue();
_queue->setName(_queueName);
}
} else { // there is another queue with the same name
if (!_queue->isLinked()) { // no one else uses it. It can be removed
_queue->~Queue();
} else { // there is another one using the queue with old name. Let it there
_queue->removeLink();
}
_queue = queueNewName;
_queue->addLink();
}
}
}
void Seize::setResourceName(std::string _resourceName) {
if (_resource->getName() != _resourceName) {
Resource* resourceNewName = (Resource*)_model->getInfrastructure(typeid (Resource).name(), _resourceName);
if (resourceNewName == nullptr) { // there is no resource with the new name
if (!_resource->isLinked()) { // no one else uses it. Only change the name
_resource->setName(_resourceName);
} else { // it is linked. Create a new one
_resource = new Resource();
_resource->setName(_resourceName);
}
} else { // there is another resource with the same name
if (!_resource->isLinked()) { // no one else uses it. It can be removed
_resource->~Resource();
} else { // there is another one using the resource with old name. Let it there
_resource->removeLink();
}
_resource = resourceNewName;
_resource->addLink();
}
}
}
std::string Seize::getResourceName() const {
return _resource->getName();
}
std::string Seize::getQueueName() const {
return _queue->getName();
}
Seize::~Seize() {
}