-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnstream.h
134 lines (109 loc) · 4.63 KB
/
nstream.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
Pixcen - A windows platform low level pixel editor for C64
Copyright (C) 2013 John Hammarberg ([email protected])
This file is part of Pixcen.
Pixcen is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Pixcen is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Pixcen. If not, see <http://www.gnu.org/licenses/>.
*/
// nstream.h: interface for the nstream class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_NSTREAM_H__F3F970C6_1445_472B_951C_A1C1A03DA3FC__INCLUDED_)
#define AFX_NSTREAM_H__F3F970C6_1445_472B_951C_A1C1A03DA3FC__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class nstream
{
public:
nstream(){};
virtual ~nstream(){};
virtual size_t write(const void *p, size_t l)=NULL;
virtual size_t read(void *p, size_t l)=NULL;
typedef enum
{
pos_begin=0,
pos_current,
pos_end
}pos_type;
virtual __int64 setpos(__int64 delta, pos_type how=pos_begin){return -1;}
__int64 getpos(void){return setpos(0,pos_current);}
inline nstream &operator<<(const bool &d){write(&d,sizeof(d));return *this;}
inline nstream &operator<<(const float &d){write(&d,sizeof(d));return *this;}
inline nstream &operator<<(const double &d){write(&d,sizeof(d));return *this;}
inline nstream &operator<<(const wchar_t &d){write(&d,sizeof(d));return *this;}
inline nstream &operator<<(const char &d){write(&d,sizeof(d));return *this;}
inline nstream &operator<<(const short &d){write(&d,sizeof(d));return *this;}
inline nstream &operator<<(const int &d){write(&d,sizeof(d));return *this;}
inline nstream &operator<<(const long &d){write(&d,sizeof(d));return *this;}
inline nstream &operator<<(const __int64 &d){write(&d,sizeof(d));return *this;}
inline nstream &operator<<(const unsigned char &d){write(&d,sizeof(d));return *this;}
inline nstream &operator<<(const unsigned short &d){write(&d,sizeof(d));return *this;}
inline nstream &operator<<(const unsigned int &d){write(&d,sizeof(d));return *this;}
inline nstream &operator<<(const unsigned long &d){write(&d,sizeof(d));return *this;}
inline nstream &operator<<(const unsigned __int64 &d){write(&d,sizeof(d));return *this;}
#ifdef _NEWSTR_CLASS
inline nstream &operator<<(const nstrc &o){writestring(o);return *this;}
inline nstream &operator<<(const nstrw &o){writestring(o);return *this;}
#endif
inline nstream &operator>>(bool &d){read(&d,sizeof(d));return *this;}
inline nstream &operator>>(float &d){read(&d,sizeof(d));return *this;}
inline nstream &operator>>(double &d){read(&d,sizeof(d));return *this;}
inline nstream &operator>>(wchar_t &d){read(&d,sizeof(d));return *this;}
inline nstream &operator>>(char &d){read(&d,sizeof(d));return *this;}
inline nstream &operator>>(short &d){read(&d,sizeof(d));return *this;}
inline nstream &operator>>(int &d){read(&d,sizeof(d));return *this;}
inline nstream &operator>>(long &d){read(&d,sizeof(d));return *this;}
inline nstream &operator>>(__int64 &d){read(&d,sizeof(d));return *this;}
inline nstream &operator>>(unsigned char &d){read(&d,sizeof(d));return *this;}
inline nstream &operator>>(unsigned short &d){read(&d,sizeof(d));return *this;}
inline nstream &operator>>(unsigned int &d){read(&d,sizeof(d));return *this;}
inline nstream &operator>>(unsigned long &d){read(&d,sizeof(d));return *this;}
inline nstream &operator>>(unsigned __int64 &d){read(&d,sizeof(d));return *this;}
#ifdef _NEWSTR_CLASS
inline nstream &operator>>(nstrc &o){readstring(o);return *this;}
inline nstream &operator>>(nstrw &o){readstring(o);return *this;}
#endif
private:
#ifdef _NEWSTR_CLASS
void writestring(const nstrc &o)
{
write(o,(o.len()+1)*sizeof(char));
}
void writestring(const nstrw &o)
{
write(o,(o.len()+1)*sizeof(unsigned short));
}
void readstring(nstrc &o)
{
o="";
char b;
for(;;)
{
read(&b,sizeof(char));
if(!b)break;
o+=b;
}
}
void readstring(nstrw &o)
{
o=L"";
unsigned short b;
for(;;)
{
read(&b,sizeof(unsigned short));
if(!b)break;
o+=b;
}
}
#endif
};
#endif // !defined(AFX_NSTREAM_H__F3F970C6_1445_472B_951C_A1C1A03DA3FC__INCLUDED_)