-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrollReader.cpp
executable file
·43 lines (30 loc) · 1.07 KB
/
scrollReader.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
#include "scrollReader.h"
#include <istream>
#include <vector>
#include <stdlib.h>
#include "memoryManager.h"
#include "array.h"
#include "platter.h"
using namespace std;
array * scrollReader::readLegacy(memoryManager & mm,
istream & scroll, size_t size)
throw(invalid_argument, runtime_error)
{
static_assert(sizeof(unsigned int) == sizeof(platter),
"unsigned int is used to hold platter values");
static_assert(sizeof(unsigned int) == 4,
"unsigned int is read as 4 bytes");
if (size % 4 != 0)
throw invalid_argument("size is not a multiple of 4");
array * res = array::create(mm, size / 4);
scroll.read(reinterpret_cast<char*>(res->platters()), size);
if (!scroll)
{
res->destroy(mm);
throw runtime_error("scroll does not have enough characters");
}
platter * platters = res->platters();
for (size_t i = 0; i < size / 4; ++i)
platters[i] = _byteswap_ulong(platters[i]);
return res;
}