Bump version to 4.1-6
[LibreOffice.git] / writerfilter / source / doctok / XNoteHelperImpl.hxx
blob8b7043aa37da8cbd41446f3bf00728ad5f2eb821
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_X_NOTE_HELPER_IMPL_HXX
21 #define INCLUDED_X_NOTE_HELPER_IMPL_HXX
23 namespace writerfilter {
24 namespace doctok
26 template <class T>
27 sal_uInt32 XNoteHelper<T>::getCount() const
29 sal_uInt32 nResult = 0;
31 if (mpCps.get() != NULL && mpCps->getCount() > 8)
32 nResult = ( mpCps->getCount() / 4) - 2;
34 return nResult;
37 template <class T>
38 CpAndFc XNoteHelper<T>::getCpAndFc(sal_uInt32 nPos)
40 // There are getCount() + 1 entries in mpOffsets => greater
41 if (nPos > getCount())
42 throw ExceptionNotFound("getCpAndFc");
44 Cp aCp(mCpAndFcOffset.getCp() + mpCps->getU32(nPos * 4));
45 Fc aFc(mpPieceTable->cp2fc(aCp));
46 CpAndFc aCpAndFc(aCp, aFc, meType);
48 return aCpAndFc;
51 template <class T>
52 CpAndFc XNoteHelper<T>::getRefCpAndFc(sal_uInt32 nPos)
54 // There are getCount() entries in mpRefs => greater or equal
55 if (nPos >= getCount())
56 throw ExceptionNotFound("");
58 Cp aCp(mpRefs->getFc(nPos));
59 Fc aFc(mpPieceTable->cp2fc(aCp));
60 CpAndFc aCpAndFc(aCp, aFc, meType);
62 return aCpAndFc;
65 template <class T>
66 writerfilter::Reference<Stream>::Pointer_t
67 XNoteHelper<T>::get(sal_uInt32 nPos)
69 // There are getCount() entries => greater or equal
70 if (nPos >= getCount())
71 throw ExceptionNotFound("get");
73 writerfilter::Reference<Stream>::Pointer_t pResult;
75 CpAndFc aCpAndFcStart(getCpAndFc(nPos));
76 CpAndFc aCpAndFcEnd(getCpAndFc(nPos + 1));
78 if (aCpAndFcStart < aCpAndFcEnd)
79 pResult = writerfilter::Reference<Stream>::Pointer_t
80 (new WW8DocumentImpl(*mpDocument, aCpAndFcStart, aCpAndFcEnd));
82 return pResult;
85 template <class T>
86 sal_uInt32 XNoteHelper<T>::getIndexOfCpAndFc(const CpAndFc & rCpAndFc)
88 sal_uInt32 nResult = getCount();
90 sal_uInt32 n = nResult;
91 while (n > 0)
93 --n;
95 Cp aCp(mpRefs->getFc(n));
96 Fc aFc(mpPieceTable->cp2fc(aCp));
97 CpAndFc aCpAndFc(aCp, aFc, meType);
99 if (aCpAndFc <= rCpAndFc)
101 nResult = n;
102 break;
106 return nResult;
109 template <class T>
110 writerfilter::Reference<Stream>::Pointer_t
111 XNoteHelper<T>::get(const CpAndFc & rCpAndFc)
113 writerfilter::Reference<Stream>::Pointer_t pResult;
115 sal_uInt32 n = getIndexOfCpAndFc(rCpAndFc);
117 if (n < getCount())
118 pResult = get(n);
120 return pResult;
123 template <class T>
125 XNoteHelper<T>::getRef(sal_uInt32 nIndex)
127 return mpRefs->getEntryPointer(nIndex);
130 template <class T>
132 XNoteHelper<T>::getRef(const CpAndFc & rCpAndFc)
134 T * pResult = NULL;
136 sal_uInt32 n = getIndexOfCpAndFc(rCpAndFc);
138 if (n < getCount())
140 pResult = getRef(n);
143 return pResult;
146 template <class T>
147 void XNoteHelper<T>::init()
149 for (sal_uInt32 n = 0; n < getCount(); ++n)
151 CpAndFc aCpAndFc(getCpAndFc(n));
152 mpDocument->insertCpAndFc(aCpAndFc);
154 CpAndFc aCpAndFcRef(getRefCpAndFc(n));
155 mpDocument->insertCpAndFc(aCpAndFcRef);
160 #endif // INCLUDED_X_NOTE_HELPER_IMPL_HXX
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */