Skip to content

Commit

Permalink
Push
Browse files Browse the repository at this point in the history
  • Loading branch information
clecat committed Mar 5, 2017
1 parent 93cfb45 commit b69edbb
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 23 deletions.
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"exception": "cpp",
"initializer_list": "cpp",
"type_traits": "cpp",
"algorithm": "cpp"
"algorithm": "cpp",
"tuple": "cpp",
"utility": "cpp"
}
}
1 change: 1 addition & 0 deletions include/AComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/commands/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ void dump(std::vector<nts::IComponent *> chipsets)
void simulate(std::vector<nts::IComponent *> chipsets_v)
{
for(std::vector<nts::IComponent *>::iterator it = chipsets_v.begin(); it != chipsets_v.end(); ++it )
if (dynamic_cast<nts::AComponent *>(*it)->getType() == nts::AComponent::Type::T)
(*it)->Compute(0);
(*it)->Compute(0);
}

void display(std::vector<nts::IComponent *> chipsets)
Expand Down
11 changes: 11 additions & 0 deletions src/components/AComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ namespace nts

const std::vector<Pin> &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;
Expand Down
4 changes: 3 additions & 1 deletion src/components/Clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 3 additions & 1 deletion src/components/False.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
6 changes: 5 additions & 1 deletion src/components/Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 3 additions & 1 deletion src/components/Output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
7 changes: 6 additions & 1 deletion src/components/Pin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
4 changes: 3 additions & 1 deletion src/components/True.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
4 changes: 3 additions & 1 deletion src/components/c4001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 3 additions & 1 deletion src/components/c4008.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 3 additions & 1 deletion src/components/c4011.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 3 additions & 1 deletion src/components/c4013.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 3 additions & 1 deletion src/components/c4017.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 3 additions & 1 deletion src/components/c4030.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 3 additions & 1 deletion src/components/c4040.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
6 changes: 4 additions & 2 deletions src/components/c4069.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 3 additions & 1 deletion src/components/c4071.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
6 changes: 4 additions & 2 deletions src/components/c4081.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
6 changes: 4 additions & 2 deletions src/components/c4514.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b69edbb

Please sign in to comment.