Update ooo320-m1
[ooovba.git] / writerfilter / source / doctok / PLCF.hxx
blobd56b0c304d2a5be0e05d44751a2d312122ec3310
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: PLCF.hxx,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 #ifndef INCLUDED_PLCF_HXX
32 #define INCLUDED_PLCF_HXX
34 #include <boost/shared_ptr.hpp>
35 #include <WW8StructBase.hxx>
37 namespace writerfilter {
38 namespace doctok
41 class Empty
43 public:
44 typedef boost::shared_ptr<Empty> Pointer_t;
46 Empty() {}
47 virtual ~Empty() {}
49 sal_uInt32 getSize() { return 0; }
52 template <class T>
53 /**
54 Plex in File
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
66 /// number of entries
67 sal_uInt32 nEntryCount;
69 /// offset to payload
70 sal_uInt32 nPayloadOffset;
72 /// internal method to calculate the number of entries
73 sal_uInt32 getEntryCount_() const;
75 public:
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)
98 /**
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;
134 template <class T>
135 sal_uInt32 PLCF<T>::getEntryCount_() const
137 return (getCount() - 4) / (T::getSize() + 4);
140 template <class T>
141 sal_uInt32 PLCF<T>::getFc(sal_uInt32 nIndex) const
143 return getU32(nIndex * 4);
146 template <class T>
147 T * PLCF<T>::getEntryPointer(sal_uInt32 nIndex) const
149 return new T(mSequence, nPayloadOffset + nIndex * T::getSize(),
150 T::getSize());
153 template <class T>
154 typename T::Pointer_t PLCF<T>::getEntry(sal_uInt32 nIndex) const
156 typename T::Pointer_t pResult(getEntryPointer(nIndex));
158 return pResult;
162 template <class T>
163 T * PLCF<T>::getEntryByFc(sal_uInt32 nFc) const
165 T * pResult = NULL;
167 sal_uInt32 n = getEntryCount();
169 while (getFc(n) > nFc)
170 n--;
172 pResult = getEntryPointer(n);
174 return pResult;
177 template <class T>
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)
186 Fc aFc = getFc(n);
187 typename T::Pointer_t pT = getEntry(n);
189 output_.addItem("<plcfentry cpandfc=\"" + aFc.toString() + "\">");
190 pT->dump(output_);
191 output_.addItem("</plcfentry>");
193 output_.addItem("</plcf>>");
198 #endif // INCLUDED_PLCF_HXX