Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #ifndef _XMLSEARCH_UTIL_DECOMPRESSOR_HXX_
29 : : #define _XMLSEARCH_UTIL_DECOMPRESSOR_HXX_
30 : :
31 : : #include <vector>
32 : : #include <excep/XmlSearchExceptions.hxx>
33 : : #include <util/RandomAccessStream.hxx>
34 : :
35 : : namespace xmlsearch {
36 : :
37 : : namespace util {
38 : :
39 : :
40 : : class Decompressor
41 : : {
42 : : public:
43 : :
44 : : Decompressor()
45 : : : toRead_( 0 )
46 : : {
47 : : }
48 : :
49 [ # # ]: 0 : virtual ~Decompressor() { }
50 : :
51 : : virtual sal_Int32 getNextByte() = 0;
52 : :
53 : 0 : virtual void initReading()
54 : : {
55 : 0 : toRead_ = 0;
56 : 0 : }
57 : :
58 : : private:
59 : :
60 : : static const sal_Int32 BitsInByte;
61 : : static const sal_Int32 NBits;
62 : :
63 : : sal_Int32 toRead_;
64 : : };
65 : :
66 : :
67 : :
68 : :
69 : : class StreamDecompressor
70 : : : public Decompressor
71 : : {
72 : : public:
73 : :
74 : : StreamDecompressor( RandomAccessStream* in )
75 : : : in_( in )
76 : : {
77 : : }
78 : :
79 [ # # ]: 0 : ~StreamDecompressor() { }
80 : :
81 : :
82 : : virtual sal_Int32 getNextByte();
83 : :
84 : : private:
85 : :
86 : : RandomAccessStream* in_;
87 : :
88 : : };
89 : :
90 : :
91 : :
92 : : class ByteArrayDecompressor
93 : : : public Decompressor
94 : : {
95 : : public:
96 : :
97 : : ByteArrayDecompressor( sal_Int32 arrayL,sal_Int8* array,sal_Int32 index )
98 : : {
99 : : initReading(array,arrayL,index);
100 : : }
101 : :
102 : :
103 [ # # ]: 0 : ~ByteArrayDecompressor() { }
104 : :
105 : : sal_Int32 bytesRead()
106 : : {
107 : : return index_ - index0_;
108 : : }
109 : :
110 : :
111 : 0 : sal_Int32 getNextByte() throw( xmlsearch::excep::XmlSearchException )
112 : : {
113 [ # # ]: 0 : if( arrayL_ <= index_ )
114 : : throw xmlsearch::excep::XmlSearchException(
115 [ # # ]: 0 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ByteArrayDecompressor->getNextByte()" )) );
116 : 0 : return array_[index_++] & 0xFF;
117 : : }
118 : :
119 : :
120 : : private:
121 : :
122 : : sal_Int32 arrayL_;
123 : : sal_Int8 *array_;
124 : :
125 : : sal_Int32 index_,index0_;
126 : :
127 : : using xmlsearch::util::Decompressor::initReading;
128 : : void initReading( sal_Int8* array,sal_Int32 arrayL,sal_Int32 index )
129 : : {
130 : : arrayL_ = arrayL;
131 : : array_ = array;
132 : : index_ = index0_ = index;
133 : : Decompressor::initReading();
134 : : }
135 : :
136 : : };
137 : :
138 : :
139 : : }
140 : :
141 : : }
142 : :
143 : :
144 : : #endif
145 : :
146 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|