source: trunk/gsdl/src/mgpp/lib/bitio_m_random.h@ 855

Last change on this file since 855 was 855, checked in by sjboddie, 24 years ago

Rodgers new C++ mg

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