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: PLCF.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_PLCF_HXX
32 #define INCLUDED_PLCF_HXX
34 #include <boost/shared_ptr.hpp>
35 #include <WW8StructBase.hxx>
37 namespace writerfilter
{
44 typedef boost::shared_ptr
<Empty
> Pointer_t
;
49 sal_uInt32
getSize() { return 0; }
56 A PLCF is a concatenation of two arrays. The first array contains
57 file character positions. The second array contains elements of
58 type T. If the first array contains N elements, the second contains
59 N - 1 elements. The N-th element in the first array corresponds to
60 the N-th element of the second array.
62 The second array is referred to as the payload.
64 class PLCF
: public WW8StructBase
67 sal_uInt32 nEntryCount
;
70 sal_uInt32 nPayloadOffset
;
72 /// internal method to calculate the number of entries
73 sal_uInt32
getEntryCount_() const;
76 typedef boost::shared_ptr
< PLCF
< T
> > Pointer_t
;
78 PLCF(sal_uInt32 nLength
)
79 : WW8StructBase(nLength
), nEntryCount(getEntryCount_()),
80 nPayloadOffset((nEntryCount
+ 1) * 4)
84 PLCF(WW8Stream
& rStream
,
85 sal_Int32 nOffset
, sal_Int32 nCount
)
86 : WW8StructBase(rStream
, nOffset
, nCount
),
87 nEntryCount(getEntryCount_()),
88 nPayloadOffset((nEntryCount
+ 1) * 4)
92 PLCF(const Sequence
& rSequence
)
93 : WW8StructBase(rSequence
), nEntryCount(getEntryCount_()),
94 nPayloadOffset((nEntryCount
+ 1) * 4)
99 Return the number of elements in the PLCF-
101 sal_uInt32
getEntryCount() const { return nEntryCount
; }
104 Return the file character position of a certain element.
106 @param nIndex the index of the element
108 sal_uInt32
getFc(sal_uInt32 nIndex
) const;
111 Return a C++ pointer to a certain payload entry.
113 @param nIndex the index of the element
115 T
* getEntryPointer(sal_uInt32 nIndex
) const;
118 Return a shared pointer to a certain payload element.
120 @param nIndex the index of the element
122 typename
T::Pointer_t
getEntry(sal_uInt32 nIndex
) const;
125 Return a C++ pointer a certain payload element.
127 @param nFc the file character position of the element
129 T
* getEntryByFc(sal_uInt32 nFc
) const;
131 virtual void dump(OutputWithDepth
<string
> & out
) const;
135 sal_uInt32 PLCF
<T
>::getEntryCount_() const
137 return (getCount() - 4) / (T::getSize() + 4);
141 sal_uInt32 PLCF
<T
>::getFc(sal_uInt32 nIndex
) const
143 return getU32(nIndex
* 4);
147 T
* PLCF
<T
>::getEntryPointer(sal_uInt32 nIndex
) const
149 return new T(mSequence
, nPayloadOffset
+ nIndex
* T::getSize(),
154 typename
T::Pointer_t PLCF
<T
>::getEntry(sal_uInt32 nIndex
) const
156 typename
T::Pointer_t
pResult(getEntryPointer(nIndex
));
163 T
* PLCF
<T
>::getEntryByFc(sal_uInt32 nFc
) const
167 sal_uInt32 n
= getEntryCount();
169 while (getFc(n
) > nFc
)
172 pResult
= getEntryPointer(n
);
178 void PLCF
<T
>::dump(OutputWithDepth
<string
> & output_
) const
180 output_
.addItem("<plcf>");
181 WW8StructBase::dump(output_
);
183 sal_uInt32 nCount
= getEntryCount();
184 for (sal_uInt32 n
= 0; n
< nCount
; ++n
)
187 typename
T::Pointer_t pT
= getEntry(n
);
189 output_
.addItem("<plcfentry cpandfc=\"" + aFc
.toString() + "\">");
191 output_
.addItem("</plcfentry>");
193 output_
.addItem("</plcf>>");
198 #endif // INCLUDED_PLCF_HXX