1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_WW8_STRUCT_BASE_HXX
21 #define INCLUDED_WW8_STRUCT_BASE_HXX
23 #include <boost/shared_ptr.hpp>
24 #include <doctok/WW8Document.hxx>
25 #include <resourcemodel/OutputWithDepth.hxx>
27 namespace writerfilter
{
30 class WW8DocumentImpl
;
35 A part can have a parent, meaning its sequence of data is a
36 subsequence of its parent's sequence of data.
41 typedef SubSequence
<sal_uInt8
> Sequence
;
42 typedef boost::shared_ptr
<WW8StructBase
> Pointer_t
;
46 Stream this part was created from.
48 ::com::sun::star::uno::Reference
<com::sun::star::io::
49 XInputStream
> mrStream
;
54 mutable Sequence mSequence
;
59 WW8StructBase
* mpParent
;
62 This part's offset in parent.
64 sal_uInt32 mnOffsetInParent
;
67 The document of this struct.
69 WW8DocumentImpl
* mpDocument
;
72 WW8StructBase(sal_Int32 nLength
)
73 : mSequence(nLength
), mpParent(NULL
), mpDocument(NULL
)
78 Creates a part from a steam.
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
84 WW8StructBase(WW8Stream
& rStream
,
85 sal_Int32 nOffset
, sal_Int32 nCount
)
86 : mSequence(rStream
.get(nOffset
, nCount
)), mpParent(0), mpDocument(0)
91 Creates a part from a sequence.
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
97 WW8StructBase(const Sequence
& rSequence
, sal_uInt32 nOffset
= 0,
98 sal_uInt32 nCount
= 0)
99 : mSequence(rSequence
, nOffset
, nCount
), mpParent(0), mpDocument(0)
104 Creates a part from a parent part.
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
110 WW8StructBase(const WW8StructBase
& rParent
,
111 sal_uInt32 nOffset
, sal_uInt32 nCount
);
114 Creates a part from a parent part.
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
120 WW8StructBase(WW8StructBase
* pParent
,
121 sal_uInt32 nOffset
, sal_uInt32 nCount
)
122 : mSequence(pParent
->mSequence
, nOffset
, nCount
), mpParent(pParent
),
123 mnOffsetInParent(nOffset
), mpDocument(pParent
->getDocument())
125 if (nOffset
+ nCount
> pParent
->mSequence
.getCount())
126 throw ExceptionOutOfBounds("WW8StructBase");
130 virtual ~WW8StructBase()
135 Assign a part to this part.
137 After assignment this part has the same content as the assigned
140 @param rSrc part to assign
142 @return this part after assignment
144 virtual WW8StructBase
& Assign(const WW8StructBase
& rSrc
);
147 Set the document of this struct.
149 void setDocument(WW8DocumentImpl
* pDocument
);
152 Return the document of this struct.
154 WW8DocumentImpl
* getDocument() const;
157 Return count of bytes in this part.
159 sal_uInt32
getCount() const { return mSequence
.getCount(); }
162 Return unsigned byte value at an offset.
164 @param offset offset to get value from
166 sal_uInt8
getU8(sal_uInt32 nOffset
) const;
169 Return unsigned 16-bit value at an offset.
171 @param offset offset to get value from
173 sal_uInt16
getU16(sal_uInt32 nOffset
) const;
176 Return unsigned 32-bit value at an offset.
178 @param offset offset to get value from
180 sal_uInt32
getU32(sal_uInt32 nOffset
) const;
183 Return signed 8-bit value at an offset.
185 @param offset offset to get value from
187 sal_Int8
getS8(sal_uInt32 nOffset
) const
188 { return (sal_Int8
) getU8(nOffset
); }
191 Return signed 16-bit value at an offset.
193 @param offset offset to get value from
195 sal_Int16
getS16(sal_uInt32 nOffset
) const
196 {return (sal_Int16
) getU16(nOffset
); }
199 Return signed 32-bit value at an offset.
201 @param offset offset to get value from
203 sal_Int32
getS32(sal_uInt32 nOffset
) const
204 { return (sal_Int32
) getU32(nOffset
); }
207 Returns byte at an index.
209 @param nIndex index in this part of the byte to return
211 const sal_uInt8
* get(sal_uInt32 nIndex
) const
212 { return &((mSequence
.getSequence())[nIndex
+ mSequence
.getOffset()]); }
215 Returns two byte character string starting at an offset.
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
221 @param nOffset offset the string starts at
225 OUString
getString(sal_uInt32 nOffset
) const;
228 Returns binary object for remainder of this WW8StructBase
230 @param nOffset offset where remainder starts
232 WW8StructBase
* getRemainder(sal_uInt32 nOffset
) const;
235 Returns two byte character string starting at an offset with a
238 @param nOffset offset the string starts at
239 @param nLength number of characters in the string
241 OUString
getString(sal_uInt32 nOffset
, sal_uInt32
) const;
246 @param o stream to dump to
248 virtual void dump(OutputWithDepth
<string
> & o
) const { mSequence
.dump(o
); }
251 class WW8StructBaseTmpOffset
254 WW8StructBase
* mpStructBase
;
257 WW8StructBaseTmpOffset(WW8StructBase
* pStructBase
);
259 sal_uInt32
set(sal_uInt32 nOffset
);
260 sal_uInt32
get() const;
261 sal_uInt32
inc(sal_uInt32 nOffset
);
263 operator sal_uInt32 () const;
267 Return unsigned byte from a sequence.
269 @param rSeq sequence to get value from
270 @param nOffset offset in sequence to get value from
272 sal_uInt8
getU8(const WW8StructBase::Sequence
& rSeq
, sal_uInt32 nOffset
);
275 Return unsigned 16-bit value from a sequence.
277 @param rSeq sequence to get value from
278 @param nOffset offset in sequence to get value from
280 sal_uInt16
getU16(const WW8StructBase::Sequence
& rSeq
, sal_uInt32 nOffset
);
283 Return unsigned 32-bit value from a sequence.
285 @param rSeq sequence to get value from
286 @param nOffset offset in sequence to get value from
288 sal_uInt32
getU32(const WW8StructBase::Sequence
& rSeq
, sal_uInt32 nOffset
);
292 #endif // INCLUDED_WW8_STRUCT_BASE_HXX
294 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */