-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnector.cpp
54 lines (46 loc) · 1.25 KB
/
Connector.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
//
// Created by 沈敖 on 16/9/13.
//
#include "Connector.h"
#include <iostream>
Connector::Connector() { }
int Connector::getValue() {
return this->value;
}
void Connector::setValue(int newValue, string setter) {
if (!hasValue()) {
this->value = newValue;
this->informant = setter;
for (shared_ptr<Constraint> c : constraints) {
if (c->getName() != setter) {
c->informAboutValue();
}
}
} else {
if (this->value != newValue) {
cout << "Error! Contradiction (" << this->value << ", " << newValue << ")" << endl;
}
}
}
void Connector::forgetValue(string retractor) {
if (retractor == informant) {
this->informant = string();
for (shared_ptr<Constraint> c : constraints) {
if (c->getName() != retractor) {
c->informAboutNoValue();
}
}
}
}
void Connector::connect(Constraint *newConstraint) {
shared_ptr<Constraint> sp(newConstraint);
if (constraints.find(sp) == constraints.end()) {
this->constraints.insert(sp);
if (hasValue()) {
newConstraint->informAboutValue();
}
}
}
bool Connector::hasValue() {
return !this->informant.empty();
}