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 60760f4 commit 93cfb45
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ PARSER = $(PARSER_P)Parser.cpp \
$(PARSER_P)Create.cpp \

ERROR_P = $(SRC_P)errors/
ERROR = $(ERROR_P)ErrorParser.cpp
ERROR = $(ERROR_P)Error.cpp

CMD_P = $(SRC_P)commands/
CMD = $(CMD_P)Commands.cpp \
Expand Down
2 changes: 1 addition & 1 deletion include/AComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# include "Pin.hpp"
# include "Tristate.hpp"

# include "ErrorParser.hpp"
# include "Error.hpp"

namespace nts
{
Expand Down
10 changes: 5 additions & 5 deletions include/ErrorParser.hpp → include/Error.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#ifndef ERRORPARSER_HPP_
# define ERRORPARSER_HPP_
#ifndef ERROR_HPP_
# define ERROR_HPP_

# include <string>
# include <iostream>
# include <exception>

class ErrorParser : public std::exception
class Error : public std::exception
{
public:
ErrorParser(const std::string & = "Unknow error.", const std::string & = "Unknow") noexcept;
~ErrorParser() noexcept {};
Error(const std::string & = "Unknow error.", const std::string & = "Unknow") noexcept;
~Error() noexcept {};
std::string const &getIndicator() const noexcept;
const char * what() const noexcept;

Expand Down
2 changes: 1 addition & 1 deletion include/Pin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# include <iostream>

#include "IComponent.hpp"
#include "ErrorParser.hpp"
#include "Error.hpp"

namespace nts
{
Expand Down
8 changes: 4 additions & 4 deletions src/commands/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ int launch(std::map<std::string, nts::IComponent *> chipsets_m, std::vector<nts:
else if (match[2] == "0")
(*it).second->Compute(3);
else
throw ErrorParser("Invalid value.", match[2]);
throw Error("Invalid value.", match[2]);
}
else
throw ErrorParser("Component is not an variable input.", match[1]);
throw Error("Component is not an variable input.", match[1]);
}
else
throw ErrorParser("No component with this name.", match[1]);
throw Error("No component with this name.", match[1]);
}
else
throw ErrorParser("Unknown command.", command);
throw Error("Unknown command.", command);
}
}
2 changes: 1 addition & 1 deletion src/components/Pin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace nts
{
if (this->component)
return (this->component->Compute(this->target_pin));
throw ErrorParser("Attempt to compute a linkless pin.", "FLEMME DE DIRE OU");
throw Error("Attempt to compute a linkless pin.", "FLEMME DE DIRE OU");
}

Pin::Mode Pin::getMode() const {return (this->mode);}
Expand Down
12 changes: 6 additions & 6 deletions src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ void set_inputs(std::map<std::string, nts::IComponent *> chipsets_m, char **arg,
else if (match[2] == "0")
(*it).second->Compute(3);
else
throw ErrorParser("Invalid value.", match[2]);
throw Error("Invalid value.", match[2]);
input--;
}
else
throw ErrorParser("Component is not an variable input.", match[1]);
throw Error("Component is not an variable input.", match[1]);
}
else
throw ErrorParser("No component with this name.", match[1]);
throw Error("No component with this name.", match[1]);
}
else
throw ErrorParser("Invalid argument.", arg[i]);
throw Error("Invalid argument.", arg[i]);
i++;
}
if (input)
throw ErrorParser("Every inputs werent set", "arguments");
throw Error("Every inputs werent set", "arguments");
}

int core(int ac, char **av)
Expand All @@ -74,7 +74,7 @@ int core(int ac, char **av)
set_inputs(chipsets_m, &av[2], ac - 2);
launch(chipsets_m, chipsets_v);
}
catch (const ErrorParser &error)
catch (const Error &error)
{
std::cerr << "\x1b[31mAn error occured\x1b[0m: " << error.what() << " \x1b[31mat\x1b[0m: " << error.getIndicator() << std::endl;
return (1);
Expand Down
15 changes: 15 additions & 0 deletions src/errors/Error.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "Error.hpp"

Error::Error(const std::string &message, const std::string &indicator) noexcept : _message(message), _indicator(indicator)
{
}

const char *Error::what() const noexcept
{
return (this->_message.c_str());
}

std::string const &Error::getIndicator() const noexcept
{
return (this->_indicator);
}
15 changes: 0 additions & 15 deletions src/errors/ErrorParser.cpp

This file was deleted.

4 changes: 2 additions & 2 deletions src/parser/Create.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Create.hpp"
#include "ErrorParser.hpp"
#include "Error.hpp"

nts::IComponent * Create::createComponent(const std::string &type, const std::string &value)
{
Expand Down Expand Up @@ -28,6 +28,6 @@ nts::IComponent * Create::createComponent(const std::string &type, const std::st
static std::map<std::string, std::function<nts::IComponent *(const std::string &)>>::iterator it;
if ((it = data.find(type)) != data.end())
return (it->second(value));
throw ErrorParser("Unknown component type.", type);
throw Error("Unknown component type.", type);
return (NULL);
}
14 changes: 7 additions & 7 deletions src/parser/Parser.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Parser.hpp"
#include "ErrorParser.hpp"
#include "Error.hpp"

bool is_non_empty(std::string &line)
{
Expand Down Expand Up @@ -30,7 +30,7 @@ void set_links(std::stringstream &str, std::map<std::string, nts::IComponent *>
// std::cout << "Link set between chipsets \x1b[31m" << match[1] << "\x1b[0m and \x1b[31m" << match[3]<< "\x1b[0m with pins \x1b[32m" << match[2] << "\x1b[0m and \x1b[32m" << match[4] << "\x1b[0m." << std::endl;
}
else
throw ErrorParser("Unknown component name.", ((it1 == chipsets.end()) ? (match[1]) : (match[3])));
throw Error("Unknown component name.", ((it1 == chipsets.end()) ? (match[1]) : (match[3])));
}
}

Expand All @@ -50,12 +50,12 @@ std::map<std::string, nts::IComponent *> create_chipset(std::stringstream &str,
chipsets[match[2]] = cmpt;
}
else
throw ErrorParser("Several components share the same name.", match[2]);
throw Error("Several components share the same name.", match[2]);
}
else
throw ErrorParser("Syntax error.", line);
throw Error("Syntax error.", line);
if (line != ".links:")
throw ErrorParser("No links section.", file);
throw Error("No links section.", file);
set_links(str, chipsets);
return (chipsets);
}
Expand All @@ -80,9 +80,9 @@ std::map<std::string, nts::IComponent *> parser(const char *file)
if (line == ".chipsets:")
return (create_chipset(str, file));
else
throw ErrorParser("No chipset section.", file);
throw Error("No chipset section.", file);
}
else
throw ErrorParser("No such file.", file);
throw Error("No such file.", file);
return (*new std::map<std::string, nts::IComponent *>);
}
17 changes: 17 additions & 0 deletions test.nts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.chipsets:
output s
4081 gate
input b
input a

.links:
s:1 gate:3

gate:1 a:1
gate:2 b:1
gate:3 s:1

b:1 gate:2

a:1 gate:1

0 comments on commit 93cfb45

Please sign in to comment.