Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #ifndef INCLUDED_WW8_STRUCT_BASE_HXX
21 : : #define INCLUDED_WW8_STRUCT_BASE_HXX
22 : :
23 : : #include <boost/shared_ptr.hpp>
24 : : #include <doctok/WW8Document.hxx>
25 : : #include <resourcemodel/OutputWithDepth.hxx>
26 : :
27 : : namespace writerfilter {
28 : : namespace doctok {
29 : :
30 : : class WW8DocumentImpl;
31 : :
32 : : /**
33 : : Part of a stream.
34 : :
35 : : A part can have a parent, meaning its sequence of data is a
36 : : subsequence of its parent's sequence of data.
37 : : */
38 [ # # ]: 0 : class WW8StructBase
39 : : {
40 : : public:
41 : : typedef SubSequence<sal_uInt8> Sequence;
42 : : typedef boost::shared_ptr<WW8StructBase> Pointer_t;
43 : :
44 : : protected:
45 : : /**
46 : : Stream this part was created from.
47 : : */
48 : : ::com::sun::star::uno::Reference<com::sun::star::io::
49 : : XInputStream> mrStream;
50 : :
51 : : /**
52 : : The data.
53 : : */
54 : : mutable Sequence mSequence;
55 : :
56 : : /**
57 : : This part's parent.
58 : : */
59 : : WW8StructBase * mpParent;
60 : :
61 : : /**
62 : : This part's offset in parent.
63 : : */
64 : : sal_uInt32 mnOffsetInParent;
65 : :
66 : : /**
67 : : The document of this struct.
68 : : */
69 : : WW8DocumentImpl * mpDocument;
70 : :
71 : : public:
72 : : WW8StructBase(sal_Int32 nLength)
73 : : : mSequence(nLength)
74 : : {
75 : : }
76 : :
77 : : /**
78 : : Creates a part from a steam.
79 : :
80 : : @param rStream the stream
81 : : @param nOffset offset in @a rStream to start at
82 : : @param nCount count of bytes in the new part
83 : : */
84 : 0 : WW8StructBase(WW8Stream & rStream,
85 : : sal_Int32 nOffset, sal_Int32 nCount)
86 [ # # ]: 0 : : mSequence(rStream.get(nOffset, nCount)), mpParent(0), mpDocument(0)
87 : : {
88 : 0 : }
89 : :
90 : : /**
91 : : Creates a part from a sequence.
92 : :
93 : : @param rSequence the sequence
94 : : @param nOffset offset in @a rSequence to start at
95 : : @param nCount count of bytes in the new part
96 : : */
97 : 0 : WW8StructBase(const Sequence & rSequence, sal_uInt32 nOffset = 0,
98 : : sal_uInt32 nCount = 0)
99 [ # # ]: 0 : : mSequence(rSequence, nOffset, nCount), mpParent(0), mpDocument(0)
100 : : {
101 : 0 : }
102 : :
103 : : /**
104 : : Creates a part from a parent part.
105 : :
106 : : @param pParent the parent
107 : : @param nOffset offset in @a pParent to start at
108 : : @param nCount count of bytes in the new part
109 : : */
110 : : WW8StructBase(const WW8StructBase & rParent,
111 : : sal_uInt32 nOffset, sal_uInt32 nCount);
112 : :
113 : : /**
114 : : Creates a part from a parent part.
115 : :
116 : : @param pParent the parent
117 : : @param nOffset offset in @a pParent to start at
118 : : @param nCount count of bytes in the new part
119 : : */
120 : 0 : WW8StructBase(WW8StructBase * pParent,
121 : : sal_uInt32 nOffset, sal_uInt32 nCount)
122 : : : mSequence(pParent->mSequence, nOffset, nCount), mpParent(pParent),
123 [ # # ][ # # ]: 0 : mnOffsetInParent(nOffset), mpDocument(pParent->getDocument())
124 : : {
125 [ # # ]: 0 : if (nOffset + nCount > pParent->mSequence.getCount())
126 [ # # ][ # # ]: 0 : throw ExceptionOutOfBounds("WW8StructBase");
127 : 0 : }
128 : :
129 : :
130 : 0 : virtual ~WW8StructBase()
131 [ # # ]: 0 : {
132 [ # # ]: 0 : }
133 : :
134 : : /**
135 : : Assign a part to this part.
136 : :
137 : : After assignment this part has the same content as the assigned
138 : : part.
139 : :
140 : : @param rSrc part to assign
141 : :
142 : : @return this part after assignment
143 : : */
144 : : virtual WW8StructBase & Assign(const WW8StructBase & rSrc);
145 : :
146 : : /**
147 : : Set the document of this struct.
148 : : */
149 : : void setDocument(WW8DocumentImpl * pDocument);
150 : :
151 : : /**
152 : : Return the document of this struct.
153 : : */
154 : : WW8DocumentImpl * getDocument() const;
155 : :
156 : : /**
157 : : Return count of bytes in this part.
158 : : */
159 : 0 : sal_uInt32 getCount() const { return mSequence.getCount(); }
160 : :
161 : : /**
162 : : Return unsigned byte value at an offset.
163 : :
164 : : @param offset offset to get value from
165 : : */
166 : : sal_uInt8 getU8(sal_uInt32 nOffset) const;
167 : :
168 : : /**
169 : : Return unsigned 16-bit value at an offset.
170 : :
171 : : @param offset offset to get value from
172 : : */
173 : : sal_uInt16 getU16(sal_uInt32 nOffset) const;
174 : :
175 : : /**
176 : : Return unsigned 32-bit value at an offset.
177 : :
178 : : @param offset offset to get value from
179 : : */
180 : : sal_uInt32 getU32(sal_uInt32 nOffset) const;
181 : :
182 : : /**
183 : : Return signed 8-bit value at an offset.
184 : :
185 : : @param offset offset to get value from
186 : : */
187 : 0 : sal_Int8 getS8(sal_uInt32 nOffset) const
188 : 0 : { return (sal_Int8) getU8(nOffset); }
189 : :
190 : : /**
191 : : Return signed 16-bit value at an offset.
192 : :
193 : : @param offset offset to get value from
194 : : */
195 : 0 : sal_Int16 getS16(sal_uInt32 nOffset) const
196 : 0 : {return (sal_Int16) getU16(nOffset); }
197 : :
198 : : /**
199 : : Return signed 32-bit value at an offset.
200 : :
201 : : @param offset offset to get value from
202 : : */
203 : 0 : sal_Int32 getS32(sal_uInt32 nOffset) const
204 : 0 : { return (sal_Int32) getU32(nOffset); }
205 : :
206 : : /**
207 : : Returns byte at an index.
208 : :
209 : : @param nIndex index in this part of the byte to return
210 : : */
211 : 0 : const sal_uInt8 * get(sal_uInt32 nIndex) const
212 : 0 : { return &((mSequence.getSequence())[nIndex + mSequence.getOffset()]); }
213 : :
214 : : /**
215 : : Returns two byte character string starting at an offset.
216 : :
217 : : The string has to be Pascal like, e.g. the first word contains
218 : : the lengthof the string in characters and is followed by the
219 : : string's characters.
220 : :
221 : : @param nOffset offset the string starts at
222 : :
223 : : @return the string
224 : : */
225 : : OUString getString(sal_uInt32 nOffset) const;
226 : :
227 : : /**
228 : : Returns binary object for remainder of this WW8StructBase
229 : :
230 : : @param nOffset offset where remainder starts
231 : : */
232 : : WW8StructBase * getRemainder(sal_uInt32 nOffset) const;
233 : :
234 : : /**
235 : : Returns two byte character string starting at an offset with a
236 : : given length.
237 : :
238 : : @param nOffset offset the string starts at
239 : : @param nLength number of characters in the string
240 : : */
241 : : OUString getString(sal_uInt32 nOffset, sal_uInt32) const;
242 : :
243 : : /**
244 : : Dump the part.
245 : :
246 : : @param o stream to dump to
247 : : */
248 : 0 : virtual void dump(OutputWithDepth<string> & o) const { mSequence.dump(o); }
249 : : };
250 : :
251 : : class WW8StructBaseTmpOffset
252 : : {
253 : : sal_uInt32 mnOffset;
254 : : WW8StructBase * mpStructBase;
255 : :
256 : : public:
257 : : WW8StructBaseTmpOffset(WW8StructBase * pStructBase);
258 : :
259 : : sal_uInt32 set(sal_uInt32 nOffset);
260 : : sal_uInt32 get() const;
261 : : sal_uInt32 inc(sal_uInt32 nOffset);
262 : :
263 : : operator sal_uInt32 () const;
264 : : };
265 : :
266 : : /**
267 : : Return unsigned byte from a sequence.
268 : :
269 : : @param rSeq sequence to get value from
270 : : @param nOffset offset in sequence to get value from
271 : : */
272 : : sal_uInt8 getU8(const WW8StructBase::Sequence & rSeq, sal_uInt32 nOffset);
273 : :
274 : : /**
275 : : Return unsigned 16-bit value from a sequence.
276 : :
277 : : @param rSeq sequence to get value from
278 : : @param nOffset offset in sequence to get value from
279 : : */
280 : : sal_uInt16 getU16(const WW8StructBase::Sequence & rSeq, sal_uInt32 nOffset);
281 : :
282 : : /**
283 : : Return unsigned 32-bit value from a sequence.
284 : :
285 : : @param rSeq sequence to get value from
286 : : @param nOffset offset in sequence to get value from
287 : : */
288 : : sal_uInt32 getU32(const WW8StructBase::Sequence & rSeq, sal_uInt32 nOffset);
289 : :
290 : : }}
291 : :
292 : : #endif // INCLUDED_WW8_STRUCT_BASE_HXX
293 : :
294 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|