update dev300-m58
[ooovba.git] / writerfilter / source / doctok / WW8StructBase.cxx
blobf66648071d801adddfe6fdd9c7e396eed6867a2c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WW8StructBase.cxx,v $
10 * $Revision: 1.5 $
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>
32 #include <util.hxx>
34 namespace writerfilter {
35 namespace doctok {
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;
54 return *this;
57 void WW8StructBase::setDocument(WW8DocumentImpl * pDocument)
59 mpDocument = pDocument;
62 WW8DocumentImpl * WW8StructBase::getDocument() const
64 return mpDocument;
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,
94 sal_uInt32 nOffset)
96 return rSeq[nOffset];
99 sal_uInt16 getU16(const WW8StructBase::Sequence & rSeq,
100 sal_uInt32 nOffset)
102 return getU8(rSeq, nOffset) | (getU8(rSeq, nOffset + 1) << 8);
105 sal_uInt32 getU32(const WW8StructBase::Sequence & rSeq,
106 sal_uInt32 nOffset)
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);
113 return nResult;
116 rtl::OUString WW8StructBase::getString(sal_uInt32 nOffset, sal_uInt32 nCount)
117 const
119 rtl::OUString aResult;
121 Sequence aSeq(mSequence, nOffset, nCount * 2);
123 if (nCount > 0)
125 rtl_uString * pNew = 0;
126 rtl_uString_newFromStr_WithLength
127 (&pNew, reinterpret_cast<const sal_Unicode *>(&aSeq[0]),
128 nCount);
130 aResult = rtl::OUString(pNew);
133 return aResult;
136 WW8StructBase *
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);
147 return pResult;
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");
169 mnOffset = nOffset;
171 return mnOffset;
174 sal_uInt32 WW8StructBaseTmpOffset::get() const
176 return mnOffset;
179 sal_uInt32 WW8StructBaseTmpOffset::inc(sal_uInt32 nOffset)
181 if (mpStructBase->getCount() - mnOffset < nOffset)
182 throw ExceptionOutOfBounds("WW8StructBaseTmpOffset::inc");
184 mnOffset += nOffset;
186 return mnOffset;
189 WW8StructBaseTmpOffset::operator sal_uInt32() const
191 return mnOffset;