From 93cfb45fe3c1e66cd1a607ce0ce195332bc8972b Mon Sep 17 00:00:00 2001 From: charlie Date: Sun, 5 Mar 2017 16:43:41 +0100 Subject: [PATCH] Push --- Makefile | 2 +- include/AComponent.hpp | 2 +- include/{ErrorParser.hpp => Error.hpp} | 10 +++++----- include/Pin.hpp | 2 +- src/commands/Commands.cpp | 8 ++++---- src/components/Pin.cpp | 2 +- src/core.cpp | 12 ++++++------ src/errors/Error.cpp | 15 +++++++++++++++ src/errors/ErrorParser.cpp | 15 --------------- src/parser/Create.cpp | 4 ++-- src/parser/Parser.cpp | 14 +++++++------- test.nts | 17 +++++++++++++++++ 12 files changed, 60 insertions(+), 43 deletions(-) rename include/{ErrorParser.hpp => Error.hpp} (53%) create mode 100644 src/errors/Error.cpp delete mode 100644 src/errors/ErrorParser.cpp create mode 100644 test.nts diff --git a/Makefile b/Makefile index ad52625..971f8b3 100644 --- a/Makefile +++ b/Makefile @@ -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 \ diff --git a/include/AComponent.hpp b/include/AComponent.hpp index c790bff..84a56e0 100644 --- a/include/AComponent.hpp +++ b/include/AComponent.hpp @@ -9,7 +9,7 @@ # include "Pin.hpp" # include "Tristate.hpp" -# include "ErrorParser.hpp" +# include "Error.hpp" namespace nts { diff --git a/include/ErrorParser.hpp b/include/Error.hpp similarity index 53% rename from include/ErrorParser.hpp rename to include/Error.hpp index e0227bc..2da3b98 100644 --- a/include/ErrorParser.hpp +++ b/include/Error.hpp @@ -1,15 +1,15 @@ -#ifndef ERRORPARSER_HPP_ -# define ERRORPARSER_HPP_ +#ifndef ERROR_HPP_ +# define ERROR_HPP_ # include # include # include -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; diff --git a/include/Pin.hpp b/include/Pin.hpp index ff622a7..fafb82e 100644 --- a/include/Pin.hpp +++ b/include/Pin.hpp @@ -5,7 +5,7 @@ # include #include "IComponent.hpp" -#include "ErrorParser.hpp" +#include "Error.hpp" namespace nts { diff --git a/src/commands/Commands.cpp b/src/commands/Commands.cpp index 000d69e..1e36ff2 100644 --- a/src/commands/Commands.cpp +++ b/src/commands/Commands.cpp @@ -86,15 +86,15 @@ int launch(std::map chipsets_m, std::vectorCompute(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); } } \ No newline at end of file diff --git a/src/components/Pin.cpp b/src/components/Pin.cpp index 74c7174..8ecebce 100644 --- a/src/components/Pin.cpp +++ b/src/components/Pin.cpp @@ -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);} diff --git a/src/core.cpp b/src/core.cpp index a36a118..7b77785 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -43,21 +43,21 @@ void set_inputs(std::map 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) @@ -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); diff --git a/src/errors/Error.cpp b/src/errors/Error.cpp new file mode 100644 index 0000000..6ee7dc4 --- /dev/null +++ b/src/errors/Error.cpp @@ -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); +} \ No newline at end of file diff --git a/src/errors/ErrorParser.cpp b/src/errors/ErrorParser.cpp deleted file mode 100644 index 25d80be..0000000 --- a/src/errors/ErrorParser.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "ErrorParser.hpp" - -ErrorParser::ErrorParser(const std::string &message, const std::string &indicator) noexcept : _message(message), _indicator(indicator) -{ -} - -const char *ErrorParser::what() const noexcept -{ - return (this->_message.c_str()); -} - -std::string const &ErrorParser::getIndicator() const noexcept -{ - return (this->_indicator); -} \ No newline at end of file diff --git a/src/parser/Create.cpp b/src/parser/Create.cpp index 95ca3fd..48e0871 100644 --- a/src/parser/Create.cpp +++ b/src/parser/Create.cpp @@ -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) { @@ -28,6 +28,6 @@ nts::IComponent * Create::createComponent(const std::string &type, const std::st static std::map>::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); } diff --git a/src/parser/Parser.cpp b/src/parser/Parser.cpp index fbaf548..5cf65d1 100644 --- a/src/parser/Parser.cpp +++ b/src/parser/Parser.cpp @@ -1,5 +1,5 @@ #include "Parser.hpp" -#include "ErrorParser.hpp" +#include "Error.hpp" bool is_non_empty(std::string &line) { @@ -30,7 +30,7 @@ void set_links(std::stringstream &str, std::map // 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]))); } } @@ -50,12 +50,12 @@ std::map 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); } @@ -80,9 +80,9 @@ std::map 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); } diff --git a/test.nts b/test.nts new file mode 100644 index 0000000..99562be --- /dev/null +++ b/test.nts @@ -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 +