Bug fix
[satune.git] / src / Serialize / serializer.cc
1
2 /*
3  * File:   serializer.cc
4  * Author: hamed
5  *
6  * Created on September 7, 2017, 3:38 PM
7  */
8
9 #include "serializer.h"
10 #include "unistd.h"
11 #include "fcntl.h"
12 #include "boolean.h"
13
14 Serializer::Serializer(const char *file) {
15         filedesc = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
16
17         if (filedesc < 0) {
18                 exit(-1);
19         }
20 }
21
22 Serializer::~Serializer() {
23         if (-1 == close(filedesc)) {
24                 exit(-1);
25         }
26 }
27
28 void Serializer::mywrite(const void *__buf, size_t __n) {
29         write (filedesc, __buf, __n);
30 }
31
32
33 void serializeBooleanEdge(Serializer *serializer, BooleanEdge be) {
34         if (be == BooleanEdge(NULL))
35                 return;
36         be.getBoolean()->serialize(serializer);
37         ASTNodeType type = BOOLEANEDGE;
38         serializer->mywrite(&type, sizeof(ASTNodeType));
39         Boolean *boolean = be.getRaw();
40         serializer->mywrite(&boolean, sizeof(Boolean *));
41 }