diff --git a/Makefile b/Makefile index fb8cfaf..ad52625 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,8 @@ ERROR_P = $(SRC_P)errors/ ERROR = $(ERROR_P)ErrorParser.cpp CMD_P = $(SRC_P)commands/ -CMD = $(CMD_P)Commands.cpp +CMD = $(CMD_P)Commands.cpp \ + $(CMD_P)Save.cpp SRC_P = src/ SRC_L = $(SRC_P)core.cpp \ diff --git a/include/AComponent.hpp b/include/AComponent.hpp index c55528d..c790bff 100644 --- a/include/AComponent.hpp +++ b/include/AComponent.hpp @@ -31,16 +31,21 @@ namespace nts virtual void SetLink(std::size_t pin_num_this, nts::IComponent &component, std::size_t pin_num_target) = 0; virtual void Dump(void) const = 0; virtual ~AComponent(void) {} + virtual const std::string &save() const = 0; public: const std::string &getName() const; + const std::string &getArg() const; Type getType() const; const std::vector &getPins() const; void setName(const std::string &); + void setArg(const std::string &); + const std::string *save_pins() const; protected: Type type; std::string name; + std::string arg; std::vector pins; }; } diff --git a/include/Clock.hpp b/include/Clock.hpp index f3a3202..ba4013d 100644 --- a/include/Clock.hpp +++ b/include/Clock.hpp @@ -13,6 +13,7 @@ namespace nts virtual void SetLink(std::size_t pin_num_this, nts::IComponent &component, std::size_t pin_num_target); virtual void Dump(void) const; virtual ~Clock(void); + virtual const std::string &save() const; }; } diff --git a/include/Commands.hpp b/include/Commands.hpp index 63f0d39..f57568a 100644 --- a/include/Commands.hpp +++ b/include/Commands.hpp @@ -10,5 +10,6 @@ #include "AComponent.hpp" int launch(std::map, std::vector); +void save(const std::string &file, std::vector components); #endif \ No newline at end of file diff --git a/include/False.hpp b/include/False.hpp index 95c06e4..d55e8db 100644 --- a/include/False.hpp +++ b/include/False.hpp @@ -13,6 +13,7 @@ namespace nts virtual void SetLink(std::size_t pin_num_this, nts::IComponent &component, std::size_t pin_num_target); virtual void Dump(void) const; virtual ~False(void); + virtual const std::string &save() const; }; } diff --git a/include/Input.hpp b/include/Input.hpp index 4743f8c..32f83c4 100644 --- a/include/Input.hpp +++ b/include/Input.hpp @@ -13,6 +13,7 @@ namespace nts virtual void SetLink(std::size_t pin_num_this, nts::IComponent &component, std::size_t pin_num_target); virtual void Dump(void) const; virtual ~Input(void); + virtual const std::string &save() const; }; } diff --git a/include/Output.hpp b/include/Output.hpp index 3eb1bbf..7eb9bf7 100644 --- a/include/Output.hpp +++ b/include/Output.hpp @@ -13,6 +13,7 @@ namespace nts virtual void SetLink(std::size_t pin_num_this, nts::IComponent &component, std::size_t pin_num_target); virtual void Dump(void) const; virtual ~Output(void); + virtual const std::string &save() const; }; } diff --git a/include/Pin.hpp b/include/Pin.hpp index 1aa92da..ff622a7 100644 --- a/include/Pin.hpp +++ b/include/Pin.hpp @@ -33,6 +33,7 @@ namespace nts void setTarget(std::size_t); void setState(Tristate); void setMode(Mode); + bool isLinked() const; IComponent &getComponent() const; std::size_t getTargetPin() const; Tristate getState() const; diff --git a/include/True.hpp b/include/True.hpp index efd1910..602415a 100644 --- a/include/True.hpp +++ b/include/True.hpp @@ -13,6 +13,7 @@ namespace nts virtual void SetLink(std::size_t pin_num_this, nts::IComponent &component, std::size_t pin_num_target); virtual void Dump(void) const; virtual ~True(void); + virtual const std::string &save() const; }; } diff --git a/include/c4001.hpp b/include/c4001.hpp index abbee8a..018d85b 100644 --- a/include/c4001.hpp +++ b/include/c4001.hpp @@ -13,6 +13,7 @@ namespace nts virtual void SetLink(std::size_t pin_num_this, nts::IComponent &component, std::size_t pin_num_target); virtual void Dump(void) const; virtual ~c4001(void); + virtual const std::string &save() const; }; } diff --git a/include/c4008.hpp b/include/c4008.hpp index bd807d2..d31008b 100644 --- a/include/c4008.hpp +++ b/include/c4008.hpp @@ -13,6 +13,7 @@ namespace nts virtual void SetLink(std::size_t pin_num_this, nts::IComponent &component, std::size_t pin_num_target); virtual void Dump(void) const; virtual ~c4008(void); + virtual const std::string &save() const; }; } diff --git a/include/c4011.hpp b/include/c4011.hpp index 0547d14..c002512 100644 --- a/include/c4011.hpp +++ b/include/c4011.hpp @@ -13,6 +13,7 @@ namespace nts virtual void SetLink(std::size_t pin_num_this, nts::IComponent &component, std::size_t pin_num_target); virtual void Dump(void) const; virtual ~c4011(void); + virtual const std::string &save() const; }; } diff --git a/include/c4013.hpp b/include/c4013.hpp index d8b7932..dbd7bb0 100644 --- a/include/c4013.hpp +++ b/include/c4013.hpp @@ -13,6 +13,7 @@ namespace nts virtual void SetLink(std::size_t pin_num_this, nts::IComponent &component, std::size_t pin_num_target); virtual void Dump(void) const; virtual ~c4013(void); + virtual const std::string &save() const; }; } diff --git a/include/c4017.hpp b/include/c4017.hpp index ddbd837..71b556b 100644 --- a/include/c4017.hpp +++ b/include/c4017.hpp @@ -13,6 +13,7 @@ namespace nts virtual void SetLink(std::size_t pin_num_this, nts::IComponent &component, std::size_t pin_num_target); virtual void Dump(void) const; virtual ~c4017(void); + virtual const std::string &save() const; private: int value; diff --git a/include/c4030.hpp b/include/c4030.hpp index 9f4ac3d..7f3458c 100644 --- a/include/c4030.hpp +++ b/include/c4030.hpp @@ -13,6 +13,7 @@ namespace nts virtual void SetLink(std::size_t pin_num_this, nts::IComponent &component, std::size_t pin_num_target); virtual void Dump(void) const; virtual ~c4030(void); + virtual const std::string &save() const; }; } #endif \ No newline at end of file diff --git a/include/c4040.hpp b/include/c4040.hpp index f88490b..48d4abc 100644 --- a/include/c4040.hpp +++ b/include/c4040.hpp @@ -13,6 +13,7 @@ namespace nts virtual void SetLink(std::size_t pin_num_this, nts::IComponent &component, std::size_t pin_num_target); virtual void Dump(void) const; virtual ~c4040(void); + virtual const std::string &save() const; private: int value; diff --git a/include/c4069.hpp b/include/c4069.hpp index adfe1a7..e050dc0 100644 --- a/include/c4069.hpp +++ b/include/c4069.hpp @@ -13,6 +13,7 @@ namespace nts virtual void SetLink(std::size_t pin_num_this, nts::IComponent &component, std::size_t pin_num_target); virtual void Dump(void) const; virtual ~c4069(void); + virtual const std::string &save() const; }; } #endif \ No newline at end of file diff --git a/include/c4071.hpp b/include/c4071.hpp index a0dcb72..5c9f09b 100644 --- a/include/c4071.hpp +++ b/include/c4071.hpp @@ -13,6 +13,7 @@ namespace nts virtual void SetLink(std::size_t pin_num_this, nts::IComponent &component, std::size_t pin_num_target); virtual void Dump(void) const; virtual ~c4071(void); + virtual const std::string &save() const; }; } #endif \ No newline at end of file diff --git a/include/c4081.hpp b/include/c4081.hpp index def0513..c162140 100644 --- a/include/c4081.hpp +++ b/include/c4081.hpp @@ -13,6 +13,7 @@ namespace nts virtual void SetLink(std::size_t pin_num_this, nts::IComponent &component, std::size_t pin_num_target); virtual void Dump(void) const; virtual ~c4081(void); + virtual const std::string &save() const; }; } #endif \ No newline at end of file diff --git a/include/c4514.hpp b/include/c4514.hpp index 9349e6b..1439a9b 100644 --- a/include/c4514.hpp +++ b/include/c4514.hpp @@ -13,6 +13,7 @@ namespace nts virtual void SetLink(std::size_t pin_num_this, nts::IComponent &component, std::size_t pin_num_target); virtual void Dump(void) const; virtual ~c4514(void); + virtual const std::string &save() const; private: int value; diff --git a/src/commands/Commands.cpp b/src/commands/Commands.cpp index 879de6b..000d69e 100644 --- a/src/commands/Commands.cpp +++ b/src/commands/Commands.cpp @@ -72,6 +72,8 @@ int launch(std::map chipsets_m, std::vector::iterator it; diff --git a/src/commands/Save.cpp b/src/commands/Save.cpp new file mode 100644 index 0000000..9a64e86 --- /dev/null +++ b/src/commands/Save.cpp @@ -0,0 +1,13 @@ +#include "Save.hpp" + +void save(const std::string &file, std::vector components) +{ + std::ofstream save(file + ".nts"); + + save << ".chipsets:" << std::endl; + for (auto it = components.begin(); it != components.end(); ++it) + save << dynamic_cast(*it)->save() << std::endl; + save << std::endl << ".links:" << std::endl; + for (auto it = components.begin(); it != components.end(); ++it) + save << *dynamic_cast(*it)->save_pins() << std::endl; +} \ No newline at end of file diff --git a/src/commands/Save.hpp b/src/commands/Save.hpp new file mode 100644 index 0000000..c5ff9e8 --- /dev/null +++ b/src/commands/Save.hpp @@ -0,0 +1,11 @@ +#ifndef SAVE_HPP_ +# define SAVE_HPP_ + +# include +# include +# include +# include + +# include "../../include/AComponent.hpp" + +#endif \ No newline at end of file diff --git a/src/components/AComponent.cpp b/src/components/AComponent.cpp index 76ff685..f28ae0c 100644 --- a/src/components/AComponent.cpp +++ b/src/components/AComponent.cpp @@ -4,9 +4,26 @@ namespace nts { void AComponent::setName(const std::string &_name) {this->name = _name;} + void AComponent::setArg(const std::string &_arg) {this->arg = _arg;} + const std::string &AComponent::getName() const {return (this->name);} + const std::string &AComponent::getArg() const {return (this->arg);} + AComponent::Type AComponent::getType() const {return (this->type);} const std::vector &AComponent::getPins() const {return (this->pins);} + + const std::string *AComponent::save_pins() const + { + size_t i = 0; + std::string *save = new std::string(); + while (i < this->pins.size()) + { + if (this->pins[i].isLinked()) + *save += this->name + ":" + std::to_string(i + 1) + " " + dynamic_cast(this->pins[i].getComponent()).getName() + ":" + std::to_string(this->pins[i].getTargetPin()) + "\n"; + i++; + } + return (save); + } } \ No newline at end of file diff --git a/src/components/Clock.cpp b/src/components/Clock.cpp index 620364a..2ad1563 100644 --- a/src/components/Clock.cpp +++ b/src/components/Clock.cpp @@ -34,6 +34,11 @@ namespace nts std::cout << "Input " << this->name << std::endl; } + const std::string &Clock::save() const + { + return (*(new std::string ("clock " + this->name))); + } + Clock::~Clock(void) { } diff --git a/src/components/False.cpp b/src/components/False.cpp index 855411a..ec35bc6 100644 --- a/src/components/False.cpp +++ b/src/components/False.cpp @@ -30,6 +30,11 @@ namespace nts std::cout << "Input " << this->name << std::endl; } + const std::string &False::save() const + { + return (*(new std::string ("false " + this->name))); + } + False::~False(void) { } diff --git a/src/components/Input.cpp b/src/components/Input.cpp index 97b10ba..8076196 100644 --- a/src/components/Input.cpp +++ b/src/components/Input.cpp @@ -36,6 +36,11 @@ namespace nts std::cout << "Input " << this->name << std::endl; } + const std::string &Input::save() const + { + return (*(new std::string ("input " + this->name))); + } + Input::~Input(void) { } diff --git a/src/components/Output.cpp b/src/components/Output.cpp index 257bac7..43b40f9 100644 --- a/src/components/Output.cpp +++ b/src/components/Output.cpp @@ -29,6 +29,11 @@ namespace nts std::cout << "Output " << this->name << std::endl; } + const std::string &Output::save() const + { + return (*(new std::string ("output " + this->name))); + } + Output::~Output(void) { } diff --git a/src/components/Pin.cpp b/src/components/Pin.cpp index d2b0811..74c7174 100644 --- a/src/components/Pin.cpp +++ b/src/components/Pin.cpp @@ -30,6 +30,13 @@ namespace nts void Pin::setMode(Mode _mode) {this->mode = _mode;} + bool Pin::isLinked() const + { + if (this->component) + return (true); + return (false); + } + IComponent &Pin::getComponent() const {return (*this->component);} std::size_t Pin::getTargetPin() const {return (this->target_pin);} diff --git a/src/components/True.cpp b/src/components/True.cpp index b02e6d2..c925a43 100644 --- a/src/components/True.cpp +++ b/src/components/True.cpp @@ -30,6 +30,11 @@ namespace nts std::cout << "Input " << this->name << std::endl; } + const std::string &True::save() const + { + return (*(new std::string ("true " + this->name))); + } + True::~True(void) { } diff --git a/src/components/c4001.cpp b/src/components/c4001.cpp index 751fee7..33ea7b6 100644 --- a/src/components/c4001.cpp +++ b/src/components/c4001.cpp @@ -51,6 +51,11 @@ namespace nts std::cout << "Chipset " << this->name << std::endl; } + const std::string &c4001::save() const + { + return (*(new std::string ("4001 " + this->name))); + } + c4001::~c4001(void) { } diff --git a/src/components/c4008.cpp b/src/components/c4008.cpp index 6f8a9f1..73554de 100644 --- a/src/components/c4008.cpp +++ b/src/components/c4008.cpp @@ -75,6 +75,11 @@ namespace nts std::cout << "Chipset " << this->name << std::endl; } + const std::string &c4008::save() const + { + return (*(new std::string ("4008 " + this->name))); + } + c4008::~c4008(void) { } diff --git a/src/components/c4011.cpp b/src/components/c4011.cpp index e1a0b6d..43c915a 100644 --- a/src/components/c4011.cpp +++ b/src/components/c4011.cpp @@ -51,6 +51,11 @@ namespace nts std::cout << "Chipset " << this->name << std::endl; } + const std::string &c4011::save() const + { + return (*(new std::string ("4011 " + this->name))); + } + c4011::~c4011(void) { } diff --git a/src/components/c4013.cpp b/src/components/c4013.cpp index 49bc2df..94b932f 100644 --- a/src/components/c4013.cpp +++ b/src/components/c4013.cpp @@ -73,6 +73,11 @@ namespace nts std::cout << "Chipset " << this->name << std::endl; } + const std::string &c4013::save() const + { + return (*(new std::string ("4013 " + this->name))); + } + c4013::~c4013(void) { } diff --git a/src/components/c4017.cpp b/src/components/c4017.cpp index 57aef92..ca02e06 100644 --- a/src/components/c4017.cpp +++ b/src/components/c4017.cpp @@ -63,6 +63,11 @@ namespace nts std::cout << "Chipset " << this->name << std::endl; } + const std::string &c4017::save() const + { + return (*(new std::string ("4017 " + this->name))); + } + c4017::~c4017(void) { } diff --git a/src/components/c4030.cpp b/src/components/c4030.cpp index a0b0493..349fc36 100644 --- a/src/components/c4030.cpp +++ b/src/components/c4030.cpp @@ -53,6 +53,11 @@ namespace nts std::cout << "Chipset " << this->name << std::endl; } + const std::string &c4030::save() const + { + return (*(new std::string ("4030 " + this->name))); + } + c4030::~c4030(void) { } diff --git a/src/components/c4040.cpp b/src/components/c4040.cpp index 2151fec..3a2bcef 100644 --- a/src/components/c4040.cpp +++ b/src/components/c4040.cpp @@ -62,6 +62,11 @@ namespace nts std::cout << "Chipset " << this->name << std::endl; } + const std::string &c4040::save() const + { + return (*(new std::string ("4040 " + this->name))); + } + c4040::~c4040(void) { } diff --git a/src/components/c4069.cpp b/src/components/c4069.cpp index 7f79c03..f3f6c6e 100644 --- a/src/components/c4069.cpp +++ b/src/components/c4069.cpp @@ -55,6 +55,11 @@ namespace nts std::cout << "Chipset " << this->name << std::endl; } + const std::string &c4069::save() const + { + return (*(new std::string ("4069 " + this->name))); + } + c4069::~c4069(void) { } diff --git a/src/components/c4071.cpp b/src/components/c4071.cpp index 42d41bd..c871568 100644 --- a/src/components/c4071.cpp +++ b/src/components/c4071.cpp @@ -51,6 +51,11 @@ namespace nts std::cout << "Chipset " << this->name << std::endl; } + const std::string &c4071::save() const + { + return (*(new std::string ("4071 " + this->name))); + } + c4071::~c4071(void) { } diff --git a/src/components/c4081.cpp b/src/components/c4081.cpp index 9280f31..5fd4264 100644 --- a/src/components/c4081.cpp +++ b/src/components/c4081.cpp @@ -51,6 +51,11 @@ namespace nts std::cout << "Chipset " << this->name << std::endl; } + const std::string &c4081::save() const + { + return (*(new std::string ("4081 " + this->name))); + } + c4081::~c4081(void) { } diff --git a/src/components/c4514.cpp b/src/components/c4514.cpp index dced142..92c0bef 100644 --- a/src/components/c4514.cpp +++ b/src/components/c4514.cpp @@ -81,6 +81,11 @@ namespace nts std::cout << "Chipset " << this->name << std::endl; } + const std::string &c4514::save() const + { + return (*(new std::string ("4514 " + this->name))); + } + c4514::~c4514(void) { }