~ubuntu-branches/debian/squeeze/stella/squeeze

« back to all changes in this revision

Viewing changes to src/emucore/Serializer.hxx

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Kitt
  • Date: 2010-07-12 23:49:36 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100712234936-juawrr3etzhr2qpv
Tags: 3.1.2-1
* New maintainer (closes: #532039).
* New upstream version (closes: #461121):
  - includes launcher (closes: #396058).
* Fix the reference to the X Window System in the description (closes:
  #411815).
* Move to main, DFSG-free ROMs are available (see README.Debian).
* Enhance the package description.
* Drop the libslang2-dev dependency (closes: #560274).
* Remove the Encoding entry from stella.desktop.
* Avoid ignoring errors when cleaning.
* Add ${misc:Depends} to the package dependencies.
* Provide a doc-base file to install the documentation using doc-base.
* Switch to debhelper 7 with a simplified rules file.
* Use autotools-dev to provide updated configuration files.
* Update to Standards-Version 3.9.0:
  - Move to menu section Applications/Emulators.
  - Move the homepage declaration.
* Re-write the manpage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
//  SS  SS   tt   ee      ll   ll  aa  aa
9
9
//   SSSS     ttt  eeeee llll llll  aaaaa
10
10
//
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
12
13
//
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.
15
16
//
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
//============================================================================
18
19
 
19
20
#ifndef SERIALIZER_HXX
20
21
#define SERIALIZER_HXX
21
22
 
22
 
#include <fstream>
 
23
#include <iostream>
23
24
#include "bspf.hxx"
24
25
 
25
26
/**
26
 
  This class implements a Serializer device, whereby data is
27
 
  serialized and sent to an output binary file in a system-
28
 
  independent way.
 
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.
29
30
 
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.
33
34
 
 
35
  All bytes and ints should be cast to their appropriate data type upon
 
36
  method return.
 
37
 
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 $
36
40
*/
37
41
class Serializer
38
42
{
39
43
  public:
40
44
    /**
41
 
      Creates a new Serializer device.
42
 
 
43
 
      Open must be called with a valid file before this Serializer can
44
 
      be used.
 
45
      Creates a new Serializer device for streaming binary data.
 
46
 
 
47
      If a filename is provided, the stream will be to the given
 
48
      filename.  Otherwise, the stream will be in memory.
 
49
 
 
50
      If a file is opened readonly, we can never write to it.
 
51
 
 
52
      The isValid() method must immediately be called to verify the stream
 
53
      was correctly initialized.
45
54
    */
 
55
    Serializer(const string& filename, bool readonly = false);
46
56
    Serializer(void);
47
57
 
48
58
    /**
52
62
 
53
63
  public:
54
64
    /**
55
 
      Opens the given file for output.  Multiple calls to this method
56
 
      will close previously opened files.
57
 
 
58
 
      @param fileName The filename to send the serialized data to.
59
 
      @return Result of opening the file.  True on success, false on failure
60
 
    */
61
 
    bool open(const string& fileName);
62
 
 
63
 
    /**
64
 
      Closes the current output stream.
65
 
    */
66
 
    void close(void);
67
 
 
68
 
    /**
69
 
      Answers whether the serializer is currently opened
70
 
    */
71
 
    bool isOpen(void);
 
65
      Answers whether the serializer is currently initialized for reading
 
66
      and writing.
 
67
    */
 
68
    bool isValid(void);
 
69
 
 
70
    /**
 
71
      Resets the read/write location to the beginning of the stream.
 
72
    */
 
73
    void reset(void);
 
74
 
 
75
    /**
 
76
      Reads a byte value (8-bit) from the current input stream.
 
77
 
 
78
      @result The char value which has been read from the stream.
 
79
    */
 
80
    char getByte(void);
 
81
 
 
82
    /**
 
83
      Reads an int value (32-bit) from the current input stream.
 
84
 
 
85
      @result The int value which has been read from the stream.
 
86
    */
 
87
    int getInt(void);
 
88
 
 
89
    /**
 
90
      Reads a string from the current input stream.
 
91
 
 
92
      @result The string which has been read from the stream.
 
93
    */
 
94
    string getString(void);
 
95
 
 
96
    /**
 
97
      Reads a boolean value from the current input stream.
 
98
 
 
99
      @result The boolean value which has been read from the stream.
 
100
    */
 
101
    bool getBool(void);
72
102
 
73
103
    /**
74
104
      Writes an byte value (8-bit) to the current output stream.
100
130
 
101
131
  private:
102
132
    // The stream to send the serialized data to.
103
 
    fstream myStream;
 
133
    iostream* myStream;
 
134
    bool myUseFilestream;
104
135
 
105
136
    enum {
106
137
      TruePattern  = 0xfe,