-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiplier.cpp
35 lines (27 loc) · 923 Bytes
/
Multiplier.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
//
// Created by 沈敖 on 16/9/13.
//
#include "Multiplier.h"
Multiplier::Multiplier(Connector *m1, Connector *m2, Connector *product, string name)
:Constraint(name), m1(m1), m2(m2), product(product) {
this->m1->connect(this);
this->m2->connect(this);
product->connect(this);
}
void Multiplier::informAboutValue() {
if (m1->hasValue() && m2->hasValue()) {
product->setValue(m1->getValue() * m2->getValue(), this->getName());
}
if (m1->hasValue() && product->hasValue()) {
m2->setValue(product->getValue() / m1->getValue(), this->getName());
}
if (m2->hasValue() && product->hasValue()) {
m1->setValue(product->getValue() / m2->getValue(), this->getName());
}
}
void Multiplier::informAboutNoValue() {
m1->forgetValue(this->getName());
m2->forgetValue(this->getName());
product->forgetValue(this->getName());
informAboutValue();
}