1 | /**************************************************************************
|
---|
2 | *
|
---|
3 | * bitio_m_random.h -- Macros for bitio to a file (random access)
|
---|
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 an array
|
---|
23 | * of chars. These routines are slower than the ones in "mem" files. but
|
---|
24 | * with these routines you can mix reads and writes, or multiple writes, on
|
---|
25 | * the array of chars at the same time and guarantee them to work, also you
|
---|
26 | * can seek to a point and do a write. The decode and encode macros cannot
|
---|
27 | * detect when the end off the character is reached and just continue
|
---|
28 | * processing.
|
---|
29 | *
|
---|
30 | *
|
---|
31 | **************************************************************************/
|
---|
32 |
|
---|
33 | #ifndef H_BITIO_M_RANDOM
|
---|
34 | #define H_BITIO_M_RANDOM
|
---|
35 |
|
---|
36 | #include "longlong.h"
|
---|
37 | #include "bitio_m_abstract.h"
|
---|
38 |
|
---|
39 |
|
---|
40 | class random_bitio_buffer : public bitio_buffer {
|
---|
41 | public:
|
---|
42 | FILE *file;
|
---|
43 | unsigned char *buffer;
|
---|
44 | unsigned long base;
|
---|
45 | unsigned long used;
|
---|
46 | unsigned long pos;
|
---|
47 | unsigned long len;
|
---|
48 | unsigned long shift;
|
---|
49 | void writeRead();
|
---|
50 |
|
---|
51 | random_bitio_buffer(FILE *f = 0,
|
---|
52 | unsigned long length = 8*1024);
|
---|
53 | virtual ~random_bitio_buffer();
|
---|
54 |
|
---|
55 | void attachFile (FILE *f, unsigned long length);
|
---|
56 |
|
---|
57 | random_bitio_buffer &operator= (const random_bitio_buffer &_rbb);
|
---|
58 |
|
---|
59 | void encodeDone();
|
---|
60 | void encodeBit(int b);
|
---|
61 | void flush();
|
---|
62 | unsigned long tell();
|
---|
63 |
|
---|
64 | void seek(unsigned long topos);
|
---|
65 | void error();
|
---|
66 | long add00(long b);
|
---|
67 | long addff(long b);
|
---|
68 | int bit();
|
---|
69 | int bitOffset();
|
---|
70 | void done();
|
---|
71 |
|
---|
72 | #ifdef USE_LONG_LONG
|
---|
73 | // extras for longlong.h
|
---|
74 | void seek_LL(mg_ullong pos);
|
---|
75 | mg_ullong tell_LL();
|
---|
76 | #endif
|
---|
77 | };
|
---|
78 |
|
---|
79 |
|
---|
80 | /*#define ENCODE_START(f,l) \
|
---|
81 | { \
|
---|
82 | random_bitio_buffer buffer(f, l);
|
---|
83 |
|
---|
84 | #define ENCODE_CONTINUE(b) \
|
---|
85 | { \
|
---|
86 | random_bitio_buffer buffer; \
|
---|
87 | buffer.unpause(b);
|
---|
88 |
|
---|
89 | #define SEEK fprintf(stderr, "Seek to %d\n",buffer.base)
|
---|
90 | #define READ fprintf(stderr, "Read of %d\n",buffer.len)
|
---|
91 | #define WRITE fprintf(stderr, "Write of %d\n",buffer.used)
|
---|
92 |
|
---|
93 | #define WRITE_READ buffer.writeRead()
|
---|
94 |
|
---|
95 | #define ENCODE_PAUSE(b) buffer.pause(&b);}
|
---|
96 |
|
---|
97 | #define ENCODE_FLUSH buffer.flush();
|
---|
98 |
|
---|
99 | #define ENCODE_DONE buffer.done();}
|
---|
100 |
|
---|
101 | #define DECODE_START(f,l) \
|
---|
102 | { \
|
---|
103 | random_bitio_buffer buffer(f, l);
|
---|
104 |
|
---|
105 | #define DECODE_CONTINUE(b) \
|
---|
106 | { \
|
---|
107 | random_bitio_buffer buffer; \
|
---|
108 | buffer.unpause(b);
|
---|
109 |
|
---|
110 | #define DECODE_BIT buffer.bit()
|
---|
111 |
|
---|
112 | #define DECODE_ADD_FF(b) b = buffer.addff(b)
|
---|
113 |
|
---|
114 | #define DECODE_ADD_00(b) b = buffer.add00(b)
|
---|
115 |
|
---|
116 | #define DECODE_DONE buffer.done();}
|
---|
117 |
|
---|
118 | #define DECODE_PAUSE(b) buffer.pause(&b);}
|
---|
119 |
|
---|
120 | #define ENCODE_TELL buffer.tell()
|
---|
121 |
|
---|
122 | #define DECODE_TELL buffer.tell()
|
---|
123 | */
|
---|
124 |
|
---|
125 |
|
---|
126 |
|
---|
127 | #endif
|
---|