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 : #include "WW8StructBase.hxx"
21 :
22 : namespace writerfilter {
23 : namespace doctok {
24 : using namespace ::com::sun::star;
25 :
26 0 : WW8StructBase::WW8StructBase(const WW8StructBase & rParent,
27 : sal_uInt32 nOffset, sal_uInt32 nCount)
28 : : mSequence(rParent.mSequence, nOffset, nCount), mpParent(0),
29 0 : mpDocument(rParent.getDocument())
30 : {
31 0 : if (nOffset + nCount > rParent.getCount())
32 : {
33 0 : throw ExceptionOutOfBounds("WW8StructBase");
34 : }
35 0 : }
36 :
37 0 : WW8StructBase & WW8StructBase::Assign(const WW8StructBase & rSrc)
38 : {
39 0 : mSequence = rSrc.mSequence;
40 0 : mpDocument = rSrc.mpDocument;
41 :
42 0 : return *this;
43 : }
44 :
45 0 : void WW8StructBase::setDocument(WW8DocumentImpl * pDocument)
46 : {
47 0 : mpDocument = pDocument;
48 0 : }
49 :
50 0 : WW8DocumentImpl * WW8StructBase::getDocument() const
51 : {
52 0 : return mpDocument;
53 : }
54 :
55 0 : sal_uInt8 WW8StructBase::getU8(sal_uInt32 nOffset) const
56 : {
57 0 : return doctok::getU8(mSequence, nOffset);
58 : }
59 :
60 0 : sal_uInt16 WW8StructBase::getU16(sal_uInt32 nOffset) const
61 : {
62 0 : return doctok::getU16(mSequence, nOffset);
63 : }
64 :
65 0 : sal_uInt32 WW8StructBase::getU32(sal_uInt32 nOffset) const
66 : {
67 0 : return doctok::getU32(mSequence, nOffset);
68 : }
69 :
70 0 : sal_uInt8 getU8(const WW8StructBase::Sequence & rSeq,
71 : sal_uInt32 nOffset)
72 : {
73 0 : return rSeq[nOffset];
74 : }
75 :
76 0 : sal_uInt16 getU16(const WW8StructBase::Sequence & rSeq,
77 : sal_uInt32 nOffset)
78 : {
79 0 : return getU8(rSeq, nOffset) | (getU8(rSeq, nOffset + 1) << 8);
80 : }
81 :
82 0 : sal_uInt32 getU32(const WW8StructBase::Sequence & rSeq,
83 : sal_uInt32 nOffset)
84 : {
85 0 : sal_uInt32 nResult = getU8(rSeq, nOffset);
86 0 : nResult |= (getU8(rSeq, nOffset + 1) << 8);
87 0 : nResult |= (getU8(rSeq, nOffset + 2) << 16);
88 0 : nResult |= (getU8(rSeq, nOffset + 3) << 24);
89 :
90 0 : return nResult;
91 : }
92 :
93 0 : OUString WW8StructBase::getString(sal_uInt32 nOffset, sal_uInt32 nCount)
94 : const
95 : {
96 0 : OUString aResult;
97 :
98 0 : if (nOffset < getCount())
99 : {
100 0 : sal_uInt32 nCount1 = nCount;
101 0 : if (nOffset + nCount * 2 > getCount())
102 : {
103 0 : nCount1 = (getCount() - nOffset) / 2;
104 : }
105 :
106 0 : if (nCount1 > 0)
107 : {
108 0 : Sequence aSeq(mSequence, nOffset, nCount1 * 2);
109 :
110 0 : rtl_uString * pNew = 0;
111 : rtl_uString_newFromStr_WithLength
112 0 : (&pNew, reinterpret_cast<const sal_Unicode *>(&aSeq[0]),
113 0 : nCount1);
114 :
115 0 : aResult = OUString(pNew);
116 : }
117 : }
118 :
119 0 : return aResult;
120 : }
121 :
122 : WW8StructBase *
123 0 : WW8StructBase::getRemainder(sal_uInt32 nOffset) const
124 : {
125 0 : WW8StructBase * pResult = NULL;
126 :
127 0 : sal_uInt32 nCount = getCount();
128 0 : if (nCount > nOffset)
129 : {
130 0 : pResult = new WW8StructBase(*this, nOffset, nCount - nOffset);
131 : }
132 :
133 0 : return pResult;
134 : }
135 :
136 :
137 0 : OUString WW8StructBase::getString(sal_uInt32 nOffset) const
138 : {
139 0 : sal_uInt32 nCount = getU16(nOffset);
140 :
141 0 : return getString(nOffset + 2, nCount);
142 : }
143 :
144 0 : WW8StructBaseTmpOffset::WW8StructBaseTmpOffset
145 : (WW8StructBase * pStructBase)
146 0 : : mnOffset(0), mpStructBase(pStructBase)
147 : {
148 0 : }
149 :
150 0 : sal_uInt32 WW8StructBaseTmpOffset::set(sal_uInt32 nOffset)
151 : {
152 0 : if (nOffset >= mpStructBase->getCount())
153 0 : throw ExceptionOutOfBounds("WW8StructBaseTmpOffset::set");
154 :
155 0 : mnOffset = nOffset;
156 :
157 0 : return mnOffset;
158 : }
159 :
160 0 : sal_uInt32 WW8StructBaseTmpOffset::get() const
161 : {
162 0 : return mnOffset;
163 : }
164 :
165 0 : sal_uInt32 WW8StructBaseTmpOffset::inc(sal_uInt32 nOffset)
166 : {
167 0 : if (mpStructBase->getCount() - mnOffset < nOffset)
168 0 : throw ExceptionOutOfBounds("WW8StructBaseTmpOffset::inc");
169 :
170 0 : mnOffset += nOffset;
171 :
172 0 : return mnOffset;
173 : }
174 :
175 0 : WW8StructBaseTmpOffset::operator sal_uInt32() const
176 : {
177 0 : return mnOffset;
178 : }
179 :
180 15 : }}
181 :
182 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|