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