aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Parser.cpp20
-rw-r--r--Parser.h18
-rw-r--r--docs/Parser.h16
-rw-r--r--main.cpp40
4 files changed, 59 insertions, 35 deletions
diff --git a/Parser.cpp b/Parser.cpp
new file mode 100644
index 0000000..d76f11a
--- /dev/null
+++ b/Parser.cpp
@@ -0,0 +1,20 @@
+#include "Parser.h"
+
+void Parser::parse(string input) const {
+ std::cout << input << std::endl;
+}
+
+istream & Parser::parse(const Parser & parser, istream & s) const {
+ string temp(std::istreambuf_iterator<char>(s), {});
+ parse(temp);
+ return s;
+}
+
+istream & operator >> (istream & s, const Parser & parser) {
+ return parser.parse(parser, s);
+}
+
+istream & operator << (const Parser & parser, istream & s) {
+ return parser.parse(parser, s);
+}
+
diff --git a/Parser.h b/Parser.h
new file mode 100644
index 0000000..58d062f
--- /dev/null
+++ b/Parser.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#include <iostream>
+#include <istream>
+
+using std::istream;
+using std::string;
+
+class Parser {
+public:
+ void parse(string input) const;
+
+private:
+ istream & parse(const Parser & parser, istream & s) const;
+ friend istream & operator << (const Parser & parser, istream & s);
+ friend istream & operator >> (istream & s, const Parser & parser);
+};
+
diff --git a/docs/Parser.h b/docs/Parser.h
deleted file mode 100644
index a7c90e9..0000000
--- a/docs/Parser.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#pragma once
-
-#include <iostream>
-#include <istream>
-
-using std::ostream;
-
-class Parser {
-
- friend void operator >> (Parser& p, std::istream& filestream) {
- // cout assigned to another object mycout
- std::cout << "the file contains:\n" << filestream << std::endl;
- mycout << "Value of dx and dy are \n";
- mycout << d.dx << " " << d.dy;
- }
-}
diff --git a/main.cpp b/main.cpp
index 01b78b2..cca0636 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,38 +1,40 @@
+#include <cstdio>
#include <iostream>
#include <exception>
#include <fstream>
#include "Parser.h"
-#include "Circuit.h"
+// #include "Circuit.h"
using std::cout;
using std::endl;
-using std::fstream;
using std::exception;
+using std::ifstream;
+using std::istream;
int main(int argc, char** argv) {
- Parser main_parser;
- Circuit circuit;
+ Parser main_parser;
+ // Circuit circuit;
- main_parser.setCircuit(circuit);
+ // main_parser.setCircuit(circuit);
- fstream file{"circuits/full-adder.txt", file.out};
+ ifstream file("circuits/full-adder.txt");
- try {
- main_parser << file;
- } catch (exception e) {
- cout << "Parser error: " << e.what() << endl;
- return EXIT_FAILURE;
- }
+ try {
+ file >> main_parser;
+ } catch (exception e) {
+ cout << "Parser error: " << e.what() << endl;
+ return EXIT_FAILURE;
+ }
- try {
- circuit.run();
- } catch (exception e) {
- cout << "Circuit error: " << e.what() << endl;
- return EXIT_FAILURE;
- }
+ // try {
+ // circuit.run();
+ // } catch (exception e) {
+ // cout << "Circuit error: " << e.what() << endl;
+ // return EXIT_FAILURE;
+ // }
- cout << "Circuit output: " << circuit.getOutput() << endl;
+ // cout << "Circuit output: " << circuit.getOutput() << endl;
return EXIT_SUCCESS;
}