1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WW8StructBase.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_WW8_STRUCT_BASE_HXX
32 #define INCLUDED_WW8_STRUCT_BASE_HXX
34 #include <boost/shared_ptr.hpp>
35 #include <doctok/WW8Document.hxx>
36 #include <resourcemodel/OutputWithDepth.hxx>
38 namespace writerfilter
{
41 class WW8DocumentImpl
;
46 A part can have a parent, meaning its sequence of data is a
47 subsequence of its parent's sequence of data.
52 typedef SubSequence
<sal_uInt8
> Sequence
;
53 typedef boost::shared_ptr
<WW8StructBase
> Pointer_t
;
57 Stream this part was created from.
59 ::com::sun::star::uno::Reference
<com::sun::star::io::
60 XInputStream
> mrStream
;
65 mutable Sequence mSequence
;
70 WW8StructBase
* mpParent
;
73 This part's offset in parent.
75 sal_uInt32 mnOffsetInParent
;
78 The document of this struct.
80 WW8DocumentImpl
* mpDocument
;
83 WW8StructBase(sal_Int32 nLength
)
89 Creates a part from a steam.
91 @param rStream the stream
92 @param nOffset offset in @a rStream to start at
93 @param nCount count of bytes in the new part
95 WW8StructBase(WW8Stream
& rStream
,
96 sal_Int32 nOffset
, sal_Int32 nCount
)
97 : mSequence(rStream
.get(nOffset
, nCount
)), mpParent(0), mpDocument(0)
102 Creates a part from a sequence.
104 @param rSequence the sequence
105 @param nOffset offset in @a rSequence to start at
106 @param nCount count of bytes in the new part
108 WW8StructBase(const Sequence
& rSequence
, sal_uInt32 nOffset
= 0,
109 sal_uInt32 nCount
= 0)
110 : mSequence(rSequence
, nOffset
, nCount
), mpParent(0), mpDocument(0)
115 Creates a part from a parent part.
117 @param pParent the parent
118 @param nOffset offset in @a pParent to start at
119 @param nCount count of bytes in the new part
121 WW8StructBase(const WW8StructBase
& rParent
,
122 sal_uInt32 nOffset
, sal_uInt32 nCount
);
125 Creates a part from a parent part.
127 @param pParent the parent
128 @param nOffset offset in @a pParent to start at
129 @param nCount count of bytes in the new part
131 WW8StructBase(WW8StructBase
* pParent
,
132 sal_uInt32 nOffset
, sal_uInt32 nCount
)
133 : mSequence(pParent
->mSequence
, nOffset
, nCount
), mpParent(pParent
),
134 mnOffsetInParent(nOffset
), mpDocument(pParent
->getDocument())
136 if (nOffset
+ nCount
> pParent
->mSequence
.getCount())
137 throw ExceptionOutOfBounds("WW8StructBase");
141 virtual ~WW8StructBase()
146 Assign a part to this part.
148 After assignment this part has the same content as the assigned
151 @param rSrc part to assign
153 @return this part after assignment
155 virtual WW8StructBase
& Assign(const WW8StructBase
& rSrc
);
158 Set the document of this struct.
160 void setDocument(WW8DocumentImpl
* pDocument
);
163 Return the document of this struct.
165 WW8DocumentImpl
* getDocument() const;
168 Return count of bytes in this part.
170 sal_uInt32
getCount() const { return mSequence
.getCount(); }
173 Return unsigned byte value at an offset.
175 @param offset offset to get value from
177 sal_uInt8
getU8(sal_uInt32 nOffset
) const;
180 Return unsigned 16-bit value at an offset.
182 @param offset offset to get value from
184 sal_uInt16
getU16(sal_uInt32 nOffset
) const;
187 Return unsigned 32-bit value at an offset.
189 @param offset offset to get value from
191 sal_uInt32
getU32(sal_uInt32 nOffset
) const;
194 Return signed 8-bit value at an offset.
196 @param offset offset to get value from
198 sal_Int8
getS8(sal_uInt32 nOffset
) const
199 { return (sal_Int8
) getU8(nOffset
); }
202 Return signed 16-bit value at an offset.
204 @param offset offset to get value from
206 sal_Int16
getS16(sal_uInt32 nOffset
) const
207 {return (sal_Int16
) getU16(nOffset
); }
210 Return signed 32-bit value at an offset.
212 @param offset offset to get value from
214 sal_Int32
getS32(sal_uInt32 nOffset
) const
215 { return (sal_Int32
) getU32(nOffset
); }
218 Return bit value from a 32-bit unsigned value.
220 @param nValue value to retreive bit from
221 @param nBit number of bit to retreive (0 = least significant)
223 sal_Bool
getBit(sal_uInt32 nValue
, sal_uInt16 nBit
) const;
226 Return nibble from a 32-bit unsigned value.
228 @param nValue value to retreive nibble from (most significant bit left)
229 @param nShift amount of bits to shift right before returning least significant nibble
231 sal_uInt8
getNibble(sal_uInt32 nValue
, sal_uInt16 nShift
) const;
234 Returns byte at an index.
236 @param nIndex index in this part of the byte to return
238 const sal_uInt8
* get(sal_uInt32 nIndex
) const
239 { return &((mSequence
.getSequence())[nIndex
+ mSequence
.getOffset()]); }
242 Returns two byte character string starting at an offset.
244 The string has to be Pascal like, e.g. the first word contains
245 the lengthof the string in characters and is followed by the
248 @param nOffset offset the string starts at
252 rtl::OUString
getString(sal_uInt32 nOffset
) const;
255 Returns binary object for remainder of this WW8StructBase
257 @param nOffset offset where remainder starts
259 WW8StructBase
* getRemainder(sal_uInt32 nOffset
) const;
262 Returns two byte character string starting at an offset with a
265 @param nOffset offset the string starts at
266 @param nLength number of characters in the string
268 rtl::OUString
getString(sal_uInt32 nOffset
, sal_uInt32
) const;
273 @param o stream to dump to
275 virtual void dump(OutputWithDepth
<string
> & o
) const { mSequence
.dump(o
); }
278 class WW8StructBaseTmpOffset
281 WW8StructBase
* mpStructBase
;
284 WW8StructBaseTmpOffset(WW8StructBase
* pStructBase
);
286 sal_uInt32
set(sal_uInt32 nOffset
);
287 sal_uInt32
get() const;
288 sal_uInt32
inc(sal_uInt32 nOffset
);
290 operator sal_uInt32 () const;
294 Return unsigned byte from a sequence.
296 @param rSeq sequence to get value from
297 @param nOffset offset in sequence to get value from
299 sal_uInt8
getU8(const WW8StructBase::Sequence
& rSeq
, sal_uInt32 nOffset
);
302 Return unsigned 16-bit value from a sequence.
304 @param rSeq sequence to get value from
305 @param nOffset offset in sequence to get value from
307 sal_uInt16
getU16(const WW8StructBase::Sequence
& rSeq
, sal_uInt32 nOffset
);
310 Return unsigned 32-bit value from a sequence.
312 @param rSeq sequence to get value from
313 @param nOffset offset in sequence to get value from
315 sal_uInt32
getU32(const WW8StructBase::Sequence
& rSeq
, sal_uInt32 nOffset
);
319 #endif // INCLUDED_WW8_STRUCT_BASE_HXX