1 | /**************************************************************************
|
---|
2 | *
|
---|
3 | * bitio_m_mems.h -- Macros for bitio to memory (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 | #ifndef H_BITIO_M_MEMS
|
---|
33 | #define H_BITIO_M_MEMS
|
---|
34 |
|
---|
35 | #include "bitio_m_abstract.h"
|
---|
36 |
|
---|
37 |
|
---|
38 | class mems_bitio_buffer : public bitio_buffer {
|
---|
39 | protected:
|
---|
40 | unsigned char *base;
|
---|
41 | unsigned long pos;
|
---|
42 |
|
---|
43 | public:
|
---|
44 | mems_bitio_buffer();
|
---|
45 | mems_bitio_buffer(unsigned char *readbuffer, long _pos);
|
---|
46 | void seek(unsigned long topos);
|
---|
47 | void error();
|
---|
48 | long add00(long b);
|
---|
49 | long addff(long b);
|
---|
50 | int bit();
|
---|
51 | // int bitOffset();
|
---|
52 | void done();
|
---|
53 |
|
---|
54 | unsigned long position();
|
---|
55 |
|
---|
56 | void encodeStart();
|
---|
57 | void encodeBit(int b);
|
---|
58 | void encodeDone();
|
---|
59 | void flush();
|
---|
60 | };
|
---|
61 |
|
---|
62 |
|
---|
63 | /*#define ENCODE_START(b,p) \
|
---|
64 | { \
|
---|
65 | mems_bitio_buffer buffer(b, p);
|
---|
66 |
|
---|
67 | #define ENCODE_CONTINUE(b) \
|
---|
68 | { \
|
---|
69 | mems_bitio_buffer buffer; \
|
---|
70 | buffer.unpause(b);
|
---|
71 |
|
---|
72 | #define ENCODE_PAUSE(b) buffer.pause(&b);}
|
---|
73 |
|
---|
74 | #define ENCODE_FLUSH buffer.flush();
|
---|
75 |
|
---|
76 |
|
---|
77 | #define ENCODE_DONE buffer.encodeDone();}
|
---|
78 |
|
---|
79 |
|
---|
80 | #define DECODE_START(b,p) \
|
---|
81 | { \
|
---|
82 | mems_bitio_buffer buffer(b, p);
|
---|
83 |
|
---|
84 | #define DECODE_CONTINUE(b) \
|
---|
85 | { \
|
---|
86 | mems_bitio_buffer buffer; \
|
---|
87 | buffer.unpause(b);
|
---|
88 |
|
---|
89 | #define DECODE_ADD_FF(b) b = buffer.addff(b);
|
---|
90 |
|
---|
91 | #define DECODE_ADD_00(b) b = buffer.add00(b);
|
---|
92 |
|
---|
93 | #define DECODE_BIT buffer.bit()
|
---|
94 |
|
---|
95 | #define DECODE_DONE buffer.done();}
|
---|
96 |
|
---|
97 | #define DECODE_PAUSE(b) buffer.pause(&b);}
|
---|
98 | */
|
---|
99 |
|
---|
100 | #endif
|
---|