-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathknh.cpp
More file actions
58 lines (44 loc) · 1.08 KB
/
knh.cpp
File metadata and controls
58 lines (44 loc) · 1.08 KB
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
#include "knh.h"
#include <fstream>
#include <filesystem>
void knh::Entry::read(std::istream& stream)
{
m_name = kn5::readString(stream);
m_matrix.read(stream);
m_children.resize(kn5::readInt32(stream));
for (auto& child : m_children)
child.read(stream);
}
void knh::Entry::dump(std::ostream& stream, const std::string& indent) const
{
stream << indent << "m_name: " << m_name << std::endl;
m_matrix.dump(stream, indent);
stream << indent << "children: " << m_children.size() << std::endl;
for (size_t i = 0; i < m_children.size(); i++)
{
stream << indent << " children[" << i << "]" << std::endl;
m_children[i].dump(stream, indent + " ");
}
}
void knh::read(const std::string& fileName)
{
std::ifstream stream(fileName, std::ios::binary);
if (!stream)
throw std::runtime_error("Couldn't open file: " + fileName);
m_entry.read(stream);
}
void knh::dump(std::ostream& stream) const
{
m_entry.dump(stream);
}
bool knh::dump(const std::string& fileName) const
{
std::ofstream of(fileName);
if (of)
{
m_entry.dump(of);
of.close();
return true;
}
return false;
}