xref: /trunk/main/xmlhelp/source/cxxhelp/inc/util/Decompressor.hxx (revision 914d351e5f5b84e4342a86d6ab8d4aca7308b9bd)
1*7b6bd0c4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*7b6bd0c4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*7b6bd0c4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*7b6bd0c4SAndrew Rist  * distributed with this work for additional information
6*7b6bd0c4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*7b6bd0c4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*7b6bd0c4SAndrew Rist  * "License"); you may not use this file except in compliance
9*7b6bd0c4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*7b6bd0c4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*7b6bd0c4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*7b6bd0c4SAndrew Rist  * software distributed under the License is distributed on an
15*7b6bd0c4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*7b6bd0c4SAndrew Rist  * KIND, either express or implied.  See the License for the
17*7b6bd0c4SAndrew Rist  * specific language governing permissions and limitations
18*7b6bd0c4SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*7b6bd0c4SAndrew Rist  *************************************************************/
21*7b6bd0c4SAndrew Rist 
22*7b6bd0c4SAndrew Rist 
23cdf0e10cSrcweir #ifndef _XMLSEARCH_UTIL_DECOMPRESSOR_HXX_
24cdf0e10cSrcweir #define _XMLSEARCH_UTIL_DECOMPRESSOR_HXX_
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #ifndef INCLUDED_STL_VECTOR
27cdf0e10cSrcweir #include <vector>
28cdf0e10cSrcweir #define INCLUDED_STL_VECTOR
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #include <excep/XmlSearchExceptions.hxx>
31cdf0e10cSrcweir #include <util/RandomAccessStream.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace xmlsearch {
35cdf0e10cSrcweir 
36cdf0e10cSrcweir     namespace util {
37cdf0e10cSrcweir 
38cdf0e10cSrcweir 
39cdf0e10cSrcweir         class CompressorIterator;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir 
42cdf0e10cSrcweir         class Decompressor
43cdf0e10cSrcweir         {
44cdf0e10cSrcweir         public:
45cdf0e10cSrcweir 
Decompressor()46cdf0e10cSrcweir             Decompressor()
47cdf0e10cSrcweir                 : toRead_( 0 ),
48cdf0e10cSrcweir                   path_( 0 )
49cdf0e10cSrcweir             {
50cdf0e10cSrcweir             }
51cdf0e10cSrcweir 
~Decompressor()52cdf0e10cSrcweir             virtual ~Decompressor() { }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir             virtual sal_Int32 getNextByte() = 0;
55cdf0e10cSrcweir 
initReading()56cdf0e10cSrcweir             virtual void initReading()
57cdf0e10cSrcweir             {
58cdf0e10cSrcweir                 toRead_ = 0;
59cdf0e10cSrcweir             }
60cdf0e10cSrcweir 
61cdf0e10cSrcweir         private:
62cdf0e10cSrcweir 
63cdf0e10cSrcweir             static const sal_Int32 BitsInByte;
64cdf0e10cSrcweir             static const sal_Int32 NBits;
65cdf0e10cSrcweir 
66cdf0e10cSrcweir             sal_Int32 readByte_, toRead_, path_;
67cdf0e10cSrcweir         };
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 
72cdf0e10cSrcweir         class StreamDecompressor
73cdf0e10cSrcweir             : public Decompressor
74cdf0e10cSrcweir         {
75cdf0e10cSrcweir         public:
76cdf0e10cSrcweir 
StreamDecompressor(RandomAccessStream * in)77cdf0e10cSrcweir             StreamDecompressor( RandomAccessStream* in )
78cdf0e10cSrcweir                 : in_( in )
79cdf0e10cSrcweir             {
80cdf0e10cSrcweir             }
81cdf0e10cSrcweir 
~StreamDecompressor()82cdf0e10cSrcweir             ~StreamDecompressor() { }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 
85cdf0e10cSrcweir             virtual sal_Int32 getNextByte();
86cdf0e10cSrcweir 
87cdf0e10cSrcweir         private:
88cdf0e10cSrcweir 
89cdf0e10cSrcweir             RandomAccessStream* in_;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir         };
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 
95cdf0e10cSrcweir         class ByteArrayDecompressor
96cdf0e10cSrcweir             : public Decompressor
97cdf0e10cSrcweir         {
98cdf0e10cSrcweir         public:
99cdf0e10cSrcweir 
ByteArrayDecompressor(sal_Int32 arrayL,sal_Int8 * array,sal_Int32 index)100cdf0e10cSrcweir             ByteArrayDecompressor( sal_Int32 arrayL,sal_Int8* array,sal_Int32 index )
101cdf0e10cSrcweir             {
102cdf0e10cSrcweir                 initReading(array,arrayL,index);
103cdf0e10cSrcweir             }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 
~ByteArrayDecompressor()106cdf0e10cSrcweir             ~ByteArrayDecompressor() { }
107cdf0e10cSrcweir 
bytesRead()108cdf0e10cSrcweir             sal_Int32 bytesRead()
109cdf0e10cSrcweir             {
110cdf0e10cSrcweir                 return index_ - index0_;
111cdf0e10cSrcweir             }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 
getNextByte()114cdf0e10cSrcweir             sal_Int32 getNextByte() throw( xmlsearch::excep::XmlSearchException )
115cdf0e10cSrcweir             {
116cdf0e10cSrcweir                 if( arrayL_ <= index_ )
117cdf0e10cSrcweir                     throw  xmlsearch::excep::XmlSearchException(
118cdf0e10cSrcweir                         rtl::OUString::createFromAscii( "ByteArrayDecompressor->getNextByte()" ) );
119cdf0e10cSrcweir                 return array_[index_++] & 0xFF;
120cdf0e10cSrcweir             }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 
123cdf0e10cSrcweir         private:
124cdf0e10cSrcweir 
125cdf0e10cSrcweir             sal_Int32  arrayL_;
126cdf0e10cSrcweir             sal_Int8   *array_;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir             sal_Int32  index_,index0_;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir             using xmlsearch::util::Decompressor::initReading;
initReading(sal_Int8 * array,sal_Int32 arrayL,sal_Int32 index)131cdf0e10cSrcweir             void initReading( sal_Int8* array,sal_Int32 arrayL,sal_Int32 index )
132cdf0e10cSrcweir             {
133cdf0e10cSrcweir                 arrayL_ = arrayL;
134cdf0e10cSrcweir                 array_ = array;
135cdf0e10cSrcweir                 index_ = index0_ = index;
136cdf0e10cSrcweir                 Decompressor::initReading();
137cdf0e10cSrcweir             }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir         };
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 
147cdf0e10cSrcweir #endif
148