Extract common parts of wxData{In,Out}putStream in a common base class.
[wxWidgets.git] / include / wx / datstrm.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/datstrm.h
3 // Purpose: Data stream classes
4 // Author: Guilhem Lavaux
5 // Modified by: Mickael Gilabert
6 // Created: 28/06/1998
7 // RCS-ID: $Id$
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_DATSTREAM_H_
13 #define _WX_DATSTREAM_H_
14
15 #include "wx/stream.h"
16 #include "wx/longlong.h"
17 #include "wx/convauto.h"
18
19 #if wxUSE_STREAMS
20
21 // Common wxDataInputStream and wxDataOutputStream parameters.
22 class WXDLLIMPEXP_BASE wxDataStreamBase
23 {
24 public:
25 void BigEndianOrdered(bool be_order) { m_be_order = be_order; }
26
27 #if wxUSE_UNICODE
28 void SetConv( const wxMBConv &conv );
29 wxMBConv *GetConv() const { return m_conv; }
30 #endif
31
32 protected:
33 // Ctor and dtor are both protected, this class is never used directly but
34 // only by its derived classes.
35 wxDataStreamBase(const wxMBConv& conv);
36 ~wxDataStreamBase();
37
38
39 bool m_be_order;
40
41 #if wxUSE_UNICODE
42 wxMBConv *m_conv;
43 #endif
44
45 wxDECLARE_NO_COPY_CLASS(wxDataStreamBase);
46 };
47
48
49 class WXDLLIMPEXP_BASE wxDataInputStream : public wxDataStreamBase
50 {
51 public:
52 wxDataInputStream(wxInputStream& s, const wxMBConv& conv = wxConvUTF8);
53
54 bool IsOk() { return m_input->IsOk(); }
55
56 #if wxHAS_INT64
57 wxUint64 Read64();
58 #endif
59 #if wxUSE_LONGLONG
60 wxLongLong ReadLL();
61 #endif
62 wxUint32 Read32();
63 wxUint16 Read16();
64 wxUint8 Read8();
65 double ReadDouble();
66 wxString ReadString();
67
68 #if wxHAS_INT64
69 void Read64(wxUint64 *buffer, size_t size);
70 void Read64(wxInt64 *buffer, size_t size);
71 #endif
72 #if defined(wxLongLong_t) && wxUSE_LONGLONG
73 void Read64(wxULongLong *buffer, size_t size);
74 void Read64(wxLongLong *buffer, size_t size);
75 #endif
76 #if wxUSE_LONGLONG
77 void ReadLL(wxULongLong *buffer, size_t size);
78 void ReadLL(wxLongLong *buffer, size_t size);
79 #endif
80 void Read32(wxUint32 *buffer, size_t size);
81 void Read16(wxUint16 *buffer, size_t size);
82 void Read8(wxUint8 *buffer, size_t size);
83 void ReadDouble(double *buffer, size_t size);
84
85 wxDataInputStream& operator>>(wxString& s);
86 wxDataInputStream& operator>>(wxInt8& c);
87 wxDataInputStream& operator>>(wxInt16& i);
88 wxDataInputStream& operator>>(wxInt32& i);
89 wxDataInputStream& operator>>(wxUint8& c);
90 wxDataInputStream& operator>>(wxUint16& i);
91 wxDataInputStream& operator>>(wxUint32& i);
92 #if wxHAS_INT64
93 wxDataInputStream& operator>>(wxUint64& i);
94 wxDataInputStream& operator>>(wxInt64& i);
95 #endif
96 #if defined(wxLongLong_t) && wxUSE_LONGLONG
97 wxDataInputStream& operator>>(wxULongLong& i);
98 wxDataInputStream& operator>>(wxLongLong& i);
99 #endif
100 wxDataInputStream& operator>>(double& i);
101 wxDataInputStream& operator>>(float& f);
102
103 protected:
104 wxInputStream *m_input;
105
106 wxDECLARE_NO_COPY_CLASS(wxDataInputStream);
107 };
108
109 class WXDLLIMPEXP_BASE wxDataOutputStream : public wxDataStreamBase
110 {
111 public:
112 wxDataOutputStream(wxOutputStream& s, const wxMBConv& conv = wxConvUTF8);
113
114 bool IsOk() { return m_output->IsOk(); }
115
116 #if wxHAS_INT64
117 void Write64(wxUint64 i);
118 void Write64(wxInt64 i);
119 #endif
120 #if wxUSE_LONGLONG
121 void WriteLL(const wxLongLong &ll);
122 void WriteLL(const wxULongLong &ll);
123 #endif
124 void Write32(wxUint32 i);
125 void Write16(wxUint16 i);
126 void Write8(wxUint8 i);
127 void WriteDouble(double d);
128 void WriteString(const wxString& string);
129
130 #if wxHAS_INT64
131 void Write64(const wxUint64 *buffer, size_t size);
132 void Write64(const wxInt64 *buffer, size_t size);
133 #endif
134 #if defined(wxLongLong_t) && wxUSE_LONGLONG
135 void Write64(const wxULongLong *buffer, size_t size);
136 void Write64(const wxLongLong *buffer, size_t size);
137 #endif
138 #if wxUSE_LONGLONG
139 void WriteLL(const wxULongLong *buffer, size_t size);
140 void WriteLL(const wxLongLong *buffer, size_t size);
141 #endif
142 void Write32(const wxUint32 *buffer, size_t size);
143 void Write16(const wxUint16 *buffer, size_t size);
144 void Write8(const wxUint8 *buffer, size_t size);
145 void WriteDouble(const double *buffer, size_t size);
146
147 wxDataOutputStream& operator<<(const wxString& string);
148 wxDataOutputStream& operator<<(wxInt8 c);
149 wxDataOutputStream& operator<<(wxInt16 i);
150 wxDataOutputStream& operator<<(wxInt32 i);
151 wxDataOutputStream& operator<<(wxUint8 c);
152 wxDataOutputStream& operator<<(wxUint16 i);
153 wxDataOutputStream& operator<<(wxUint32 i);
154 #if wxHAS_INT64
155 wxDataOutputStream& operator<<(wxUint64 i);
156 wxDataOutputStream& operator<<(wxInt64 i);
157 #endif
158 #if defined(wxLongLong_t) && wxUSE_LONGLONG
159 wxDataOutputStream& operator<<(const wxULongLong &i);
160 wxDataOutputStream& operator<<(const wxLongLong &i);
161 #endif
162 wxDataOutputStream& operator<<(double f);
163 wxDataOutputStream& operator<<(float f);
164
165 protected:
166 wxOutputStream *m_output;
167
168 wxDECLARE_NO_COPY_CLASS(wxDataOutputStream);
169 };
170
171 #endif
172 // wxUSE_STREAMS
173
174 #endif
175 // _WX_DATSTREAM_H_