1 | /**************************************************************************
|
---|
2 | *
|
---|
3 | * bitio_m_stdio.h -- Macros for bitio to a file
|
---|
4 | * Copyright (C) 1994 Neil Sharman
|
---|
5 | *
|
---|
6 | * This program is free software; you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation; either version 2 of the License, or
|
---|
9 | * (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This program is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU General Public License
|
---|
17 | * along with this program; if not, write to the Free Software
|
---|
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
19 | *
|
---|
20 | **************************************************************************
|
---|
21 | *
|
---|
22 | * This file contains macros for doing bitwise input and output on a FILE*.
|
---|
23 | * With these routines you cannot mix reads and writes on the FILE,
|
---|
24 | * or multiple writes, at the same time and guarantee them to work, also you
|
---|
25 | * cannot seek to a point and do a write. The decode routine can detect when
|
---|
26 | * you run off the end of the file and will produce an approate error message.
|
---|
27 | *
|
---|
28 | *
|
---|
29 | **************************************************************************/
|
---|
30 |
|
---|
31 | #ifndef H_BITIO_M_STDIO
|
---|
32 | #define H_BITIO_M_STDIO
|
---|
33 |
|
---|
34 | #include "bitio_m_abstract.h"
|
---|
35 |
|
---|
36 |
|
---|
37 | class stdio_bitio_buffer : public bitio_buffer {
|
---|
38 | protected:
|
---|
39 | FILE *file;
|
---|
40 | unsigned char buffer;
|
---|
41 | unsigned char btg;
|
---|
42 | unsigned long bytesWritten;
|
---|
43 |
|
---|
44 | public:
|
---|
45 | stdio_bitio_buffer (FILE *f = NULL);
|
---|
46 |
|
---|
47 | void attachFile (FILE *f);
|
---|
48 |
|
---|
49 | unsigned char GetBtg () { return btg; }
|
---|
50 | unsigned long GetBytesWritten () { return bytesWritten; }
|
---|
51 |
|
---|
52 | void seek (unsigned long byte, unsigned char bit);
|
---|
53 | void seek (unsigned long topos);
|
---|
54 | void error();
|
---|
55 | long add00(long b);
|
---|
56 | long addff(long b);
|
---|
57 | int bit();
|
---|
58 | int bitOffset() { return btg; }
|
---|
59 | void done();
|
---|
60 |
|
---|
61 | void encodeStart();
|
---|
62 | void encodeBit(int bit);
|
---|
63 | void encodeDone();
|
---|
64 | };
|
---|
65 |
|
---|
66 |
|
---|
67 | /*#define ENCODE_START(f) \
|
---|
68 | { \
|
---|
69 | stdio_bitio_buffer buffer(f); \
|
---|
70 | buffer.encodeStart();
|
---|
71 |
|
---|
72 | #define ENCODE_CONTINUE(b) \
|
---|
73 | { \
|
---|
74 | stdio_bitio_buffer buffer; \
|
---|
75 | buffer.unpause(b);
|
---|
76 |
|
---|
77 | #define ENCODE_PAUSE(b) buffer.pause(&b);}
|
---|
78 |
|
---|
79 | #define ENCODE_DONE buffer.encodeDone();}
|
---|
80 |
|
---|
81 | #define DECODE_START(f) \
|
---|
82 | { \
|
---|
83 | stdio_bitio_buffer buffer(f);
|
---|
84 |
|
---|
85 | #define DECODE_CONTINUE(b) \
|
---|
86 | { \
|
---|
87 | stdio_bitio_buffer buffer; \
|
---|
88 | buffer.unpause(b);
|
---|
89 |
|
---|
90 | #define DECODE_ADD_FF(b) b = buffer.addff(b)
|
---|
91 |
|
---|
92 | #define DECODE_ADD_00(b) b = buffer.add00(b)
|
---|
93 |
|
---|
94 | #define DECODE_BIT buffer.bit()
|
---|
95 |
|
---|
96 | #define DECODE_DONE buffer.done();}
|
---|
97 |
|
---|
98 | #define DECODE_PAUSE(b) buffer.pause(&b);}
|
---|
99 | */
|
---|
100 |
|
---|
101 | #endif
|
---|