LibreOffice Module sw (master) 1
docary.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#ifndef INCLUDED_SW_INC_DOCARY_HXX
20#define INCLUDED_SW_INC_DOCARY_HXX
21
22#include <vector>
23#include <type_traits>
25
26#include "fmtcol.hxx"
27#include "frmfmt.hxx"
28#include "section.hxx"
29#include "tox.hxx"
30#include "numrule.hxx"
31#include "fldbas.hxx"
32
33class SwRangeRedline;
34class SwExtraRedline;
35class SwOLENode;
36class SwTable;
37class SwTableLine;
38class SwTableBox;
39struct SwPosition;
40enum class RedlineType : sal_uInt16;
41
44{
45public:
46 virtual size_t GetFormatCount() const = 0;
47 virtual SwFormat* GetFormat(size_t idx) const = 0;
48 virtual ~SwFormatsBase();
49
50 // default linear search implementation, some subclasses will override with a more efficient search
51 virtual SwFormat* FindFormatByName(const OUString& rName) const;
52 virtual void Rename(const SwFrameFormat&, const OUString&) {};
53
54 SwFormatsBase() = default;
55 SwFormatsBase(SwFormatsBase const &) = default;
57 SwFormatsBase & operator =(SwFormatsBase const &) = default;
58 SwFormatsBase & operator =(SwFormatsBase &&) = default;
59};
60
61template<typename Value>
63{
64public:
65 typedef typename std::vector<Value>::iterator iterator;
66 typedef typename std::vector<Value>::const_iterator const_iterator;
67 typedef typename std::vector<Value>::size_type size_type;
68 typedef typename std::vector<Value>::value_type value_type;
69
70protected:
71 enum class DestructorPolicy {
72 KeepElements,
73 FreeElements,
74 };
75
76private:
77 typename std::vector<Value> mvVals;
79
80protected:
81 // default destructor deletes all contained elements
83 : mPolicy(policy) {}
84
85public:
86 bool empty() const { return mvVals.empty(); }
87 Value const& front() const { return mvVals.front(); }
88 size_t size() const { return mvVals.size(); }
89 iterator begin() { return mvVals.begin(); }
90 const_iterator begin() const { return mvVals.begin(); }
91 iterator end() { return mvVals.end(); }
92 const_iterator end() const { return mvVals.end(); }
93 void clear() { mvVals.clear(); }
94 iterator erase(iterator aIt) { return mvVals.erase(aIt); }
95 iterator erase(iterator aFirst, iterator aLast) { return mvVals.erase(aFirst, aLast); }
96 iterator insert(iterator aIt, Value const& rVal) { return mvVals.insert(aIt, rVal); }
97 template<typename TInputIterator>
98 void insert(iterator aIt, TInputIterator aFirst, TInputIterator aLast)
99 {
100 mvVals.insert(aIt, aFirst, aLast);
101 }
102 void push_back(Value const& rVal) { mvVals.push_back(rVal); }
103 void reserve(size_type nSize) { mvVals.reserve(nSize); }
104 Value const& at(size_type nPos) const { return mvVals.at(nPos); }
105 Value const& operator[](size_type nPos) const { return mvVals[nPos]; }
107
108 // free any remaining child objects based on mPolicy
110 {
112 for(const_iterator it = begin(); it != end(); ++it)
113 delete *it;
114 }
115
116 //TODO: These functions are apparently brittle (but the copy functions are actually used by the
117 // code; the move functions will be implicitly-defined as deleted anyway) and should probably
118 // only be used with DestructorPolicy::KeepELements:
123
124 void DeleteAndDestroy(int aStartIdx, int aEndIdx)
125 {
126 if (aEndIdx < aStartIdx)
127 return;
128 for (const_iterator it = begin() + aStartIdx;
129 it != begin() + aEndIdx; ++it)
130 delete *it;
131 erase( begin() + aStartIdx, begin() + aEndIdx);
132 }
133
134 size_t GetPos(Value const& p) const
135 {
136 const_iterator const it = std::find(begin(), end(), p);
137 return it == end() ? SIZE_MAX : it - begin();
138 }
139
141 bool IsAlive(typename std::remove_pointer<Value>::type const*const p) const
142 { return std::find(begin(), end(), p) != end(); }
143
144 static void dumpAsXml(xmlTextWriterPtr /*pWriter*/) {};
145};
146
147template<typename Value>
149{
150protected:
153 : SwVectorModifyBase<Value>(policy) {}
154
155public:
156 virtual size_t GetFormatCount() const override
158
159 virtual Value GetFormat(size_t idx) const override
161
162 size_t GetPos(const SwFormat *p) const
163 { return SwVectorModifyBase<Value>::GetPos( static_cast<Value>( const_cast<SwFormat*>( p ) ) ); }
164
165 // Override return type to reduce casting
166 virtual Value FindFormatByName(const OUString& rName) const override
167 { return static_cast<Value>(SwFormatsBase::FindFormatByName(rName)); }
168};
169
170class SwGrfFormatColls final : public SwFormatsModifyBase<SwGrfFormatColl*>
171{
172public:
174};
175
176
178class SwFrameFormatsV final : public SwFormatsModifyBase<SwFrameFormat*>
179{
180public:
182};
183
184class SwTextFormatColls final : public SwFormatsModifyBase<SwTextFormatColl*>
185{
186public:
188 void dumpAsXml(xmlTextWriterPtr pWriter) const;
189};
190
192class SwSectionFormats final : public SwFormatsModifyBase<SwSectionFormat*>
193{
194public:
195 void dumpAsXml(xmlTextWriterPtr pWriter) const;
196};
197
198class SwFieldTypes : public std::vector<std::unique_ptr<SwFieldType>> {
199public:
200 void dumpAsXml(xmlTextWriterPtr pWriter) const;
201};
202
203class SwTOXTypes : public std::vector<std::unique_ptr<SwTOXType>> {};
204
205class SwNumRuleTable final : public SwVectorModifyBase<SwNumRule*> {
206public:
207 void dumpAsXml(xmlTextWriterPtr pWriter) const;
208};
209
211{
212 bool operator()(SwRangeRedline* const &lhs, SwRangeRedline* const &rhs) const;
213};
214
215// Notification type for notifying about redlines to LOK clients
217
219{
220public:
224 static constexpr size_type npos = SAL_MAX_INT32;
225private:
230public:
232 bool Contains(const SwRangeRedline* p) const { return maVector.find(const_cast<SwRangeRedline*>(p)) != maVector.end(); }
233 size_type GetPos(const SwRangeRedline* p) const;
234
235 bool Insert(SwRangeRedline*& p);
236 bool Insert(SwRangeRedline*& p, size_type& rInsPos);
237 bool InsertWithValidRanges(SwRangeRedline*& p, size_type* pInsPos = nullptr);
239
240 void Remove( size_type nPos );
241 void Remove( const SwRangeRedline* p );
242 void DeleteAndDestroy(size_type nPos);
243 void DeleteAndDestroyAll();
244
245 void dumpAsXml(xmlTextWriterPtr pWriter) const;
246
247 size_type FindNextOfSeqNo( size_type nSttPos ) const;
248 size_type FindPrevOfSeqNo( size_type nSttPos ) const;
252 size_type FindNextSeqNo( sal_uInt16 nSeqNo, size_type nSttPos ) const;
253 size_type FindPrevSeqNo( sal_uInt16 nSeqNo, size_type nSttPos ) const;
254
262 const SwRangeRedline* FindAtPosition( const SwPosition& startPosition, size_type& tableIndex, bool next = true ) const;
263 // is there a redline with the same text content from the same author (near the redline),
264 // but with the opposite type (Insert or Delete). It's used to recognize tracked text moving.
265 bool isMoved(size_type tableIndex) const;
266
267 bool empty() const { return maVector.empty(); }
268 size_type size() const { return maVector.size(); }
269 SwRangeRedline* operator[]( size_type idx ) const { return maVector[idx]; }
272 void Resort() { maVector.Resort(); }
273
274 // Notifies all LOK clients when redlines are added/modified/removed
275 static void LOKRedlineNotification(RedlineNotification eType, SwRangeRedline* pRedline);
276
277private:
279};
280
283{
284private:
285 std::vector<SwExtraRedline*> m_aExtraRedlines;
286
287public:
289
290 void Insert( SwExtraRedline* p );
291
292 void DeleteAndDestroy( sal_uInt16 nPos);
293 void DeleteAndDestroyAll();
294
295 void dumpAsXml(xmlTextWriterPtr pWriter) const;
296
297 sal_uInt16 GetSize() const { return m_aExtraRedlines.size(); }
298 SwExtraRedline* GetRedline( sal_uInt16 uIndex ) const { return m_aExtraRedlines.operator[]( uIndex ); }
299
300 SW_DLLPUBLIC bool DeleteAllTableRedlines( SwDoc& rDoc, const SwTable& rTable, bool bSaveInUndo, RedlineType nRedlineTypeToDelete );
301 bool DeleteTableRowRedline ( SwDoc* pDoc, const SwTableLine& rTableLine, bool bSaveInUndo, RedlineType nRedlineTypeToDelete );
302 bool DeleteTableCellRedline( SwDoc* pDoc, const SwTableBox& rTableBox, bool bSaveInUndo, RedlineType nRedlineTypeToDelete );
303};
304
305typedef std::vector<SwOLENode*> SwOLENodes;
306
307#endif // INCLUDED_SW_INC_DOCARY_HXX
308
309/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: doc.hxx:197
Table that holds 'extra' redlines, such as 'table row insert/delete', 'paragraph moves' etc....
Definition: docary.hxx:283
void Insert(SwExtraRedline *p)
Definition: docredln.cxx:2104
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: docredln.cxx:96
std::vector< SwExtraRedline * > m_aExtraRedlines
Definition: docary.hxx:285
void DeleteAndDestroyAll()
Definition: docredln.cxx:2129
bool DeleteTableRowRedline(SwDoc *pDoc, const SwTableLine &rTableLine, bool bSaveInUndo, RedlineType nRedlineTypeToDelete)
Definition: docredln.cxx:191
bool DeleteTableCellRedline(SwDoc *pDoc, const SwTableBox &rTableBox, bool bSaveInUndo, RedlineType nRedlineTypeToDelete)
Definition: docredln.cxx:235
SW_DLLPUBLIC bool DeleteAllTableRedlines(SwDoc &rDoc, const SwTable &rTable, bool bSaveInUndo, RedlineType nRedlineTypeToDelete)
Definition: docredln.cxx:140
void DeleteAndDestroy(sal_uInt16 nPos)
Definition: docredln.cxx:2110
sal_uInt16 GetSize() const
Definition: docary.hxx:297
SwExtraRedline * GetRedline(sal_uInt16 uIndex) const
Definition: docary.hxx:298
Base object for 'Redlines' that are not of 'Ranged' type (like table row insert\delete)
Definition: redline.hxx:289
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:229
Base class for various Writer styles.
Definition: format.hxx:47
provides some methods for generic operations on lists that contain SwFormat* subclasses.
Definition: docary.hxx:44
SwFormatsBase()=default
virtual SwFormat * GetFormat(size_t idx) const =0
virtual void Rename(const SwFrameFormat &, const OUString &)
Definition: docary.hxx:52
virtual SwFormat * FindFormatByName(const OUString &rName) const
Definition: format.cxx:766
SwFormatsBase(SwFormatsBase &&)=default
SwFormatsBase(SwFormatsBase const &)=default
virtual size_t GetFormatCount() const =0
size_t GetPos(const SwFormat *p) const
Definition: docary.hxx:162
virtual size_t GetFormatCount() const override
Definition: docary.hxx:156
SwFormatsModifyBase(typename SwVectorModifyBase< Value >::DestructorPolicy policy=SwVectorModifyBase< Value >::DestructorPolicy::FreeElements)
Definition: docary.hxx:151
virtual Value GetFormat(size_t idx) const override
Definition: docary.hxx:159
virtual Value FindFormatByName(const OUString &rName) const override
Definition: docary.hxx:166
Style of a layout element.
Definition: frmfmt.hxx:72
Unsorted, undeleting SwFrameFormat vector.
Definition: docary.hxx:179
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: number.cxx:1562
void CheckOverlapping(vector_type::const_iterator it)
Definition: docredln.cxx:442
size_type FindNextSeqNo(sal_uInt16 nSeqNo, size_type nSttPos) const
Search next or previous Redline with the same Seq.
Definition: docredln.cxx:721
bool InsertWithValidRanges(SwRangeRedline *&p, size_type *pInsPos=nullptr)
Definition: docredln.cxx:608
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: docredln.cxx:884
size_type FindPrevOfSeqNo(size_type nSttPos) const
Definition: docredln.cxx:713
vector_type maVector
Definition: docary.hxx:226
size_type FindPrevSeqNo(sal_uInt16 nSeqNo, size_type nSttPos) const
Definition: docredln.cxx:744
size_type FindNextOfSeqNo(size_type nSttPos) const
Definition: docredln.cxx:706
bool empty() const
Definition: docary.hxx:267
vector_type::const_iterator end() const
Definition: docary.hxx:271
bool isMoved(size_type tableIndex) const
Definition: docredln.cxx:791
bool Insert(SwRangeRedline *&p)
Definition: docredln.cxx:416
static void LOKRedlineNotification(RedlineNotification eType, SwRangeRedline *pRedline)
Emits LOK notification about one addition / removal of a redline item.
Definition: docredln.cxx:344
bool m_bHasOverlappingElements
Sometimes we load bad data, and we need to know if we can use fast binary search, or if we have to fa...
Definition: docary.hxx:229
bool Contains(const SwRangeRedline *p) const
Definition: docary.hxx:232
void DeleteAndDestroy(size_type nPos)
Definition: docredln.cxx:698
o3tl::sorted_vector< SwRangeRedline *, CompareSwRedlineTable, o3tl::find_partialorder_ptrequals > vector_type
Definition: docary.hxx:222
static constexpr size_type npos
Definition: docary.hxx:224
size_type size() const
Definition: docary.hxx:268
vector_type::const_iterator begin() const
Definition: docary.hxx:270
void Remove(size_type nPos)
Definition: docredln.cxx:669
vector_type::size_type size_type
Definition: docary.hxx:223
SwRangeRedline * operator[](size_type idx) const
Definition: docary.hxx:269
bool HasOverlappingElements() const
Definition: docary.hxx:238
void Resort()
Definition: docary.hxx:272
void DeleteAndDestroyAll()
Definition: docredln.cxx:686
size_type GetPos(const SwRangeRedline *p) const
Definition: docredln.cxx:653
const SwRangeRedline * FindAtPosition(const SwPosition &startPosition, size_type &tableIndex, bool next=true) const
Find the redline at the given position.
Definition: docredln.cxx:765
Array of Undo-history.
Definition: docary.hxx:193
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: section.cxx:1000
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:443
SwTableLine is one table row in the document model.
Definition: swtable.hxx:376
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:113
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fmtcol.cxx:562
std::vector< Value >::const_iterator const_iterator
Definition: docary.hxx:66
size_t GetPos(Value const &p) const
Definition: docary.hxx:134
iterator end()
Definition: docary.hxx:91
SwVectorModifyBase(SwVectorModifyBase const &)=default
std::vector< Value >::size_type size_type
Definition: docary.hxx:67
const DestructorPolicy mPolicy
Definition: docary.hxx:78
std::vector< Value > mvVals
Definition: docary.hxx:77
std::vector< Value >::value_type value_type
Definition: docary.hxx:68
void insert(iterator aIt, TInputIterator aFirst, TInputIterator aLast)
Definition: docary.hxx:98
Value const & at(size_type nPos) const
Definition: docary.hxx:104
void DeleteAndDestroy(int aStartIdx, int aEndIdx)
Definition: docary.hxx:124
const_iterator end() const
Definition: docary.hxx:92
iterator begin()
Definition: docary.hxx:89
iterator insert(iterator aIt, Value const &rVal)
Definition: docary.hxx:96
size_t size() const
Definition: docary.hxx:88
void push_back(Value const &rVal)
Definition: docary.hxx:102
Value & operator[](size_type nPos)
Definition: docary.hxx:106
static void dumpAsXml(xmlTextWriterPtr)
Definition: docary.hxx:144
iterator erase(iterator aFirst, iterator aLast)
Definition: docary.hxx:95
iterator erase(iterator aIt)
Definition: docary.hxx:94
Value const & front() const
Definition: docary.hxx:87
SwVectorModifyBase(DestructorPolicy policy=DestructorPolicy::FreeElements)
Definition: docary.hxx:82
Value const & operator[](size_type nPos) const
Definition: docary.hxx:105
bool empty() const
Definition: docary.hxx:86
virtual ~SwVectorModifyBase()
Definition: docary.hxx:109
SwVectorModifyBase & operator=(SwVectorModifyBase const &)=default
void reserve(size_type nSize)
Definition: docary.hxx:103
SwVectorModifyBase(SwVectorModifyBase &&)=default
bool IsAlive(typename std::remove_pointer< Value >::type const *const p) const
check that given format is still alive (i.e. contained here)
Definition: docary.hxx:141
const_iterator begin() const
Definition: docary.hxx:90
std::vector< Value >::iterator iterator
Definition: docary.hxx:65
const_iterator begin() const
const_iterator find(const Value &x) const
bool empty() const
const_iterator end() const
size_type size() const
std::vector< Value >::size_type size_type
RedlineType
struct _xmlTextWriter * xmlTextWriterPtr
std::vector< SwOLENode * > SwOLENodes
Definition: docary.hxx:305
RedlineNotification
Definition: docary.hxx:216
const sal_uInt16 idx[]
void * p
sal_uInt16 nPos
Value
bool operator()(SwRangeRedline *const &lhs, SwRangeRedline *const &rhs) const
Definition: docredln.cxx:643
Marks a position in the document model.
Definition: pam.hxx:38
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
#define SAL_MAX_INT32