summaryrefslogtreecommitdiffabout
path: root/lib/chunk.cc
Unidiff
Diffstat (limited to 'lib/chunk.cc') (more/less context) (show whitespace changes)
-rw-r--r--lib/chunk.cc31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/chunk.cc b/lib/chunk.cc
new file mode 100644
index 0000000..7cc15ff
--- a/dev/null
+++ b/lib/chunk.cc
@@ -0,0 +1,31 @@
1#include <midillo/chunk.h>
2#include <midillo/util.h>
3#include <midillo/exception.h>
4
5namespace midillo {
6
7 void chunk_header_t::load(istream& s) {
8 s.read((char*)id_chars,sizeof(id_chars));
9 if(!s.good())
10 throw exception_input_error(CODEPOINT,"Error reading chunk header");
11 length = read32(s);
12 }
13
14 void chunk_header_t::save(ostream& s) const {
15 s.write((char*)id_chars,sizeof(id_chars));
16 if(!s.good())
17 throw exception_output_error(CODEPOINT,"Error writing chunk header");
18 write32(s,length);
19 }
20
21 void chunk_header_t::dump(ostream& s) const {
22 std::ios::fmtflags ff = s.flags();
23 s.unsetf(std::ios::hex); s.setf(std::ios::dec);
24 s
25 << id_chars[0] << id_chars[1]
26 << id_chars[2] << id_chars[3]
27 << " chunk of " << length << " byte(s)";
28 s.flags(ff);
29 }
30
31}