aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-11-10 11:59:16 +0100
committerlonkaars <loek@pipeframe.xyz>2022-11-10 11:59:16 +0100
commit8f9c3d8093cba3204e3ead853ee36820a201a1e7 (patch)
tree71caa7b13c47b1ac098920aee3f6e396c0801971
parentffae2cb77bfb3263146a2de0deedf6528d4df461 (diff)
week 1 van oop2 klaar
-rw-r--r--oop2w1/HuiswerkWeek1.datbin0 -> 72 bytes
-rw-r--r--oop2w1/ProcessFile.cpp36
-rw-r--r--oop2w1/ProcessFile.h25
-rw-r--r--oop2w1/ProcessFile.hpp13
-rw-r--r--oop2w1/main.cpp28
l---------oop2w1/makefile1
6 files changed, 103 insertions, 0 deletions
diff --git a/oop2w1/HuiswerkWeek1.dat b/oop2w1/HuiswerkWeek1.dat
new file mode 100644
index 0000000..7df850f
--- /dev/null
+++ b/oop2w1/HuiswerkWeek1.dat
Binary files differ
diff --git a/oop2w1/ProcessFile.cpp b/oop2w1/ProcessFile.cpp
new file mode 100644
index 0000000..7f3629f
--- /dev/null
+++ b/oop2w1/ProcessFile.cpp
@@ -0,0 +1,36 @@
+#include "ProcessFile.h"
+
+ProcessFile::ProcessFile() { }
+ProcessFile::~ProcessFile() { }
+
+void ProcessFile::process(std::ifstream &file) {
+ uint32_t grootte = 0;
+ file.read((char*) &grootte, sizeof(uint32_t));
+ for (unsigned int i = 0; i < grootte; i++) {
+ enum GETAL type;
+ file.read((char*) &type, sizeof(enum GETAL));
+
+ switch(type) {
+ case LONG: {
+ read_and_print<int32_t>(file);
+ break;
+ }
+ case SHORT: {
+ read_and_print<int16_t>(file);
+ break;
+ }
+ case DOUBLE: {
+ read_and_print<double>(file);
+ break;
+ }
+ case FLOAT: {
+ read_and_print<float >(file);
+ break;
+ }
+ default: {
+ break;
+ }
+ }
+ }
+}
+
diff --git a/oop2w1/ProcessFile.h b/oop2w1/ProcessFile.h
new file mode 100644
index 0000000..983f2ed
--- /dev/null
+++ b/oop2w1/ProcessFile.h
@@ -0,0 +1,25 @@
+#pragma once
+
+/*
+ * DO NOT ADAPT THIS FILE!!!
+ */
+
+
+#include <fstream>
+
+class ProcessFile
+{
+public:
+ ProcessFile();
+ virtual ~ProcessFile();
+
+public:
+ virtual void process( std::ifstream& );
+
+private:
+ enum GETAL { LONG=1, SHORT, DOUBLE, FLOAT };
+ template <typename T>
+ void read_and_print(std::ifstream &file);
+};
+
+#include "ProcessFile.hpp"
diff --git a/oop2w1/ProcessFile.hpp b/oop2w1/ProcessFile.hpp
new file mode 100644
index 0000000..37b82d4
--- /dev/null
+++ b/oop2w1/ProcessFile.hpp
@@ -0,0 +1,13 @@
+#pragma once
+
+#include <iostream>
+
+#include "ProcessFile.h"
+
+template <typename T>
+void ProcessFile::read_and_print(std::ifstream &file) {
+ T waarde;
+ file.read((char*) &waarde, sizeof(T));
+ std::cout << waarde << std::endl;
+}
+
diff --git a/oop2w1/main.cpp b/oop2w1/main.cpp
new file mode 100644
index 0000000..e9d3197
--- /dev/null
+++ b/oop2w1/main.cpp
@@ -0,0 +1,28 @@
+/*
+ * DO NOT ADAPT THIS FILE!!!
+ */
+
+#include "ProcessFile.h"
+
+#include <fstream>
+#include <iostream>
+
+#define szFilename "HuiswerkWeek1.dat"
+
+int main()
+{
+ std::ifstream cInput( szFilename, std::ios::in | std::ios::binary );
+ ProcessFile cProcessFile;
+
+ if ( cInput )
+ {
+ cProcessFile.process( cInput );
+
+ cInput.close();
+ }
+
+ std::cin.get();
+
+ return 0;
+}
+
diff --git a/oop2w1/makefile b/oop2w1/makefile
new file mode 120000
index 0000000..a4e84c6
--- /dev/null
+++ b/oop2w1/makefile
@@ -0,0 +1 @@
+../week.mk \ No newline at end of file