Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXStream.h
1 /********************************************************************************
2 * *
3 * P e r s i s t e n t S t o r a g e S t r e a m C l a s s e s *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1997,2017 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXSTREAM_H
22 #define FXSTREAM_H
23 
24 namespace FX {
25 
26 
28 enum FXStreamDirection {
29  FXStreamDead=0,
30  FXStreamSave=1,
31  FXStreamLoad=2
32  };
33 
34 
36 enum FXStreamStatus {
37  FXStreamOK=0,
38  FXStreamEnd=1,
39  FXStreamFull=2,
40  FXStreamNoWrite=3,
41  FXStreamNoRead=4,
42  FXStreamFormat=5,
43  FXStreamUnknown=6,
44  FXStreamAlloc=7,
45  FXStreamFailure=8
46  };
47 
48 
50 enum FXWhence {
51  FXFromStart=0,
52  FXFromCurrent=1,
53  FXFromEnd=2
54  };
55 
56 
78 class FXAPI FXStream {
79 protected:
80  FXHash hash; // Hash table
81  const FXObject *parent; // Parent object
82  FXuchar *begptr; // Begin of buffer
83  FXuchar *endptr; // End of buffer
84  FXuchar *wrptr; // Write pointer
85  FXuchar *rdptr; // Read pointer
86  FXlong pos; // Position
87  FXStreamDirection dir; // Direction of current transfer
88  FXStreamStatus code; // Status code
89  FXuint seq; // Sequence number
90  FXbool owns; // Stream owns buffer
91  FXbool swap; // Swap bytes on readin
92 protected:
93 
98  virtual FXuval writeBuffer(FXuval count);
99 
104  virtual FXuval readBuffer(FXuval count);
105 
106 public:
107 
114  FXStream(const FXObject* cont=NULL);
115 
122  FXbool open(FXStreamDirection save_or_load,FXuchar* data=NULL,FXuval size=8192UL,FXbool owned=false);
123 
125  virtual FXbool flush();
126 
128  virtual FXbool close();
129 
131  FXuval getSpace() const;
132 
134  void setSpace(FXuval sp);
135 
137  void setOwned(FXbool owned){ owns=owned; }
138 
140  FXbool isOwned() const { return owns; }
141 
143  FXStreamStatus status() const { return code; }
144 
146  FXbool eof() const { return code!=FXStreamOK; }
147 
149  void setError(FXStreamStatus err);
150 
152  FXStreamDirection direction() const { return dir; }
153 
155  const FXObject* container() const { return parent; }
156 
158  FXlong position() const { return pos; }
159 
161  virtual FXbool position(FXlong offset,FXWhence whence=FXFromStart);
162 
166  void swapBytes(FXbool s){ swap=s; }
167 
171  FXbool swapBytes() const { return swap; }
172 
178  void setBigEndian(FXbool big);
179 
183  FXbool isBigEndian() const;
184 
186  FXStream& operator<<(const FXuchar& v);
187  FXStream& operator<<(const FXchar& v){ return *this << reinterpret_cast<const FXuchar&>(v); }
188  FXStream& operator<<(const FXbool& v){ return *this << reinterpret_cast<const FXuchar&>(v); }
189  FXStream& operator<<(const FXushort& v);
190  FXStream& operator<<(const FXshort& v){ return *this << reinterpret_cast<const FXushort&>(v); }
191  FXStream& operator<<(const FXuint& v);
192  FXStream& operator<<(const FXint& v){ return *this << reinterpret_cast<const FXuint&>(v); }
193  FXStream& operator<<(const FXfloat& v){ return *this << reinterpret_cast<const FXuint&>(v); }
194  FXStream& operator<<(const FXdouble& v);
195  FXStream& operator<<(const FXlong& v){ return *this << reinterpret_cast<const FXdouble&>(v); }
196  FXStream& operator<<(const FXulong& v){ return *this << reinterpret_cast<const FXdouble&>(v); }
197 
199  FXStream& save(const FXuchar* p,FXuval n);
200  FXStream& save(const FXchar* p,FXuval n){ return save(reinterpret_cast<const FXuchar*>(p),n); }
201  FXStream& save(const FXbool* p,FXuval n){ return save(reinterpret_cast<const FXuchar*>(p),n); }
202  FXStream& save(const FXushort* p,FXuval n);
203  FXStream& save(const FXshort* p,FXuval n){ return save(reinterpret_cast<const FXushort*>(p),n); }
204  FXStream& save(const FXuint* p,FXuval n);
205  FXStream& save(const FXint* p,FXuval n){ return save(reinterpret_cast<const FXuint*>(p),n); }
206  FXStream& save(const FXfloat* p,FXuval n){ return save(reinterpret_cast<const FXuint*>(p),n); }
207  FXStream& save(const FXdouble* p,FXuval n);
208  FXStream& save(const FXlong* p,FXuval n){ return save(reinterpret_cast<const FXdouble*>(p),n); }
209  FXStream& save(const FXulong* p,FXuval n){ return save(reinterpret_cast<const FXdouble*>(p),n); }
210 
212  FXStream& operator>>(FXuchar& v);
213  FXStream& operator>>(FXchar& v){ return *this >> reinterpret_cast<FXuchar&>(v); }
214  FXStream& operator>>(FXbool& v){ return *this >> reinterpret_cast<FXuchar&>(v); }
215  FXStream& operator>>(FXushort& v);
216  FXStream& operator>>(FXshort& v){ return *this >> reinterpret_cast<FXushort&>(v); }
217  FXStream& operator>>(FXuint& v);
218  FXStream& operator>>(FXint& v){ return *this >> reinterpret_cast<FXuint&>(v); }
219  FXStream& operator>>(FXfloat& v){ return *this >> reinterpret_cast<FXuint&>(v); }
220  FXStream& operator>>(FXdouble& v);
221  FXStream& operator>>(FXlong& v){ return *this >> reinterpret_cast<FXdouble&>(v); }
222  FXStream& operator>>(FXulong& v){ return *this >> reinterpret_cast<FXdouble&>(v); }
223 
225  FXStream& load(FXuchar* p,FXuval n);
226  FXStream& load(FXchar* p,FXuval n){ return load(reinterpret_cast<FXuchar*>(p),n); }
227  FXStream& load(FXbool* p,FXuval n){ return load(reinterpret_cast<FXuchar*>(p),n); }
228  FXStream& load(FXushort* p,FXuval n);
229  FXStream& load(FXshort* p,FXuval n){ return load(reinterpret_cast<FXushort*>(p),n); }
230  FXStream& load(FXuint* p,FXuval n);
231  FXStream& load(FXint* p,FXuval n){ return load(reinterpret_cast<FXuint*>(p),n); }
232  FXStream& load(FXfloat* p,FXuval n){ return load(reinterpret_cast<FXuint*>(p),n); }
233  FXStream& load(FXdouble* p,FXuval n);
234  FXStream& load(FXlong* p,FXuval n){ return load(reinterpret_cast<FXdouble*>(p),n); }
235  FXStream& load(FXulong* p,FXuval n){ return load(reinterpret_cast<FXdouble*>(p),n); }
236 
238  FXStream& saveObject(const FXObject* v);
239 
241  FXStream& loadObject(FXObject*& v);
242 
244  FXStream& addObject(const FXObject* v);
245 
247  virtual ~FXStream();
248  };
249 
250 }
251 
252 #endif

Copyright © 1997-2016 Jeroen van der Zijp