1 | /**************************************************************************
|
---|
2 | *
|
---|
3 | * FText.h -- File structures for text compression
|
---|
4 | * Copyright (C) 1999 Rodger McNab
|
---|
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: FText.h 855 2000-01-14 02:17:52Z sjboddie $
|
---|
21 | *
|
---|
22 | **************************************************************************/
|
---|
23 |
|
---|
24 | #ifndef FTEXT_H
|
---|
25 | #define FTEXT_H
|
---|
26 |
|
---|
27 | #if defined(GSDL_USE_OBJECTSPACE)
|
---|
28 | # include <ospace\std\map>
|
---|
29 | #elif defined(GSDL_USE_STL_H)
|
---|
30 | # include <map.h>
|
---|
31 | #else
|
---|
32 | # include <map>
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | #include <stdio.h>
|
---|
36 | #include "UCArray.h"
|
---|
37 |
|
---|
38 |
|
---|
39 | // holds a bit address
|
---|
40 | class BitAddr {
|
---|
41 | public:
|
---|
42 | unsigned long byte;
|
---|
43 | unsigned char bit;
|
---|
44 |
|
---|
45 | BitAddr ();
|
---|
46 | void Clear ();
|
---|
47 |
|
---|
48 | bool Read (FILE *f);
|
---|
49 | bool Write (FILE *f) const;
|
---|
50 | };
|
---|
51 |
|
---|
52 |
|
---|
53 | class TextLevelInfo {
|
---|
54 | public:
|
---|
55 | UCArray levelTag;
|
---|
56 | unsigned long textIdxPtr;
|
---|
57 | unsigned long numEntries;
|
---|
58 |
|
---|
59 | TextLevelInfo ();
|
---|
60 | void Clear ();
|
---|
61 |
|
---|
62 | bool Read (FILE *f);
|
---|
63 | bool Write (FILE *f) const;
|
---|
64 | };
|
---|
65 |
|
---|
66 | // stream output for debugging purposes
|
---|
67 | ostream &operator<<(ostream &s, const TextLevelInfo &l);
|
---|
68 |
|
---|
69 |
|
---|
70 | typedef map<UCArray, TextLevelInfo, LTUCArray> TextLevelInfoMap;
|
---|
71 |
|
---|
72 |
|
---|
73 | class FTextLevel {
|
---|
74 | public:
|
---|
75 | TextLevelInfoMap levelInfo;
|
---|
76 |
|
---|
77 | FTextLevel ();
|
---|
78 | void Clear ();
|
---|
79 |
|
---|
80 | bool Read (FILE *f);
|
---|
81 | bool Write (FILE *f) const;
|
---|
82 | };
|
---|
83 |
|
---|
84 | // stream output for debugging purposes
|
---|
85 | ostream &operator<<(ostream &s, const FTextLevel &l);
|
---|
86 |
|
---|
87 |
|
---|
88 | // the text.idx file points into the compressed text
|
---|
89 | class TextIdx {
|
---|
90 | public:
|
---|
91 | BitAddr start; // the first bit of the compressed text
|
---|
92 | BitAddr end; // the first bit past the end of the text
|
---|
93 | unsigned char which; // 0 = non-word, 1 = word
|
---|
94 |
|
---|
95 | TextIdx ();
|
---|
96 | void Clear ();
|
---|
97 |
|
---|
98 | // does a seek and reads the appropriate record
|
---|
99 | bool Read (FILE *f, const TextLevelInfo &levelInfo,
|
---|
100 | unsigned long docNum);
|
---|
101 |
|
---|
102 | bool Read (FILE *f);
|
---|
103 | bool Write (FILE *f) const;
|
---|
104 | };
|
---|
105 |
|
---|
106 | // stream output for debugging purposes
|
---|
107 | ostream &operator<<(ostream &s, const TextIdx &t);
|
---|
108 |
|
---|
109 |
|
---|
110 | // note: document numbers start at 1
|
---|
111 |
|
---|
112 | bool SeekTextIdx (FILE *f, const TextLevelInfo &levelInfo,
|
---|
113 | unsigned long docNum);
|
---|
114 |
|
---|
115 |
|
---|
116 | // used to store the pointers while compressing the text
|
---|
117 | typedef vector<TextIdx> TextIdxArray;
|
---|
118 |
|
---|
119 | bool ReadTextIdxArray (FILE *f, TextIdxArray &a, unsigned long arrSize);
|
---|
120 | bool WriteTextIdxArray (FILE *f, const TextIdxArray &a);
|
---|
121 |
|
---|
122 |
|
---|
123 | // used to store information about a level while compressing the text
|
---|
124 | class CompressTextInfo {
|
---|
125 | public:
|
---|
126 | bool inDoc;
|
---|
127 | BitAddr start;
|
---|
128 | unsigned char which;
|
---|
129 | TextIdxArray docPtrs;
|
---|
130 |
|
---|
131 | CompressTextInfo ();
|
---|
132 | void Clear ();
|
---|
133 |
|
---|
134 | // clears inDoc, start, and which (not the docPtrs)
|
---|
135 | void ResetStart ();
|
---|
136 |
|
---|
137 | // set the start of a level (closing off the last opening
|
---|
138 | // tag if needed)
|
---|
139 | void SetStart (unsigned long startPos,
|
---|
140 | unsigned char startBit,
|
---|
141 | unsigned char startWhich);
|
---|
142 |
|
---|
143 | // if in a document, it will set the end, add the document to the
|
---|
144 | // list of document ptrs, and then call ResetStart
|
---|
145 | void SetEnd (unsigned long endPos,
|
---|
146 | unsigned char endBit);
|
---|
147 | };
|
---|
148 |
|
---|
149 | typedef map<UCArray, CompressTextInfo, LTUCArray> CompressTextInfoMap;
|
---|
150 |
|
---|
151 |
|
---|
152 | #endif
|
---|