ScummVM API documentation
datapacker.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * Additional copyright for this file:
8  * Copyright (C) 1999-2000 Revolution Software Ltd.
9  * This code is based on source code created by Revolution Software,
10  * used with permission.
11  *
12  * This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  *
25  */
26 
27 #ifndef ICB_DATAPACKER_HH
28 #define ICB_DATAPACKER_HH
29 
30 #include "common/stream.h"
31 
32 namespace ICB {
33 
34 // Pack: 4 values into 4*14 bits = 56-bits = 7 bytes
35 #define BUFFER_BYTE_SIZE (7)
36 #define PACK_BIT_SIZE (14)
37 #define PACK_CHUNK_SIZE (4)
38 
39 class DataPacker {
40 public:
41  DataPacker();
42  ~DataPacker();
43 
44  // Copy constructor
45  DataPacker(DataPacker &src);
46 
47  // Assignment operator
48  DataPacker &operator=(DataPacker &b);
49 
50  enum ModeEnum { NO_MODE, READ, WRITE };
51 
52  enum PackModeEnum { NO_PACKMODE, PACK, DONT_PACK };
53 
54  enum ReturnCodes { OK, BAD_POS, BAD_MODE, BAD_PACKMODE, READ_ERROR, WRITE_ERROR, BAD_READFUNC, BAD_WRITEFUNC, BAD_VALUE };
55 
56  // Start the bit-packing process : say if we are in READ or WRITE mode
57  ReturnCodes open(const ModeEnum mode, const PackModeEnum packMode);
58 
59  // Put a value into the bit-stream
60  ReturnCodes put(const int32 value, Common::WriteStream *fh);
61 
62  // Get a value from the bit-stream
63  ReturnCodes Get(int32 &value, Common::SeekableReadStream *stream);
64 
65  // Stop the bit-packing process : will output any remaining data
66  ReturnCodes close(Common::WriteStream *stream);
67  ReturnCodes close(Common::SeekableReadStream *stream);
68  // Simple inspectors
69  int32 Pos() const { return pos; }
70  int32 PackMin() const { return packMin; }
71  int32 PackMax() const { return packMax; }
72 
73 private:
74  void ClearBuffer();
75 
76  bool readMode;
77 
78  ModeEnum iMode;
79  PackModeEnum iPackMode;
80  int32 pos;
81  int32 packMin;
82  int32 packMax;
83 
84  uint8 buffer[BUFFER_BYTE_SIZE];
85 };
86 
87 } // End of namespace ICB
88 
89 #endif // #ifndef DATAPACKER_HH
Definition: stream.h:77
Definition: actor.h:32
Definition: stream.h:745
Definition: datapacker.h:39