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
53 SwFormatsBase() = default;
54 SwFormatsBase(SwFormatsBase const &) = default;
56 SwFormatsBase & operator =(SwFormatsBase const &) = default;
57 SwFormatsBase & operator =(SwFormatsBase &&) = default;
58};
59
60template<typename Value>
62{
63public:
64 typedef typename std::vector<Value>::iterator iterator;
65 typedef typename std::vector<Value>::const_iterator const_iterator;
66 typedef typename std::vector<Value>::size_type size_type;
67 typedef typename std::vector<Value>::value_type value_type;
68
69protected:
70 enum class DestructorPolicy {
71 KeepElements,
72 FreeElements,
73 };
74
75private:
76 typename std::vector<Value> mvVals;
78
79protected:
80 // default destructor deletes all contained elements
82 : mPolicy(policy) {}
83
84public:
85 bool empty() const { return mvVals.empty(); }
86 Value const& front() const { return mvVals.front(); }
87 size_t size() const { return mvVals.size(); }
88 iterator begin() { return mvVals.begin(); }
89 const_iterator begin() const { return mvVals.begin(); }
90 iterator end() { return mvVals.end(); }
91 const_iterator end() const { return mvVals.end(); }
92 void clear() { mvVals.clear(); }
93 iterator erase(iterator aIt) { return mvVals.erase(aIt); }
94 iterator erase(iterator aFirst, iterator aLast) { return mvVals.erase(aFirst, aLast); }
95 iterator insert(iterator aIt, Value const& rVal) { return mvVals.insert(aIt, rVal); }
96 template<typename TInputIterator>
97 void insert(iterator aIt, TInputIterator aFirst, TInputIterator aLast)
98 {
99 mvVals.insert(aIt, aFirst, aLast);
100 }
101 void push_back(Value const& rVal) { mvVals.push_back(rVal); }
102 void reserve(size_type nSize) { mvVals.reserve(nSize); }
103 Value const& at(size_type nPos) const { return mvVals.at(nPos); }
104 Value const& operator[](size_type nPos) const { return mvVals[nPos]; }
106
107 // free any remaining child objects based on mPolicy
109 {
111 for(const_iterator it = begin(); it != end(); ++it)
112 delete *it;
113 }
114
115 //TODO: These functions are apparently brittle (but the copy functions are actually used by the
116 // code; the move functions will be implicitly-defined as deleted anyway) and should probably
117 // only be used with DestructorPolicy::KeepELements:
122
123 void DeleteAndDestroy(int aStartIdx, int aEndIdx)
124 {
125 if (aEndIdx < aStartIdx)
126 return;
127 for (const_iterator it = begin() + aStartIdx;
128 it != begin() + aEndIdx; ++it)
129 delete *it;
130 erase( begin() + aStartIdx, begin() + aEndIdx);
131 }
132
133 size_t GetPos(Value const& p) const
134 {
135 const_iterator const it = std::find(begin(), end(), p);
136 return it == end() ? SIZE_MAX : it - begin();
137 }
138
140 bool IsAlive(typename std::remove_pointer<Value>::type const*const p) const
141 { return std::find(begin(), end(), p) != end(); }
142
143 static void dumpAsXml(xmlTextWriterPtr /*pWriter*/) {};
144};
145
146template<typename Value>
148{
149protected:
152 : SwVectorModifyBase<Value>(policy) {}
153
154public:
155 virtual size_t GetFormatCount() const override
157
158 virtual Value GetFormat(size_t idx) const override
160
161 size_t GetPos(const SwFormat *p) const
162 { return SwVectorModifyBase<Value>::GetPos( static_cast<Value>( const_cast<SwFormat*>( p ) ) ); }
163
164 // Override return type to reduce casting
165 virtual Value FindFormatByName(const OUString& rName) const override
166 { return static_cast<Value>(SwFormatsBase::FindFormatByName(rName)); }
167};
168
169class SwGrfFormatColls final : public SwFormatsModifyBase<SwGrfFormatColl*>
170{
171public:
173};
174
175
177class SwFrameFormatsV final : public SwFormatsModifyBase<SwFrameFormat*>
178{
179public:
181};
182
183class SwTextFormatColls final : public SwFormatsModifyBase<SwTextFormatColl*>
184{
185public:
187 void dumpAsXml(xmlTextWriterPtr pWriter) const;
188};
189
191class SwSectionFormats final : public SwFormatsModifyBase<SwSectionFormat*>
192{
193public:
194 void dumpAsXml(xmlTextWriterPtr pWriter) const;
195};
196
197class SwFieldTypes : public std::vector<std::unique_ptr<SwFieldType>> {
198public:
199 void dumpAsXml(xmlTextWriterPtr pWriter) const;
200};
201
202class SwTOXTypes : public std::vector<std::unique_ptr<SwTOXType>> {};
203
204class SwNumRuleTable final : public SwVectorModifyBase<SwNumRule*> {
205public:
206 void dumpAsXml(xmlTextWriterPtr pWriter) const;
207};
208
210{
211 bool operator()(SwRangeRedline* const &lhs, SwRangeRedline* const &rhs) const;
212};
213
214// Notification type for notifying about redlines to LOK clients
216
218{
219public:
223 static constexpr size_type npos = SAL_MAX_INT32;
224private:
229public:
231 bool Contains(const SwRangeRedline* p) const { return maVector.find(const_cast<SwRangeRedline*>(p)) != maVector.end(); }
232 size_type GetPos(const SwRangeRedline* p) const;
233
234 bool Insert(SwRangeRedline*& p);
235 bool Insert(SwRangeRedline*& p, size_type& rInsPos);
236 bool InsertWithValidRanges(SwRangeRedline*& p, size_type* pInsPos = nullptr);
238
239 void Remove( size_type nPos );
240 void Remove( const SwRangeRedline* p );
241 void DeleteAndDestroy(size_type nPos);
242 void DeleteAndDestroyAll();
243
244 void dumpAsXml(xmlTextWriterPtr pWriter) const;
245
246 size_type FindNextOfSeqNo( size_type nSttPos ) const;
247 size_type FindPrevOfSeqNo( size_type nSttPos ) const;
251 size_type FindNextSeqNo( sal_uInt16 nSeqNo, size_type nSttPos ) const;
252 size_type FindPrevSeqNo( sal_uInt16 nSeqNo, size_type nSttPos ) const;
253
261 const SwRangeRedline* FindAtPosition( const SwPosition& startPosition, size_type& tableIndex, bool next = true ) const;
262 // is there a redline with the same text content from the same author (near the redline),
263 // but with the opposite type (Insert or Delete). It's used to recognize tracked text moving.
264 bool isMoved(size_type tableIndex) const;
265
266 bool empty() const { return maVector.empty(); }
267 size_type size() const { return maVector.size(); }
268 SwRangeRedline* operator[]( size_type idx ) const { return maVector[idx]; }
271 void Resort() { maVector.Resort(); }
272
273 // Notifies all LOK clients when redlines are added/modified/removed
274 static void LOKRedlineNotification(RedlineNotification eType, SwRangeRedline* pRedline);
275
276private:
278};
279
282{
283private:
284 std::vector<SwExtraRedline*> m_aExtraRedlines;
285
286public:
288
289 void Insert( SwExtraRedline* p );
290
291 void DeleteAndDestroy( sal_uInt16 nPos);
292 void DeleteAndDestroyAll();
293
294 void dumpAsXml(xmlTextWriterPtr pWriter) const;
295
296 sal_uInt16 GetSize() const { return m_aExtraRedlines.size(); }
297 SwExtraRedline* GetRedline( sal_uInt16 uIndex ) const { return m_aExtraRedlines.operator[]( uIndex ); }
298
299 SW_DLLPUBLIC bool DeleteAllTableRedlines( SwDoc& rDoc, const SwTable& rTable, bool bSaveInUndo, RedlineType nRedlineTypeToDelete );
300 bool DeleteTableRowRedline ( SwDoc* pDoc, const SwTableLine& rTableLine, bool bSaveInUndo, RedlineType nRedlineTypeToDelete );
301 bool DeleteTableCellRedline( SwDoc* pDoc, const SwTableBox& rTableBox, bool bSaveInUndo, RedlineType nRedlineTypeToDelete );
302};
303
304typedef std::vector<SwOLENode*> SwOLENodes;
305
306#endif // INCLUDED_SW_INC_DOCARY_HXX
307
308/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _xmlTextWriter * xmlTextWriterPtr
Definition: doc.hxx:192
Table that holds 'extra' redlines, such as 'table row insert/delete', 'paragraph moves' etc....
Definition: docary.hxx:282
void Insert(SwExtraRedline *p)
Definition: docredln.cxx:2063
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: docredln.cxx:93
std::vector< SwExtraRedline * > m_aExtraRedlines
Definition: docary.hxx:284
void DeleteAndDestroyAll()
Definition: docredln.cxx:2088
bool DeleteTableRowRedline(SwDoc *pDoc, const SwTableLine &rTableLine, bool bSaveInUndo, RedlineType nRedlineTypeToDelete)
Definition: docredln.cxx:188
bool DeleteTableCellRedline(SwDoc *pDoc, const SwTableBox &rTableBox, bool bSaveInUndo, RedlineType nRedlineTypeToDelete)
Definition: docredln.cxx:232
SW_DLLPUBLIC bool DeleteAllTableRedlines(SwDoc &rDoc, const SwTable &rTable, bool bSaveInUndo, RedlineType nRedlineTypeToDelete)
Definition: docredln.cxx:137
void DeleteAndDestroy(sal_uInt16 nPos)
Definition: docredln.cxx:2069
sal_uInt16 GetSize() const
Definition: docary.hxx:296
SwExtraRedline * GetRedline(sal_uInt16 uIndex) const
Definition: docary.hxx:297
Base object for 'Redlines' that are not of 'Ranged' type (like table row insert\delete)
Definition: redline.hxx:283
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:218
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 SwFormat * FindFormatByName(const OUString &rName) const
Definition: format.cxx:768
SwFormatsBase(SwFormatsBase &&)=default
SwFormatsBase(SwFormatsBase const &)=default
virtual size_t GetFormatCount() const =0
size_t GetPos(const SwFormat *p) const
Definition: docary.hxx:161
virtual size_t GetFormatCount() const override
Definition: docary.hxx:155
SwFormatsModifyBase(typename SwVectorModifyBase< Value >::DestructorPolicy policy=SwVectorModifyBase< Value >::DestructorPolicy::FreeElements)
Definition: docary.hxx:150
virtual Value GetFormat(size_t idx) const override
Definition: docary.hxx:158
virtual Value FindFormatByName(const OUString &rName) const override
Definition: docary.hxx:165
Unsorted, undeleting SwFrameFormat vector.
Definition: docary.hxx:178
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: number.cxx:1582
void CheckOverlapping(vector_type::const_iterator it)
Definition: docredln.cxx:439
size_type FindNextSeqNo(sal_uInt16 nSeqNo, size_type nSttPos) const
Search next or previous Redline with the same Seq.
Definition: docredln.cxx:687
bool InsertWithValidRanges(SwRangeRedline *&p, size_type *pInsPos=nullptr)
Definition: docredln.cxx:586
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: docredln.cxx:850
size_type FindPrevOfSeqNo(size_type nSttPos) const
Definition: docredln.cxx:679
vector_type maVector
Definition: docary.hxx:225
size_type FindPrevSeqNo(sal_uInt16 nSeqNo, size_type nSttPos) const
Definition: docredln.cxx:710
size_type FindNextOfSeqNo(size_type nSttPos) const
Definition: docredln.cxx:672
bool empty() const
Definition: docary.hxx:266
vector_type::const_iterator end() const
Definition: docary.hxx:270
bool isMoved(size_type tableIndex) const
Definition: docredln.cxx:757
bool Insert(SwRangeRedline *&p)
Definition: docredln.cxx:413
static void LOKRedlineNotification(RedlineNotification eType, SwRangeRedline *pRedline)
Emits LOK notification about one addition / removal of a redline item.
Definition: docredln.cxx:341
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:228
bool Contains(const SwRangeRedline *p) const
Definition: docary.hxx:231
void DeleteAndDestroy(size_type nPos)
Definition: docredln.cxx:664
o3tl::sorted_vector< SwRangeRedline *, CompareSwRedlineTable, o3tl::find_partialorder_ptrequals > vector_type
Definition: docary.hxx:221
static constexpr size_type npos
Definition: docary.hxx:223
size_type size() const
Definition: docary.hxx:267
vector_type::const_iterator begin() const
Definition: docary.hxx:269
void Remove(size_type nPos)
Definition: docredln.cxx:635
vector_type::size_type size_type
Definition: docary.hxx:222
SwRangeRedline * operator[](size_type idx) const
Definition: docary.hxx:268
bool HasOverlappingElements() const
Definition: docary.hxx:237
void Resort()
Definition: docary.hxx:271
void DeleteAndDestroyAll()
Definition: docredln.cxx:652
size_type GetPos(const SwRangeRedline *p) const
Definition: docredln.cxx:619
const SwRangeRedline * FindAtPosition(const SwPosition &startPosition, size_type &tableIndex, bool next=true) const
Find the redline at the given position.
Definition: docredln.cxx:731
Array of Undo-history.
Definition: docary.hxx:192
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: section.cxx:1005
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:419
SwTableLine is one table row in the document model.
Definition: swtable.hxx:358
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:487
std::vector< Value >::const_iterator const_iterator
Definition: docary.hxx:65
size_t GetPos(Value const &p) const
Definition: docary.hxx:133
iterator end()
Definition: docary.hxx:90
SwVectorModifyBase(SwVectorModifyBase const &)=default
std::vector< Value >::size_type size_type
Definition: docary.hxx:66
const DestructorPolicy mPolicy
Definition: docary.hxx:77
std::vector< Value > mvVals
Definition: docary.hxx:76
std::vector< Value >::value_type value_type
Definition: docary.hxx:67
void insert(iterator aIt, TInputIterator aFirst, TInputIterator aLast)
Definition: docary.hxx:97
Value const & at(size_type nPos) const
Definition: docary.hxx:103
void DeleteAndDestroy(int aStartIdx, int aEndIdx)
Definition: docary.hxx:123
const_iterator end() const
Definition: docary.hxx:91
iterator begin()
Definition: docary.hxx:88
iterator insert(iterator aIt, Value const &rVal)
Definition: docary.hxx:95
size_t size() const
Definition: docary.hxx:87
void push_back(Value const &rVal)
Definition: docary.hxx:101
Value & operator[](size_type nPos)
Definition: docary.hxx:105
static void dumpAsXml(xmlTextWriterPtr)
Definition: docary.hxx:143
iterator erase(iterator aFirst, iterator aLast)
Definition: docary.hxx:94
iterator erase(iterator aIt)
Definition: docary.hxx:93
Value const & front() const
Definition: docary.hxx:86
SwVectorModifyBase(DestructorPolicy policy=DestructorPolicy::FreeElements)
Definition: docary.hxx:81
Value const & operator[](size_type nPos) const
Definition: docary.hxx:104
bool empty() const
Definition: docary.hxx:85
virtual ~SwVectorModifyBase()
Definition: docary.hxx:108
SwVectorModifyBase & operator=(SwVectorModifyBase const &)=default
void reserve(size_type nSize)
Definition: docary.hxx:102
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:140
const_iterator begin() const
Definition: docary.hxx:89
std::vector< Value >::iterator iterator
Definition: docary.hxx:64
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
std::vector< SwOLENode * > SwOLENodes
Definition: docary.hxx:304
RedlineNotification
Definition: docary.hxx:215
const sal_uInt16 idx[]
void * p
sal_uInt16 nPos
Value
bool operator()(SwRangeRedline *const &lhs, SwRangeRedline *const &rhs) const
Definition: docredln.cxx:609
Marks a position in the document model.
Definition: pam.hxx:37
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
#define SAL_MAX_INT32