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.cxx,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 #include <WW8StructBase.hxx>
34 namespace writerfilter
{
36 using namespace ::com::sun::star
;
38 WW8StructBase::WW8StructBase(const WW8StructBase
& rParent
,
39 sal_uInt32 nOffset
, sal_uInt32 nCount
)
40 : mSequence(rParent
.mSequence
, nOffset
, nCount
), mpParent(0),
41 mpDocument(rParent
.getDocument())
43 if (nOffset
+ nCount
> rParent
.getCount())
45 throw ExceptionOutOfBounds("WW8StructBase");
49 WW8StructBase
& WW8StructBase::Assign(const WW8StructBase
& rSrc
)
51 mSequence
= rSrc
.mSequence
;
52 mpDocument
= rSrc
.mpDocument
;
57 void WW8StructBase::setDocument(WW8DocumentImpl
* pDocument
)
59 mpDocument
= pDocument
;
62 WW8DocumentImpl
* WW8StructBase::getDocument() const
67 sal_uInt8
WW8StructBase::getU8(sal_uInt32 nOffset
) const
69 return doctok::getU8(mSequence
, nOffset
);
72 sal_uInt16
WW8StructBase::getU16(sal_uInt32 nOffset
) const
74 return doctok::getU16(mSequence
, nOffset
);
77 sal_uInt32
WW8StructBase::getU32(sal_uInt32 nOffset
) const
79 return doctok::getU32(mSequence
, nOffset
);
82 sal_Bool
WW8StructBase::getBit(sal_uInt32 nValue
, sal_uInt16 nBit
) const
84 return (nValue
& (1 << nBit
)) != 0;
87 sal_uInt8
WW8StructBase::getNibble(sal_uInt32 nValue
,
88 sal_uInt16 nShift
) const
90 return sal::static_int_cast
<sal_uInt8
>((nValue
>> nShift
) & 0xf);
93 sal_uInt8
getU8(const WW8StructBase::Sequence
& rSeq
,
99 sal_uInt16
getU16(const WW8StructBase::Sequence
& rSeq
,
102 return getU8(rSeq
, nOffset
) | (getU8(rSeq
, nOffset
+ 1) << 8);
105 sal_uInt32
getU32(const WW8StructBase::Sequence
& rSeq
,
108 sal_uInt32 nResult
= getU8(rSeq
, nOffset
);
109 nResult
|= (getU8(rSeq
, nOffset
+ 1) << 8);
110 nResult
|= (getU8(rSeq
, nOffset
+ 2) << 16);
111 nResult
|= (getU8(rSeq
, nOffset
+ 3) << 24);
116 rtl::OUString
WW8StructBase::getString(sal_uInt32 nOffset
, sal_uInt32 nCount
)
119 rtl::OUString aResult
;
121 Sequence
aSeq(mSequence
, nOffset
, nCount
* 2);
125 rtl_uString
* pNew
= 0;
126 rtl_uString_newFromStr_WithLength
127 (&pNew
, reinterpret_cast<const sal_Unicode
*>(&aSeq
[0]),
130 aResult
= rtl::OUString(pNew
);
137 WW8StructBase::getRemainder(sal_uInt32 nOffset
) const
139 WW8StructBase
* pResult
= NULL
;
141 sal_uInt32 nCount
= getCount();
142 if (nCount
> nOffset
)
144 pResult
= new WW8StructBase(*this, nOffset
, nCount
- nOffset
);
151 rtl::OUString
WW8StructBase::getString(sal_uInt32 nOffset
) const
153 sal_uInt32 nCount
= getU16(nOffset
);
155 return getString(nOffset
+ 2, nCount
);
158 WW8StructBaseTmpOffset::WW8StructBaseTmpOffset
159 (WW8StructBase
* pStructBase
)
160 : mnOffset(0), mpStructBase(pStructBase
)
164 sal_uInt32
WW8StructBaseTmpOffset::set(sal_uInt32 nOffset
)
166 if (nOffset
>= mpStructBase
->getCount())
167 throw ExceptionOutOfBounds("WW8StructBaseTmpOffset::set");
174 sal_uInt32
WW8StructBaseTmpOffset::get() const
179 sal_uInt32
WW8StructBaseTmpOffset::inc(sal_uInt32 nOffset
)
181 if (mpStructBase
->getCount() - mnOffset
< nOffset
)
182 throw ExceptionOutOfBounds("WW8StructBaseTmpOffset::inc");
189 WW8StructBaseTmpOffset::operator sal_uInt32() const