Bump version to 4.1-6
[LibreOffice.git] / writerfilter / source / doctok / PLCF.hxx
blobb84ce56faeb9e1f1549133121e0c67574ab3d197
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_PLCF_HXX
21 #define INCLUDED_PLCF_HXX
23 #include <boost/shared_ptr.hpp>
24 #include "WW8StructBase.hxx"
26 namespace writerfilter {
27 namespace doctok
30 class Empty
32 public:
33 typedef boost::shared_ptr<Empty> Pointer_t;
35 Empty() {}
36 virtual ~Empty() {}
38 sal_uInt32 getSize() { return 0; }
41 template <class T>
42 /**
43 Plex in File
45 A PLCF is a concatenation of two arrays. The first array contains
46 file character positions. The second array contains elements of
47 type T. If the first array contains N elements, the second contains
48 N - 1 elements. The N-th element in the first array corresponds to
49 the N-th element of the second array.
51 The second array is referred to as the payload.
53 class PLCF : public WW8StructBase
55 /// number of entries
56 sal_uInt32 nEntryCount;
58 /// offset to payload
59 sal_uInt32 nPayloadOffset;
61 /// internal method to calculate the number of entries
62 sal_uInt32 getEntryCount_() const;
64 public:
65 typedef boost::shared_ptr< PLCF< T > > Pointer_t;
67 PLCF(sal_uInt32 nLength)
68 : WW8StructBase(nLength), nEntryCount(getEntryCount_()),
69 nPayloadOffset((nEntryCount + 1) * 4)
73 PLCF(WW8Stream & rStream,
74 sal_Int32 nOffset, sal_Int32 nCount)
75 : WW8StructBase(rStream, nOffset, nCount),
76 nEntryCount(getEntryCount_()),
77 nPayloadOffset((nEntryCount + 1) * 4)
81 PLCF(const Sequence & rSequence)
82 : WW8StructBase(rSequence), nEntryCount(getEntryCount_()),
83 nPayloadOffset((nEntryCount + 1) * 4)
87 /**
88 Return the number of elements in the PLCF-
90 sal_uInt32 getEntryCount() const { return nEntryCount; }
92 /**
93 Return the file character position of a certain element.
95 @param nIndex the index of the element
97 sal_uInt32 getFc(sal_uInt32 nIndex) const;
99 /**
100 Return a C++ pointer to a certain payload entry.
102 @param nIndex the index of the element
104 T * getEntryPointer(sal_uInt32 nIndex) const;
107 Return a shared pointer to a certain payload element.
109 @param nIndex the index of the element
111 typename T::Pointer_t getEntry(sal_uInt32 nIndex) const;
114 Return a C++ pointer a certain payload element.
116 @param nFc the file character position of the element
118 T * getEntryByFc(sal_uInt32 nFc) const;
120 virtual void dump(OutputWithDepth<string> & out) const;
123 template <class T>
124 sal_uInt32 PLCF<T>::getEntryCount_() const
126 return (getCount() - 4) / (T::getSize() + 4);
129 template <class T>
130 sal_uInt32 PLCF<T>::getFc(sal_uInt32 nIndex) const
132 return getU32(nIndex * 4);
135 template <class T>
136 T * PLCF<T>::getEntryPointer(sal_uInt32 nIndex) const
138 return new T(mSequence, nPayloadOffset + nIndex * T::getSize(),
139 T::getSize());
142 template <class T>
143 typename T::Pointer_t PLCF<T>::getEntry(sal_uInt32 nIndex) const
145 typename T::Pointer_t pResult(getEntryPointer(nIndex));
147 return pResult;
151 template <class T>
152 T * PLCF<T>::getEntryByFc(sal_uInt32 nFc) const
154 T * pResult = NULL;
156 sal_uInt32 n = getEntryCount();
158 while (getFc(n) > nFc)
159 n--;
161 pResult = getEntryPointer(n);
163 return pResult;
166 template <class T>
167 void PLCF<T>::dump(OutputWithDepth<string> & output_) const
169 output_.addItem("<plcf>");
170 WW8StructBase::dump(output_);
172 sal_uInt32 nCount = getEntryCount();
173 for (sal_uInt32 n = 0; n < nCount; ++n)
175 Fc aFc = getFc(n);
176 typename T::Pointer_t pT = getEntry(n);
178 output_.addItem("<plcfentry cpandfc=\"" + aFc.toString() + "\">");
179 pT->dump(output_);
180 output_.addItem("</plcfentry>");
182 output_.addItem("</plcf>>");
187 #endif // INCLUDED_PLCF_HXX
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */