-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathwriter.h
49 lines (42 loc) · 1.08 KB
/
writer.h
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
#ifndef WRITER_H
#define WRITER_H
#include "storage.h"
#include <string>
#include <fstream>
class voxel_writer {
private:
abstract_voxel_storage* voxels_;
std::ofstream& assert_good_(const std::string& fn, std::ofstream& fs) {
if (!fs.good()) {
throw std::runtime_error("Unable to open file for writing. " + fn);
}
return fs;
}
public:
void SetVoxels(abstract_voxel_storage* voxels) {
voxels_ = voxels;
}
void Write(const std::string& fnc) {
{
std::string fn = fnc + std::string(".index");
std::ofstream fs(fn.c_str());
voxels_->write(file_part_index, assert_good_(fn, fs));
}
{
std::string fn = fnc + std::string(".contents");
std::ofstream fs(fn.c_str(), std::ios::binary);
voxels_->write(file_part_contents, assert_good_(fn, fs));
}
{
std::string fn = fnc + std::string(".meta");
std::ofstream fs(fn.c_str());
voxels_->write(file_part_meta, assert_good_(fn, fs));
}
{
std::string fn = fnc + std::string(".primitives");
std::ofstream fs(fn.c_str());
voxels_->write(file_part_primitives, assert_good_(fn, fs));
}
}
};
#endif