8
8
// SS SS tt ee ll ll aa aa
9
9
// SSSS ttt eeeee llll llll aaaaa
11
// Copyright (c) 1995-2008 by Bradford W. Mott and the Stella team
11
// Copyright (c) 1995-2010 by Bradford W. Mott, Stephen Anthony
12
// and the Stella Team
13
// See the file "license" for information on usage and redistribution of
14
// See the file "License.txt" for information on usage and redistribution of
14
15
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
16
// $Id: Serializer.hxx,v 1.14 2008/02/06 13:45:22 stephena Exp $
17
// $Id: Serializer.hxx 2001 2010-04-10 21:37:23Z stephena $
17
18
//============================================================================
19
20
#ifndef SERIALIZER_HXX
20
21
#define SERIALIZER_HXX
23
24
#include "bspf.hxx"
26
This class implements a Serializer device, whereby data is
27
serialized and sent to an output binary file in a system-
27
This class implements a Serializer device, whereby data is serialized and
28
read from/written to a binary stream in a system-independent way. The
29
stream can be either an actual file, or an in-memory structure.
30
31
Bytes are written as characters, integers are written as 4 characters
31
32
(32-bit), strings are written as characters prepended by the length of the
32
33
string, boolean values are written using a special character pattern.
35
All bytes and ints should be cast to their appropriate data type upon
34
38
@author Stephen Anthony
35
@version $Id: Serializer.hxx,v 1.14 2008/02/06 13:45:22 stephena Exp $
39
@version $Id: Serializer.hxx 2001 2010-04-10 21:37:23Z stephena $
41
Creates a new Serializer device.
43
Open must be called with a valid file before this Serializer can
45
Creates a new Serializer device for streaming binary data.
47
If a filename is provided, the stream will be to the given
48
filename. Otherwise, the stream will be in memory.
50
If a file is opened readonly, we can never write to it.
52
The isValid() method must immediately be called to verify the stream
53
was correctly initialized.
55
Serializer(const string& filename, bool readonly = false);
55
Opens the given file for output. Multiple calls to this method
56
will close previously opened files.
58
@param fileName The filename to send the serialized data to.
59
@return Result of opening the file. True on success, false on failure
61
bool open(const string& fileName);
64
Closes the current output stream.
69
Answers whether the serializer is currently opened
65
Answers whether the serializer is currently initialized for reading
71
Resets the read/write location to the beginning of the stream.
76
Reads a byte value (8-bit) from the current input stream.
78
@result The char value which has been read from the stream.
83
Reads an int value (32-bit) from the current input stream.
85
@result The int value which has been read from the stream.
90
Reads a string from the current input stream.
92
@result The string which has been read from the stream.
94
string getString(void);
97
Reads a boolean value from the current input stream.
99
@result The boolean value which has been read from the stream.
74
104
Writes an byte value (8-bit) to the current output stream.