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 <map>
23 #include <vector>
24 #include <type_traits>
25 #include <o3tl/sorted_vector.hxx>
26 
27 #include "fmtcol.hxx"
28 #include "frmfmt.hxx"
29 #include "section.hxx"
30 #include "tox.hxx"
31 #include "numrule.hxx"
32 #include "fldbas.hxx"
33 
34 class SwRangeRedline;
35 class SwExtraRedline;
36 class SwOLENode;
37 class SwTable;
38 class SwTableLine;
39 class SwTableBox;
40 struct SwPosition;
41 enum class RedlineType : sal_uInt16;
42 
45 {
46 public:
47  virtual size_t GetFormatCount() const = 0;
48  virtual SwFormat* GetFormat(size_t idx) const = 0;
49  virtual ~SwFormatsBase();
50 
51  // default linear search implementation, some subclasses will override with a more efficient search
52  virtual SwFormat* FindFormatByName(const OUString& rName) const;
53 
54  SwFormatsBase() = default;
55  SwFormatsBase(SwFormatsBase const &) = default;
56  SwFormatsBase(SwFormatsBase &&) = default;
57  SwFormatsBase & operator =(SwFormatsBase const &) = default;
58  SwFormatsBase & operator =(SwFormatsBase &&) = default;
59 };
60 
61 template<typename Value>
63 {
64 public:
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 
70 protected:
71  enum class DestructorPolicy {
74  };
75 
76 private:
77  typename std::vector<Value> mvVals;
79 
80 protected:
81  // default destructor deletes all contained elements
83  : mPolicy(policy) {}
84 
85 public:
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]; }
106  Value& operator[](size_type nPos) { return mvVals[nPos]; }
107 
108  // free any remaining child objects based on mPolicy
110  {
111  if (mPolicy == DestructorPolicy::FreeElements)
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:
119  SwVectorModifyBase(SwVectorModifyBase const &) = default;
121  SwVectorModifyBase & operator =(SwVectorModifyBase const &) = default;
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 
147 template<typename Value>
149 {
150 protected:
153  : SwVectorModifyBase<Value>(policy) {}
154 
155 public:
156  virtual size_t GetFormatCount() const override
157  { return SwVectorModifyBase<Value>::size(); }
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 
170 class SwGrfFormatColls final : public SwFormatsModifyBase<SwGrfFormatColl*>
171 {
172 public:
174 };
175 
176 
178 class SwFrameFormatsV final : public SwFormatsModifyBase<SwFrameFormat*>
179 {
180 public:
182 };
183 
184 class SwTextFormatColls final : public SwFormatsModifyBase<SwTextFormatColl*>
185 {
186 public:
188  void dumpAsXml(xmlTextWriterPtr pWriter) const;
189 };
190 
192 class SwSectionFormats final : public SwFormatsModifyBase<SwSectionFormat*>
193 {
194 public:
195  void dumpAsXml(xmlTextWriterPtr pWriter) const;
196 };
197 
198 class SwFieldTypes : public std::vector<std::unique_ptr<SwFieldType>> {
199 public:
200  void dumpAsXml(xmlTextWriterPtr pWriter) const;
201 };
202 
203 class SwTOXTypes : public std::vector<std::unique_ptr<SwTOXType>> {};
204 
205 class SwNumRuleTable final : public SwVectorModifyBase<SwNumRule*> {
206 public:
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 {
220 public:
224  static constexpr size_type npos = SAL_MAX_INT32;
225 private:
226  vector_type maVector;
227 public:
228  ~SwRedlineTable();
229  bool Contains(const SwRangeRedline* p) const { return maVector.find(const_cast<SwRangeRedline*>(p)) != maVector.end(); }
230  size_type GetPos(const SwRangeRedline* p) const;
231 
232  bool Insert(SwRangeRedline*& p);
233  bool Insert(SwRangeRedline*& p, size_type& rInsPos);
234  bool InsertWithValidRanges(SwRangeRedline*& p, size_type* pInsPos = nullptr);
235 
236  void Remove( size_type nPos );
237  void Remove( const SwRangeRedline* p );
238  void DeleteAndDestroy(size_type nPos);
239  void DeleteAndDestroyAll();
240 
241  void dumpAsXml(xmlTextWriterPtr pWriter) const;
242 
243  size_type FindNextOfSeqNo( size_type nSttPos ) const;
244  size_type FindPrevOfSeqNo( size_type nSttPos ) const;
248  size_type FindNextSeqNo( sal_uInt16 nSeqNo, size_type nSttPos ) const;
249  size_type FindPrevSeqNo( sal_uInt16 nSeqNo, size_type nSttPos ) const;
250 
258  const SwRangeRedline* FindAtPosition( const SwPosition& startPosition, size_type& tableIndex, bool next = true ) const;
259 
260  bool empty() const { return maVector.empty(); }
261  size_type size() const { return maVector.size(); }
262  SwRangeRedline* operator[]( size_type idx ) const { return maVector[idx]; }
263  vector_type::const_iterator begin() const { return maVector.begin(); }
264  vector_type::const_iterator end() const { return maVector.end(); }
265  void Resort() { maVector.Resort(); }
266 
267  // Notifies all LOK clients when redlines are added/modified/removed
268  static void LOKRedlineNotification(RedlineNotification eType, SwRangeRedline* pRedline);
269 };
270 
273 {
274 private:
275  std::vector<SwExtraRedline*> m_aExtraRedlines;
276 
277 public:
279 
280  void Insert( SwExtraRedline* p );
281 
282  void DeleteAndDestroy( sal_uInt16 nPos);
283  void DeleteAndDestroyAll();
284 
285  void dumpAsXml(xmlTextWriterPtr pWriter) const;
286 
287  sal_uInt16 GetSize() const { return m_aExtraRedlines.size(); }
288  SwExtraRedline* GetRedline( sal_uInt16 uIndex ) const { return m_aExtraRedlines.operator[]( uIndex ); }
289 
290  SW_DLLPUBLIC bool DeleteAllTableRedlines( SwDoc& rDoc, const SwTable& rTable, bool bSaveInUndo, RedlineType nRedlineTypeToDelete );
291  bool DeleteTableRowRedline ( SwDoc* pDoc, const SwTableLine& rTableLine, bool bSaveInUndo, RedlineType nRedlineTypeToDelete );
292  bool DeleteTableCellRedline( SwDoc* pDoc, const SwTableBox& rTableBox, bool bSaveInUndo, RedlineType nRedlineTypeToDelete );
293 };
294 
295 typedef std::vector<SwOLENode*> SwOLENodes;
296 
297 #endif // INCLUDED_SW_INC_DOCARY_HXX
298 
299 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void DeleteAndDestroy(int aStartIdx, int aEndIdx)
Definition: docary.hxx:124
void Resort()
Definition: docary.hxx:265
void insert(iterator aIt, TInputIterator aFirst, TInputIterator aLast)
Definition: docary.hxx:98
virtual Value FindFormatByName(const OUString &rName) const override
Definition: docary.hxx:166
bool InsertWithValidRanges(SwRangeRedline *&p, size_type *pInsPos=nullptr)
Definition: docredln.cxx:568
void Insert(SwExtraRedline *p)
Definition: docredln.cxx:1935
static void dumpAsXml(xmlTextWriterPtr)
Definition: docary.hxx:144
Marks a position in the document model.
Definition: pam.hxx:35
void reserve(size_type nSize)
Definition: docary.hxx:103
vector_type::const_iterator end() const
Definition: docary.hxx:264
bool Contains(const SwRangeRedline *p) const
Definition: docary.hxx:229
size_type FindPrevOfSeqNo(size_type nSttPos) const
Definition: docredln.cxx:660
iterator erase(iterator aFirst, iterator aLast)
Definition: docary.hxx:95
virtual SwFormat * FindFormatByName(const OUString &rName) const
Definition: format.cxx:772
void Remove(size_type nPos)
Definition: docredln.cxx:617
Definition: doc.hxx:188
size_t GetPos(Value const &p) const
Definition: docary.hxx:134
const_iterator find(const Value &x) const
virtual size_t GetFormatCount() const override
Definition: docary.hxx:156
SwTableLine is one table row in the document model.
Definition: swtable.hxx:351
virtual ~SwFormatsBase()
Definition: format.cxx:769
SwExtraRedline * GetRedline(sal_uInt16 uIndex) const
Definition: docary.hxx:288
std::vector< Value >::const_iterator const_iterator
Definition: docary.hxx:66
Value const & at(size_type nPos) const
Definition: docary.hxx:104
std::vector< Value > mvVals
Definition: docary.hxx:77
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: number.cxx:1528
bool empty() const
Definition: docary.hxx:86
size_t GetPos(const SwFormat *p) const
Definition: docary.hxx:162
Array of Undo-history.
Definition: docary.hxx:192
size_type size() const
Definition: docary.hxx:261
Value
provides some methods for generic operations on lists that contain SwFormat* subclasses.
Definition: docary.hxx:44
const_iterator end() const
Definition: docary.hxx:92
bool empty() const
Definition: docary.hxx:260
Unsorted, undeleting SwFrameFormat vector.
Definition: docary.hxx:178
vector_type::const_iterator begin() const
Definition: docary.hxx:263
SwFormatsBase()=default
static void LOKRedlineNotification(RedlineNotification eType, SwRangeRedline *pRedline)
Emits LOK notification about one addition / removal of a redline item.
Definition: docredln.cxx:357
void DeleteAndDestroy(sal_uInt16 nPos)
Definition: docredln.cxx:1941
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fmtcol.cxx:482
size_type size() const
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
Base class for various Writer styles.
Definition: format.hxx:46
vector_type maVector
Definition: docary.hxx:226
sal_uInt16 GetSize() const
Definition: docary.hxx:287
Table that holds 'extra' redlines, such as 'table row insert/delete', 'paragraph moves' etc...
Definition: docary.hxx:272
size_type FindPrevSeqNo(sal_uInt16 nSeqNo, size_type nSttPos) const
Definition: docredln.cxx:691
struct _xmlTextWriter * xmlTextWriterPtr
size_type GetPos(const SwRangeRedline *p) const
Definition: docredln.cxx:601
Value const & front() const
Definition: docary.hxx:87
#define SAL_MAX_INT32
std::vector< SwOLENode * > SwOLENodes
Definition: docary.hxx:295
std::vector< Value >::value_type value_type
Definition: docary.hxx:68
void DeleteAndDestroy(size_type nPos)
Definition: docredln.cxx:645
iterator begin()
Definition: docary.hxx:89
std::vector< Value >::size_type size_type
Definition: docary.hxx:67
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: section.cxx:1034
void DeleteAndDestroyAll()
Definition: docredln.cxx:634
virtual size_t GetFormatCount() const =0
vector_type::size_type size_type
Definition: docary.hxx:223
SwFormatsBase & operator=(SwFormatsBase const &)=default
bool DeleteTableRowRedline(SwDoc *pDoc, const SwTableLine &rTableLine, bool bSaveInUndo, RedlineType nRedlineTypeToDelete)
Definition: docredln.cxx:209
size_t size() const
Definition: docary.hxx:88
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:212
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: docredln.cxx:740
std::vector< Value >::iterator iterator
Definition: docary.hxx:65
const SwRangeRedline * FindAtPosition(const SwPosition &startPosition, size_type &tableIndex, bool next=true) const
Find the redline at the given position.
Definition: docredln.cxx:712
iterator erase(iterator aIt)
Definition: docary.hxx:94
Value const & operator[](size_type nPos) const
Definition: docary.hxx:105
const_iterator end() const
bool empty() const
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
Base object for 'Redlines' that are not of 'Ranged' type (like table row insert)
Definition: redline.hxx:269
SwVectorModifyBase & operator=(SwVectorModifyBase const &)=default
SwFormatsModifyBase(typename SwVectorModifyBase< Value >::DestructorPolicy policy=SwVectorModifyBase< Value >::DestructorPolicy::FreeElements)
Definition: docary.hxx:151
SW_DLLPUBLIC bool DeleteAllTableRedlines(SwDoc &rDoc, const SwTable &rTable, bool bSaveInUndo, RedlineType nRedlineTypeToDelete)
Definition: docredln.cxx:133
iterator end()
Definition: docary.hxx:91
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:111
SwVectorModifyBase(DestructorPolicy policy=DestructorPolicy::FreeElements)
Definition: docary.hxx:82
iterator insert(iterator aIt, Value const &rVal)
Definition: docary.hxx:96
void push_back(Value const &rVal)
Definition: docary.hxx:102
const sal_uInt16 idx[]
const_iterator begin() const
virtual Value GetFormat(size_t idx) const override
Definition: docary.hxx:159
size_type FindNextOfSeqNo(size_type nSttPos) const
Definition: docredln.cxx:653
const DestructorPolicy mPolicy
Definition: docary.hxx:78
SwRangeRedline * operator[](size_type idx) const
Definition: docary.hxx:262
const_iterator begin() const
Definition: docary.hxx:90
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: docredln.cxx:89
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:395
Value & operator[](size_type nPos)
Definition: docary.hxx:106
size_type FindNextSeqNo(sal_uInt16 nSeqNo, size_type nSttPos) const
Search next or previous Redline with the same Seq.
Definition: docredln.cxx:668
RedlineNotification
Definition: docary.hxx:216
void DeleteAndDestroyAll()
Definition: docredln.cxx:1960
o3tl::sorted_vector< SwRangeRedline *, CompareSwRedlineTable, o3tl::find_partialorder_ptrequals > vector_type
Definition: docary.hxx:222
RedlineType
virtual SwFormat * GetFormat(size_t idx) const =0
bool DeleteTableCellRedline(SwDoc *pDoc, const SwTableBox &rTableBox, bool bSaveInUndo, RedlineType nRedlineTypeToDelete)
Definition: docredln.cxx:253
bool Insert(SwRangeRedline *&p)
Definition: docredln.cxx:431
std::vector< Value >::size_type size_type
static constexpr size_type npos
Definition: docary.hxx:224
bool operator()(SwRangeRedline *const &lhs, SwRangeRedline *const &rhs) const
Definition: docredln.cxx:591
virtual ~SwVectorModifyBase()
Definition: docary.hxx:109
std::vector< SwExtraRedline * > m_aExtraRedlines
Definition: docary.hxx:275