-
Notifications
You must be signed in to change notification settings - Fork 0
/
binIO.cpp
62 lines (49 loc) · 1.46 KB
/
binIO.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/******************************************************************************
* GRIDGEN: Grid Generating Compiler
* By: Andy Stone (aistone@gmail.com)
* (C) Copyright 2011 Colorado State University
*****************************************************************************/
#include "binIO.hpp"
void initializeModule_binio() {
}
void BinIO::out(std::ostream &out, const int &val) {
out.write((const char*)&val, sizeof(int));
}
void BinIO::out(std::ostream &out, const double &val) {
out.write((const char*)&val, sizeof(double));
}
void BinIO::out(std::ostream &out, const bool &val) {
out.put((val ? 'T' : 'F'));
}
void BinIO::out(std::ostream &out, const std::string &s) {
out.write(s.c_str(), s.size() + 1);
}
void BinIO::out(std::ostream &out, const ISerializable &obj) {
obj.output(out);
}
void BinIO::outIdent(std::ostream &out, const IEnvironmental &obj) {
BinIO::out(out, obj.getID());
}
void BinIO::in(std::istream &in, int &val) {
in.read((char*)&val, sizeof(int));
}
void BinIO::in(std::istream &in, double &val) {
in.read((char*)&val, sizeof(double));
}
void BinIO::in(std::istream &in, bool &val) {
char c;
in.get(c);
if(c == 'T') { val = true; } else { val = false; }
}
void BinIO::in(std::istream &in, std::string &s) {
char c;
s = "";
while(true) {
in.get(c);
if(c == '\0') { return; }
s += c;
}
}
void BinIO::in(std::istream &in, ISerializable &obj) {
obj.input(in);
}