-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamAssignee.h
More file actions
65 lines (53 loc) · 1.38 KB
/
StreamAssignee.h
File metadata and controls
65 lines (53 loc) · 1.38 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
59
60
61
62
63
64
65
#ifndef STREAM_ASSIGNEE_H
#define STREAM_ASSIGNEE_H
#include "ScriptCompile.h"
template <typename T>
class StreamAssignee
{
public:
StreamAssignee(ScriptCompile& comp) : c(comp), stream(comp.ss) {}
StreamAssignee<T>& operator=(const T& rhs)
{
/*if (!c.proto)
throw std::runtime_error("Attempting to generate code outside a function.");*/
stream.write((char*)&rhs, sizeof(T));
return *this;
}
ScriptCompile& c;
std::ostream& stream;
};
template <typename T>
class StreamAssigneeRelative;
template <>
class StreamAssigneeRelative<int8_t>
{
public:
StreamAssigneeRelative(ScriptCompile& comp) : c(comp), stream(comp.ss) {}
StreamAssigneeRelative<int8_t>& operator=(const int8_t& rhs)
{
/*if (!c.proto)
throw std::runtime_error("Attempting to generate code outside a function.");*/
c.rel8.push_back(stream.tellp());
stream.write((char*)&rhs, sizeof(int8_t));
return *this;
}
ScriptCompile& c;
std::ostream& stream;
};
template <>
class StreamAssigneeRelative<int32_t>
{
public:
StreamAssigneeRelative(ScriptCompile& comp) : c(comp), stream(comp.ss) {}
StreamAssigneeRelative<int32_t>& operator=(const int32_t& rhs)
{
/*if (!c.proto)
throw std::runtime_error("Attempting to generate code outside a function.");*/
c.rel32.push_back(stream.tellp());
stream.write((char*)&rhs, sizeof(int32_t));
return *this;
}
ScriptCompile& c;
std::ostream& stream;
};
#endif