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 c4d2129 commit 60760f4
Show file tree
Hide file tree
Showing 41 changed files with 155 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
5 changes: 5 additions & 0 deletions include/AComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pin> &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<Pin> pins;
};
}
Expand Down
1 change: 1 addition & 0 deletions include/Clock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}

Expand Down
1 change: 1 addition & 0 deletions include/Commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
#include "AComponent.hpp"

int launch(std::map<std::string, nts::IComponent *>, std::vector<nts::IComponent *>);
void save(const std::string &file, std::vector<nts::IComponent *> components);

#endif
1 change: 1 addition & 0 deletions include/False.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}

Expand Down
1 change: 1 addition & 0 deletions include/Input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}

Expand Down
1 change: 1 addition & 0 deletions include/Output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}

Expand Down
1 change: 1 addition & 0 deletions include/Pin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions include/True.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}

Expand Down
1 change: 1 addition & 0 deletions include/c4001.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}

Expand Down
1 change: 1 addition & 0 deletions include/c4008.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}

Expand Down
1 change: 1 addition & 0 deletions include/c4011.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}

Expand Down
1 change: 1 addition & 0 deletions include/c4013.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}

Expand Down
1 change: 1 addition & 0 deletions include/c4017.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions include/c4030.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions include/c4040.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions include/c4069.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions include/c4071.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions include/c4081.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions include/c4514.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/commands/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ int launch(std::map<std::string, nts::IComponent *> chipsets_m, std::vector<nts:
dump(chipsets_v);
else if (command == "pony")
pony();
else if (command == "save")
save("test", chipsets_v);
else if (std::regex_search(command, match, rgx))
{
std::map<std::string, nts::IComponent *>::iterator it;
Expand Down
13 changes: 13 additions & 0 deletions src/commands/Save.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "Save.hpp"

void save(const std::string &file, std::vector<nts::IComponent *> components)
{
std::ofstream save(file + ".nts");

save << ".chipsets:" << std::endl;
for (auto it = components.begin(); it != components.end(); ++it)
save << dynamic_cast<nts::AComponent *>(*it)->save() << std::endl;
save << std::endl << ".links:" << std::endl;
for (auto it = components.begin(); it != components.end(); ++it)
save << *dynamic_cast<nts::AComponent *>(*it)->save_pins() << std::endl;
}
11 changes: 11 additions & 0 deletions src/commands/Save.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef SAVE_HPP_
# define SAVE_HPP_

# include <string>
# include <iostream>
# include <fstream>
# include <vector>

# include "../../include/AComponent.hpp"

#endif
17 changes: 17 additions & 0 deletions src/components/AComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pin> &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<AComponent &>(this->pins[i].getComponent()).getName() + ":" + std::to_string(this->pins[i].getTargetPin()) + "\n";
i++;
}
return (save);
}
}
5 changes: 5 additions & 0 deletions src/components/Clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down
5 changes: 5 additions & 0 deletions src/components/False.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down
5 changes: 5 additions & 0 deletions src/components/Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down
5 changes: 5 additions & 0 deletions src/components/Output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down
7 changes: 7 additions & 0 deletions src/components/Pin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);}
Expand Down
5 changes: 5 additions & 0 deletions src/components/True.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down
5 changes: 5 additions & 0 deletions src/components/c4001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down
5 changes: 5 additions & 0 deletions src/components/c4008.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down
5 changes: 5 additions & 0 deletions src/components/c4011.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down
5 changes: 5 additions & 0 deletions src/components/c4013.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down
5 changes: 5 additions & 0 deletions src/components/c4017.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down
5 changes: 5 additions & 0 deletions src/components/c4030.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down
Loading

0 comments on commit 60760f4

Please sign in to comment.