Permalink
Newer
Older
100644 151 lines (123 sloc) 5.27 KB
1
/***********************************************************************
2
* FXRuby -- the Ruby language bindings for the FOX GUI toolkit.
3
* Copyright (c) 2001-2009 by Lyle Johnson. All Rights Reserved.
4
*
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
9
*
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
14
*
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
*
19
* For further information please contact the author by e-mail
20
* at "lyle@lylejohnson.name".
21
***********************************************************************/
22
23
/// Stream data flow direction
24
enum FXStreamDirection {
25
FXStreamDead=0, /// Unopened stream
26
FXStreamSave=1, /// Saving stuff to stream
27
FXStreamLoad=2 /// Loading stuff from stream
28
};
29
30
31
/// Stream status codes
32
enum FXStreamStatus {
33
FXStreamOK=0, /// OK
34
FXStreamEnd=1, /// Try read past end of stream
35
FXStreamFull=2, /// Filled up stream buffer or disk full
36
FXStreamNoWrite=3, /// Unable to open for write
37
FXStreamNoRead=4, /// Unable to open for read
38
FXStreamFormat=5, /// Stream format error
39
FXStreamUnknown=6, /// Trying to read unknown class
40
FXStreamAlloc=7, /// Alloc failed
41
FXStreamFailure=8 /// General failure
42
};
43
44
45
/// Stream seeking
46
enum FXWhence {
47
FXFromStart=0, /// Seek from start position
48
FXFromCurrent=1, /// Seek from current position
49
FXFromEnd=2 /// Seek from end position
50
};
51
52
53
/********************* Persistent Store Definition *************************/
54
55
%rename("getPosition") FXStream::position() const;
56
%rename("eof?") FXStream::eof() const;
57
58
/**
59
* A stream is a way to serialize data and objects into a byte stream.
60
* Each item of data that is saved or loaded from the stream may be byte-swapped,
61
* thus allowing little-endian machines to read data produced on big endian ones
62
* and vice-versa.
63
* Data is serialized exactly as-is. There are no tags or other markers
64
* inserted into the stream; thus, the stream may be used to save or load arbitrary
65
* binary data.
66
* Objects derived from FXObjects may be serialized also; whenever a reference to an
67
* object is serialized, a table is consulted to determine if the same object has
68
* been encountered previously; if not, the object is added to the table and then
69
* its contents are serialized. If the object has been encountered before, only a
70
* reference to the object is serialized.
71
* When loading back a serialized object, new instances are constructed using
72
* the default constructor, and subsequently the object's contents are loaded.
73
* A special container object may be passed in which is placed in the table
74
* as if it had been encountered before; this will cause only references to this
75
* object to be saved. The container object is typically the top-level document
76
* object which manages all objects contained by it. Additional objects may be
77
* added using addObject(); these will not be actually saved or loaded.
78
*/
79
class FXStream {
80
public:
81
82
/**
83
* Construct stream with given container object. The container object
84
* is an object that will itself not be saved to or loaded from the stream,
85
* but which may be referenced by other objects. These references will be
86
* properly saved and restored.
87
*/
88
%extend {
89
FXStream(const FXObject* cont=NULL){
90
return new FXRbStream(cont);
91
}
92
}
93
94
/**
95
* Open stream for reading (FXStreamLoad) or for writing (FXStreamSave).
96
* An initial buffer size may be given, which must be at least 16 bytes.
97
* If data is not NULL, it is expected to point to an external data buffer
98
* of length size; otherwise stream will use an internally managed buffer.
99
*/
100
bool open(FXStreamDirection save_or_load,FXuval size=8192,FXuchar* data=NULL);
101
102
/// Get available buffer space
103
FXuval getSpace() const;
104
105
/// Set available buffer space
106
void setSpace(FXuval sp);
107
108
/// Get status code
109
FXStreamStatus status() const;
110
111
/// Return TRUE if at end of file or error
112
bool eof() const;
114
/// Set status code
115
void setError(FXStreamStatus err);
116
117
/// Obtain direction
118
FXStreamDirection direction() const;
119
120
/// Get parent object
121
const FXObject* container() const;
122
123
/// Get position
124
FXlong position() const;
125
126
/// Change swap bytes flag
127
void swapBytes(bool s);
128
129
/// Get swap bytes flag
130
bool swapBytes() const;
131
132
/**
133
* Set stream to big endian mode if TRUE. Byte swapping will
134
* be enabled if the machine native byte order is not equal to
135
* the desired byte order.
136
*/
137
void setBigEndian(bool big);
138
139
/**
140
* Return TRUE if big endian mode.
141
*/
142
bool isBigEndian() const;
143
144
/// Destructor
145
virtual ~FXStream();
146
};
147
148
149
DECLARE_FXSTREAM_VIRTUALS(FXStream)
150