aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Exception.cpp23
-rw-r--r--Exception.h16
-rw-r--r--Parser.cpp19
-rw-r--r--Parser.h11
4 files changed, 41 insertions, 28 deletions
diff --git a/Exception.cpp b/Exception.cpp
new file mode 100644
index 0000000..52e30dc
--- /dev/null
+++ b/Exception.cpp
@@ -0,0 +1,23 @@
+#include "Exception.h"
+
+#include <cstdarg>
+#include <cstdio>
+
+Exception::Exception(const char * fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ size_t sz = vsnprintf(NULL, 0, fmt, args) + 1;
+ if (error != NULL) free(error);
+ error = (char *) malloc(sz);
+ vsnprintf(error, sz, fmt, args);
+ va_end(args);
+}
+
+Exception::~Exception() {
+ if (error != NULL)
+ free(error);
+}
+
+const char * Exception::what() {
+ return error;
+} \ No newline at end of file
diff --git a/Exception.h b/Exception.h
new file mode 100644
index 0000000..818f3f0
--- /dev/null
+++ b/Exception.h
@@ -0,0 +1,16 @@
+#pragma once
+
+#include <exception>
+
+class Exception : public std::exception {
+public:
+ Exception(const char * fmt, ...);
+ virtual ~Exception();
+ virtual const char * what();
+
+private:
+ char * error = NULL;
+};
+
+class ParserException : public Exception { using Exception::Exception; };
+class CircuitException : public Exception { using Exception::Exception; };
diff --git a/Parser.cpp b/Parser.cpp
index 84c3217..c8a90b4 100644
--- a/Parser.cpp
+++ b/Parser.cpp
@@ -1,29 +1,10 @@
#include <cstring>
#include <sstream>
-#include <cstdarg>
#include "Parser.h"
using std::getline;
-ParserException::ParserException(const char * fmt, ...) {
- va_list args;
- va_start(args, fmt);
- size_t sz = vsnprintf(NULL, 0, fmt, args) + 1;
- if (error != NULL) free(error);
- error = (char *) malloc(sz);
- vsnprintf(error, sz, fmt, args);
- va_end(args);
-}
-
-ParserException::~ParserException() {
- if (error != NULL)
- free(error);
-}
-
-const char * ParserException::what() {
- return error;
-}
size_t Parser::filter(char * input) {
size_t
diff --git a/Parser.h b/Parser.h
index 3a86eec..b6d7bd5 100644
--- a/Parser.h
+++ b/Parser.h
@@ -2,22 +2,15 @@
#include <iostream>
#include <istream>
-#include <exception>
+
#include "Circuit.h"
+#include "Exception.h"
using std::istream;
using std::string;
-class ParserException : public std::exception {
-public:
- ParserException(const char * fmt, ...);
- virtual ~ParserException();
- virtual const char * what();
-private:
- char * error = NULL;
-};
class Parser {
public: