-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀 Merge pull request #28 from epitech-mirroring/22-refactor-components
♻️ Refactored components to allow "composed" one
- Loading branch information
Showing
6 changed files
with
120 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** NanoTekSpice | ||
** File description: | ||
** No file there , just an epitech header example . | ||
** You can even have multiple lines if you want ! | ||
*/ | ||
|
||
#include "Composed4071Component.hpp" | ||
#include "OrComponent.hpp" | ||
|
||
using namespace nts::Components; | ||
|
||
Composed4071Component::Composed4071Component(): ComposedComponent(14, 4) | ||
{ | ||
_internal["A"] = new OrComponent(); | ||
_internal["B"] = new OrComponent(); | ||
_internal["C"] = new OrComponent(); | ||
_internal["D"] = new OrComponent(); | ||
this->setPinMode(3, PinMode::OUTPUT); | ||
this->setPinMode(4, PinMode::OUTPUT); | ||
this->setPinMode(10, PinMode::OUTPUT); | ||
this->setPinMode(11, PinMode::OUTPUT); | ||
this->setLink(1, *_internal["A"], 1); | ||
this->setLink(2, *_internal["A"], 2); | ||
this->setLink(5, *_internal["B"], 1); | ||
this->setLink(6, *_internal["B"], 2); | ||
this->setLink(8, *_internal["C"], 1); | ||
this->setLink(9, *_internal["C"], 2); | ||
this->setLink(12, *_internal["D"], 1); | ||
this->setLink(13, *_internal["D"], 2); | ||
this->setLink(3, *_internal["A"], 3); | ||
this->setLink(4, *_internal["B"], 3); | ||
this->setLink(10, *_internal["C"], 3); | ||
this->setLink(11, *_internal["D"], 3); | ||
} | ||
|
||
nts::Tristate Composed4071Component::compute(std::size_t pin) | ||
{ | ||
if (pin == 3) | ||
return _internal["A"]->compute(3); | ||
if (pin == 4) | ||
return _internal["B"]->compute(3); | ||
if (pin == 10) | ||
return _internal["C"]->compute(3); | ||
if (pin == 11) | ||
return _internal["D"]->compute(3); | ||
return UNDEFINED; | ||
} | ||
|
||
Composed4071Component *Composed4071Component::clone() const | ||
{ | ||
return new Composed4071Component(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** NanoTekSpice | ||
** File description: | ||
** No file there , just an epitech header example . | ||
** You can even have multiple lines if you want ! | ||
*/ | ||
|
||
#pragma once | ||
#include "ComposedComponent.hpp" | ||
|
||
namespace nts::Components { | ||
class Composed4071Component: public ComposedComponent { | ||
public: | ||
Composed4071Component(); | ||
~Composed4071Component() override = default; | ||
Tristate compute(std::size_t pin) override; | ||
[[nodiscard]] Composed4071Component *clone() const override; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** NanoTekSpice | ||
** File description: | ||
** No file there , just an epitech header example . | ||
** You can even have multiple lines if you want ! | ||
*/ | ||
|
||
#include "ComposedComponent.hpp" | ||
|
||
using namespace nts::Components; | ||
|
||
ComposedComponent::ComposedComponent(std::size_t nbPins, std::size_t nbInternals) : AbstractComponent(nbPins) { | ||
this->_internal.reserve(nbInternals); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** NanoTekSpice | ||
** File description: | ||
** No file there , just an epitech header example . | ||
** You can even have multiple lines if you want ! | ||
*/ | ||
|
||
#pragma once | ||
#include "AbstractComponent.hpp" | ||
#include <unordered_map> | ||
|
||
namespace nts::Components { | ||
class ComposedComponent: public AbstractComponent { | ||
protected: | ||
std::unordered_map<std::string, IComponent *> _internal; | ||
|
||
ComposedComponent(std::size_t nbPins, std::size_t nbInternals); | ||
public: | ||
~ComposedComponent() override = default; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters