1*b8a377c6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*b8a377c6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b8a377c6SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b8a377c6SAndrew Rist * distributed with this work for additional information
6*b8a377c6SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b8a377c6SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b8a377c6SAndrew Rist * "License"); you may not use this file except in compliance
9*b8a377c6SAndrew Rist * with the License. You may obtain a copy of the License at
10*b8a377c6SAndrew Rist *
11*b8a377c6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*b8a377c6SAndrew Rist *
13*b8a377c6SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b8a377c6SAndrew Rist * software distributed under the License is distributed on an
15*b8a377c6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b8a377c6SAndrew Rist * KIND, either express or implied. See the License for the
17*b8a377c6SAndrew Rist * specific language governing permissions and limitations
18*b8a377c6SAndrew Rist * under the License.
19*b8a377c6SAndrew Rist *
20*b8a377c6SAndrew Rist *************************************************************/
21*b8a377c6SAndrew Rist
22*b8a377c6SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #ifndef INCLUDED_PLCF_HXX
25cdf0e10cSrcweir #define INCLUDED_PLCF_HXX
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
28cdf0e10cSrcweir #include <WW8StructBase.hxx>
29cdf0e10cSrcweir
30cdf0e10cSrcweir namespace writerfilter {
31cdf0e10cSrcweir namespace doctok
32cdf0e10cSrcweir {
33cdf0e10cSrcweir
34cdf0e10cSrcweir class Empty
35cdf0e10cSrcweir {
36cdf0e10cSrcweir public:
37cdf0e10cSrcweir typedef boost::shared_ptr<Empty> Pointer_t;
38cdf0e10cSrcweir
Empty()39cdf0e10cSrcweir Empty() {}
~Empty()40cdf0e10cSrcweir virtual ~Empty() {}
41cdf0e10cSrcweir
getSize()42cdf0e10cSrcweir sal_uInt32 getSize() { return 0; }
43cdf0e10cSrcweir };
44cdf0e10cSrcweir
45cdf0e10cSrcweir template <class T>
46cdf0e10cSrcweir /**
47cdf0e10cSrcweir Plex in File
48cdf0e10cSrcweir
49cdf0e10cSrcweir A PLCF is a concatenation of two arrays. The first array contains
50cdf0e10cSrcweir file character positions. The second array contains elements of
51cdf0e10cSrcweir type T. If the first array contains N elements, the second contains
52cdf0e10cSrcweir N - 1 elements. The N-th element in the first array corresponds to
53cdf0e10cSrcweir the N-th element of the second array.
54cdf0e10cSrcweir
55cdf0e10cSrcweir The second array is referred to as the payload.
56cdf0e10cSrcweir */
57cdf0e10cSrcweir class PLCF : public WW8StructBase
58cdf0e10cSrcweir {
59cdf0e10cSrcweir /// number of entries
60cdf0e10cSrcweir sal_uInt32 nEntryCount;
61cdf0e10cSrcweir
62cdf0e10cSrcweir /// offset to payload
63cdf0e10cSrcweir sal_uInt32 nPayloadOffset;
64cdf0e10cSrcweir
65cdf0e10cSrcweir /// internal method to calculate the number of entries
66cdf0e10cSrcweir sal_uInt32 getEntryCount_() const;
67cdf0e10cSrcweir
68cdf0e10cSrcweir public:
69cdf0e10cSrcweir typedef boost::shared_ptr< PLCF< T > > Pointer_t;
70cdf0e10cSrcweir
PLCF(sal_uInt32 nLength)71cdf0e10cSrcweir PLCF(sal_uInt32 nLength)
72cdf0e10cSrcweir : WW8StructBase(nLength), nEntryCount(getEntryCount_()),
73cdf0e10cSrcweir nPayloadOffset((nEntryCount + 1) * 4)
74cdf0e10cSrcweir {
75cdf0e10cSrcweir }
76cdf0e10cSrcweir
PLCF(WW8Stream & rStream,sal_Int32 nOffset,sal_Int32 nCount)77cdf0e10cSrcweir PLCF(WW8Stream & rStream,
78cdf0e10cSrcweir sal_Int32 nOffset, sal_Int32 nCount)
79cdf0e10cSrcweir : WW8StructBase(rStream, nOffset, nCount),
80cdf0e10cSrcweir nEntryCount(getEntryCount_()),
81cdf0e10cSrcweir nPayloadOffset((nEntryCount + 1) * 4)
82cdf0e10cSrcweir {
83cdf0e10cSrcweir }
84cdf0e10cSrcweir
PLCF(const Sequence & rSequence)85cdf0e10cSrcweir PLCF(const Sequence & rSequence)
86cdf0e10cSrcweir : WW8StructBase(rSequence), nEntryCount(getEntryCount_()),
87cdf0e10cSrcweir nPayloadOffset((nEntryCount + 1) * 4)
88cdf0e10cSrcweir {
89cdf0e10cSrcweir }
90cdf0e10cSrcweir
91cdf0e10cSrcweir /**
92cdf0e10cSrcweir Return the number of elements in the PLCF-
93cdf0e10cSrcweir */
getEntryCount() const94cdf0e10cSrcweir sal_uInt32 getEntryCount() const { return nEntryCount; }
95cdf0e10cSrcweir
96cdf0e10cSrcweir /**
97cdf0e10cSrcweir Return the file character position of a certain element.
98cdf0e10cSrcweir
99cdf0e10cSrcweir @param nIndex the index of the element
100cdf0e10cSrcweir */
101cdf0e10cSrcweir sal_uInt32 getFc(sal_uInt32 nIndex) const;
102cdf0e10cSrcweir
103cdf0e10cSrcweir /**
104cdf0e10cSrcweir Return a C++ pointer to a certain payload entry.
105cdf0e10cSrcweir
106cdf0e10cSrcweir @param nIndex the index of the element
107cdf0e10cSrcweir */
108cdf0e10cSrcweir T * getEntryPointer(sal_uInt32 nIndex) const;
109cdf0e10cSrcweir
110cdf0e10cSrcweir /**
111cdf0e10cSrcweir Return a shared pointer to a certain payload element.
112cdf0e10cSrcweir
113cdf0e10cSrcweir @param nIndex the index of the element
114cdf0e10cSrcweir */
115cdf0e10cSrcweir typename T::Pointer_t getEntry(sal_uInt32 nIndex) const;
116cdf0e10cSrcweir
117cdf0e10cSrcweir /**
118cdf0e10cSrcweir Return a C++ pointer a certain payload element.
119cdf0e10cSrcweir
120cdf0e10cSrcweir @param nFc the file character position of the element
121cdf0e10cSrcweir */
122cdf0e10cSrcweir T * getEntryByFc(sal_uInt32 nFc) const;
123cdf0e10cSrcweir
124cdf0e10cSrcweir virtual void dump(OutputWithDepth<string> & out) const;
125cdf0e10cSrcweir };
126cdf0e10cSrcweir
127cdf0e10cSrcweir template <class T>
getEntryCount_() const128cdf0e10cSrcweir sal_uInt32 PLCF<T>::getEntryCount_() const
129cdf0e10cSrcweir {
130cdf0e10cSrcweir return (getCount() - 4) / (T::getSize() + 4);
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
133cdf0e10cSrcweir template <class T>
getFc(sal_uInt32 nIndex) const134cdf0e10cSrcweir sal_uInt32 PLCF<T>::getFc(sal_uInt32 nIndex) const
135cdf0e10cSrcweir {
136cdf0e10cSrcweir return getU32(nIndex * 4);
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
139cdf0e10cSrcweir template <class T>
getEntryPointer(sal_uInt32 nIndex) const140cdf0e10cSrcweir T * PLCF<T>::getEntryPointer(sal_uInt32 nIndex) const
141cdf0e10cSrcweir {
142cdf0e10cSrcweir return new T(mSequence, nPayloadOffset + nIndex * T::getSize(),
143cdf0e10cSrcweir T::getSize());
144cdf0e10cSrcweir }
145cdf0e10cSrcweir
146cdf0e10cSrcweir template <class T>
getEntry(sal_uInt32 nIndex) const147cdf0e10cSrcweir typename T::Pointer_t PLCF<T>::getEntry(sal_uInt32 nIndex) const
148cdf0e10cSrcweir {
149cdf0e10cSrcweir typename T::Pointer_t pResult(getEntryPointer(nIndex));
150cdf0e10cSrcweir
151cdf0e10cSrcweir return pResult;
152cdf0e10cSrcweir }
153cdf0e10cSrcweir
154cdf0e10cSrcweir
155cdf0e10cSrcweir template <class T>
getEntryByFc(sal_uInt32 nFc) const156cdf0e10cSrcweir T * PLCF<T>::getEntryByFc(sal_uInt32 nFc) const
157cdf0e10cSrcweir {
158cdf0e10cSrcweir T * pResult = NULL;
159cdf0e10cSrcweir
160cdf0e10cSrcweir sal_uInt32 n = getEntryCount();
161cdf0e10cSrcweir
162cdf0e10cSrcweir while (getFc(n) > nFc)
163cdf0e10cSrcweir n--;
164cdf0e10cSrcweir
165cdf0e10cSrcweir pResult = getEntryPointer(n);
166cdf0e10cSrcweir
167cdf0e10cSrcweir return pResult;
168cdf0e10cSrcweir }
169cdf0e10cSrcweir
170cdf0e10cSrcweir template <class T>
dump(OutputWithDepth<string> & output_) const171cdf0e10cSrcweir void PLCF<T>::dump(OutputWithDepth<string> & output_) const
172cdf0e10cSrcweir {
173cdf0e10cSrcweir output_.addItem("<plcf>");
174cdf0e10cSrcweir WW8StructBase::dump(output_);
175cdf0e10cSrcweir
176cdf0e10cSrcweir sal_uInt32 nCount = getEntryCount();
177cdf0e10cSrcweir for (sal_uInt32 n = 0; n < nCount; ++n)
178cdf0e10cSrcweir {
179cdf0e10cSrcweir Fc aFc = getFc(n);
180cdf0e10cSrcweir typename T::Pointer_t pT = getEntry(n);
181cdf0e10cSrcweir
182cdf0e10cSrcweir output_.addItem("<plcfentry cpandfc=\"" + aFc.toString() + "\">");
183cdf0e10cSrcweir pT->dump(output_);
184cdf0e10cSrcweir output_.addItem("</plcfentry>");
185cdf0e10cSrcweir }
186cdf0e10cSrcweir output_.addItem("</plcf>>");
187cdf0e10cSrcweir }
188cdf0e10cSrcweir
189cdf0e10cSrcweir }}
190cdf0e10cSrcweir
191cdf0e10cSrcweir #endif // INCLUDED_PLCF_HXX
192