diff --git a/.vscode/settings.json b/.vscode/settings.json index b99c3f3..e8c7813 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -26,6 +26,8 @@ "exception": "cpp", "initializer_list": "cpp", "type_traits": "cpp", - "algorithm": "cpp" + "algorithm": "cpp", + "tuple": "cpp", + "utility": "cpp" } } \ No newline at end of file diff --git a/include/AComponent.hpp b/include/AComponent.hpp index 84a56e0..dfd2e9d 100644 --- a/include/AComponent.hpp +++ b/include/AComponent.hpp @@ -41,6 +41,7 @@ namespace nts void setName(const std::string &); void setArg(const std::string &); const std::string *save_pins() const; + nts::Tristate reset_pins(); protected: Type type; diff --git a/src/commands/Commands.cpp b/src/commands/Commands.cpp index 1e36ff2..a33181d 100644 --- a/src/commands/Commands.cpp +++ b/src/commands/Commands.cpp @@ -34,8 +34,7 @@ void dump(std::vector chipsets) void simulate(std::vector chipsets_v) { for(std::vector::iterator it = chipsets_v.begin(); it != chipsets_v.end(); ++it ) - if (dynamic_cast(*it)->getType() == nts::AComponent::Type::T) - (*it)->Compute(0); + (*it)->Compute(0); } void display(std::vector chipsets) diff --git a/src/components/AComponent.cpp b/src/components/AComponent.cpp index f28ae0c..215eabf 100644 --- a/src/components/AComponent.cpp +++ b/src/components/AComponent.cpp @@ -14,6 +14,17 @@ namespace nts const std::vector &AComponent::getPins() const {return (this->pins);} + nts::Tristate AComponent::reset_pins() + { + size_t i = 0; + while (i < this->pins.size()) + { + this->pins[i].setState(UNDEFINED); + i++; + } + return (UNDEFINED); + } + const std::string *AComponent::save_pins() const { size_t i = 0; diff --git a/src/components/Clock.cpp b/src/components/Clock.cpp index 2ad1563..bb7e45f 100644 --- a/src/components/Clock.cpp +++ b/src/components/Clock.cpp @@ -12,10 +12,12 @@ namespace nts nts::Tristate Clock::Compute(std::size_t pin_num_this) { - if (pin_num_this != 1) + if (pin_num_this != 1) { if (pin_num_this == 0) this->pins[0].setState(!this->pins[0].getState()); + else + throw Error ("Attempt to compute an invalid pin number", this->name + " " + std::to_string(pin_num_this)); return (UNDEFINED); } return (this->pins[0].getState()); diff --git a/src/components/False.cpp b/src/components/False.cpp index ec35bc6..8a0ef1f 100644 --- a/src/components/False.cpp +++ b/src/components/False.cpp @@ -12,8 +12,10 @@ namespace nts nts::Tristate False::Compute(std::size_t pin_num_this) { - if (pin_num_this != 1) + if (pin_num_this == 0) return (UNDEFINED); + if (pin_num_this != 1) + throw Error ("Attempt to compute an invalid pin number", this->name + " " + std::to_string(pin_num_this)); return (this->pins[0].getState()); } diff --git a/src/components/Input.cpp b/src/components/Input.cpp index 8076196..323c96e 100644 --- a/src/components/Input.cpp +++ b/src/components/Input.cpp @@ -12,12 +12,16 @@ namespace nts nts::Tristate Input::Compute(std::size_t pin_num_this) { - if (pin_num_this != 1) + if (pin_num_this == 0) + return (UNDEFINED); + if (pin_num_this != 1) { if (pin_num_this == 2) this->pins[0].setState(TRUE); else if (pin_num_this == 3) this->pins[0].setState(FALSE); + else + throw Error ("Attempt to compute an invalid pin number", this->name + " " + std::to_string(pin_num_this)); return (UNDEFINED); } return (this->pins[0].getState()); diff --git a/src/components/Output.cpp b/src/components/Output.cpp index 43b40f9..56ff11f 100644 --- a/src/components/Output.cpp +++ b/src/components/Output.cpp @@ -11,8 +11,10 @@ namespace nts nts::Tristate Output::Compute(std::size_t pin_num_this) { + if (pin_num_this == 0) + return (this->reset_pins()); if (pin_num_this != 1) - return (UNDEFINED); + throw Error ("Attempt to compute an invalid pin number", this->name + " " + std::to_string(pin_num_this)); return (this->pins[0].compute()); } diff --git a/src/components/Pin.cpp b/src/components/Pin.cpp index 8ecebce..be66a36 100644 --- a/src/components/Pin.cpp +++ b/src/components/Pin.cpp @@ -45,8 +45,13 @@ namespace nts nts::Tristate Pin::compute() { + if (this->state != UNDEFINED) + return (this->state); if (this->component) - return (this->component->Compute(this->target_pin)); + { + this->state = this->component->Compute(this->target_pin); + return (this->state); + } throw Error("Attempt to compute a linkless pin.", "FLEMME DE DIRE OU"); } diff --git a/src/components/True.cpp b/src/components/True.cpp index c925a43..640141c 100644 --- a/src/components/True.cpp +++ b/src/components/True.cpp @@ -12,8 +12,10 @@ namespace nts nts::Tristate True::Compute(std::size_t pin_num_this) { - if (pin_num_this != 1) + if (pin_num_this == 0) return (UNDEFINED); + if (pin_num_this != 1) + throw Error ("Attempt to compute an invalid pin number", this->name + " " + std::to_string(pin_num_this)); return (this->pins[0].getState()); } diff --git a/src/components/c4001.cpp b/src/components/c4001.cpp index 33ea7b6..a416303 100644 --- a/src/components/c4001.cpp +++ b/src/components/c4001.cpp @@ -24,8 +24,10 @@ namespace nts nts::Tristate c4001::Compute(std::size_t pin_num_this) { + if (pin_num_this == 0) + return (this->reset_pins()); if (pin_num_this < 1 || pin_num_this > 13 || pin_num_this == 7) - return (UNDEFINED); + throw Error ("Attempt to compute an invalid pin number", this->name + " " + std::to_string(pin_num_this)); pin_num_this--; if (this->pins[pin_num_this].getMode() == Pin::I) return (this->pins[pin_num_this].compute()); diff --git a/src/components/c4008.cpp b/src/components/c4008.cpp index 73554de..b0097fa 100644 --- a/src/components/c4008.cpp +++ b/src/components/c4008.cpp @@ -26,8 +26,10 @@ namespace nts nts::Tristate c4008::Compute(std::size_t pin_num_this) { + if (pin_num_this == 0) + return (this->reset_pins()); if (pin_num_this < 1 || pin_num_this > 16 || pin_num_this == 8) - return (UNDEFINED); + throw Error ("Attempt to compute an invalid pin number", this->name + " " + std::to_string(pin_num_this)); pin_num_this--; if (this->pins[pin_num_this].getMode() == Pin::I) return (this->pins[pin_num_this].compute()); diff --git a/src/components/c4011.cpp b/src/components/c4011.cpp index 43c915a..749c979 100644 --- a/src/components/c4011.cpp +++ b/src/components/c4011.cpp @@ -24,8 +24,10 @@ namespace nts nts::Tristate c4011::Compute(std::size_t pin_num_this) { + if (pin_num_this == 0) + return (this->reset_pins()); if (pin_num_this < 1 || pin_num_this > 13 || pin_num_this == 7) - return (UNDEFINED); + throw Error ("Attempt to compute an invalid pin number", this->name + " " + std::to_string(pin_num_this)); pin_num_this--; if (this->pins[pin_num_this].getMode() == Pin::I) return (this->pins[pin_num_this].compute()); diff --git a/src/components/c4013.cpp b/src/components/c4013.cpp index 94b932f..c8facdf 100644 --- a/src/components/c4013.cpp +++ b/src/components/c4013.cpp @@ -24,8 +24,10 @@ namespace nts nts::Tristate c4013::Compute(std::size_t pin_num_this) { + if (pin_num_this == 0) + return (this->reset_pins()); if (pin_num_this < 1 || pin_num_this > 13 || pin_num_this == 7) - return (UNDEFINED); + throw Error ("Attempt to compute an invalid pin number", this->name + " " + std::to_string(pin_num_this)); pin_num_this--; if (this->pins[pin_num_this].getMode() == Pin::I) return (this->pins[pin_num_this].compute()); diff --git a/src/components/c4017.cpp b/src/components/c4017.cpp index ca02e06..4c83d29 100644 --- a/src/components/c4017.cpp +++ b/src/components/c4017.cpp @@ -26,8 +26,10 @@ namespace nts nts::Tristate c4017::Compute(std::size_t pin_num_this) { + if (pin_num_this == 0) + return (this->reset_pins()); if (pin_num_this < 1 || pin_num_this > 15 || pin_num_this == 8) - return (UNDEFINED); + throw Error ("Attempt to compute an invalid pin number", this->name + " " + std::to_string(pin_num_this)); pin_num_this--; if (this->pins[pin_num_this].getMode() == Pin::I) return (this->pins[pin_num_this].compute()); diff --git a/src/components/c4030.cpp b/src/components/c4030.cpp index 349fc36..d7edde4 100644 --- a/src/components/c4030.cpp +++ b/src/components/c4030.cpp @@ -24,8 +24,10 @@ namespace nts nts::Tristate c4030::Compute(std::size_t pin_num_this) { + if (pin_num_this == 0) + return (this->reset_pins()); if (pin_num_this < 1 || pin_num_this > 13 || pin_num_this == 7) - return (UNDEFINED); + throw Error ("Attempt to compute an invalid pin number", this->name + " " + std::to_string(pin_num_this)); pin_num_this--; if (this->pins[pin_num_this].getMode() == Pin::I) return (this->pins[pin_num_this].compute()); diff --git a/src/components/c4040.cpp b/src/components/c4040.cpp index 3a2bcef..65fdc18 100644 --- a/src/components/c4040.cpp +++ b/src/components/c4040.cpp @@ -26,8 +26,10 @@ namespace nts nts::Tristate c4040::Compute(std::size_t pin_num_this) { + if (pin_num_this == 0) + return (this->reset_pins()); if (pin_num_this < 1 || pin_num_this > 15 || pin_num_this == 8) - return (UNDEFINED); + throw Error ("Attempt to compute an invalid pin number", this->name + " " + std::to_string(pin_num_this)); pin_num_this--; if (this->pins[pin_num_this].getMode() == Pin::I) return (this->pins[pin_num_this].compute()); diff --git a/src/components/c4069.cpp b/src/components/c4069.cpp index f3f6c6e..454e446 100644 --- a/src/components/c4069.cpp +++ b/src/components/c4069.cpp @@ -24,8 +24,10 @@ namespace nts nts::Tristate c4069::Compute(std::size_t pin_num_this) { - if (pin_num_this < 1 || pin_num_this > 13 || pin_num_this == 7) - return (UNDEFINED); + if (pin_num_this == 0) + return (this->reset_pins()); + if (pin_num_this < 1 || pin_num_this > 13 || pin_num_this == 7) + throw Error ("Attempt to compute an invalid pin number", this->name + " " + std::to_string(pin_num_this)); pin_num_this--; if (this->pins[pin_num_this].getMode() == Pin::I) return (this->pins[pin_num_this].compute()); diff --git a/src/components/c4071.cpp b/src/components/c4071.cpp index c871568..6faf6d9 100644 --- a/src/components/c4071.cpp +++ b/src/components/c4071.cpp @@ -24,8 +24,10 @@ namespace nts nts::Tristate c4071::Compute(std::size_t pin_num_this) { + if (pin_num_this == 0) + return (this->reset_pins()); if (pin_num_this < 1 || pin_num_this > 13 || pin_num_this == 7) - return (UNDEFINED); + throw Error ("Attempt to compute an invalid pin number", this->name + " " + std::to_string(pin_num_this)); pin_num_this--; if (this->pins[pin_num_this].getMode() == Pin::I) return (this->pins[pin_num_this].compute()); diff --git a/src/components/c4081.cpp b/src/components/c4081.cpp index 5fd4264..cc37412 100644 --- a/src/components/c4081.cpp +++ b/src/components/c4081.cpp @@ -24,8 +24,10 @@ namespace nts nts::Tristate c4081::Compute(std::size_t pin_num_this) { - if (pin_num_this < 1 || pin_num_this > 13 || pin_num_this == 7) - return (UNDEFINED); + if (pin_num_this == 0) + return (this->reset_pins()); + if (pin_num_this < 1 || pin_num_this > 13 || pin_num_this == 7) + throw Error ("Attempt to compute an invalid pin number", this->name + " " + std::to_string(pin_num_this)); pin_num_this--; if (this->pins[pin_num_this].getMode() == Pin::I) return (this->pins[pin_num_this].compute()); diff --git a/src/components/c4514.cpp b/src/components/c4514.cpp index 92c0bef..fa65ad6 100644 --- a/src/components/c4514.cpp +++ b/src/components/c4514.cpp @@ -34,9 +34,11 @@ namespace nts nts::Tristate c4514::Compute(std::size_t pin_num_this) { + if (pin_num_this == 0) + return (this->reset_pins()); if (pin_num_this < 1 || pin_num_this > 23 || pin_num_this == 12) - return (UNDEFINED); - pin_num_this--; + throw Error ("Attempt to compute an invalid pin number", this->name + " " + std::to_string(pin_num_this)); + pin_num_this--; if (this->pins[pin_num_this].getMode() == Pin::I) return (this->pins[pin_num_this].compute()); else