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>
24 #include <o3tl/sorted_vector.hxx>
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 
33 class SwRangeRedline;
34 class SwExtraRedline;
35 class SwOLENode;
36 class SwTable;
37 class SwTableLine;
38 class SwTableBox;
39 struct SwPosition;
40 enum class RedlineType : sal_uInt16;
41 
44 {
45 public:
46  virtual size_t GetFormatCount() const = 0;
47  virtual SwFormat* GetFormat(size_t idx) const = 0;
48  virtual ~SwFormatsBase() {};
49 
50  SwFormatsBase() = default;
51  SwFormatsBase(SwFormatsBase const &) = default;
52  SwFormatsBase(SwFormatsBase &&) = default;
53  SwFormatsBase & operator =(SwFormatsBase const &) = default;
54  SwFormatsBase & operator =(SwFormatsBase &&) = default;
55 };
56 
57 template<typename Value>
59 {
60 public:
61  typedef typename std::vector<Value>::iterator iterator;
62  typedef typename std::vector<Value>::const_iterator const_iterator;
63  typedef typename std::vector<Value>::size_type size_type;
64  typedef typename std::vector<Value>::value_type value_type;
65 
66 protected:
67  enum class DestructorPolicy {
70  };
71 
72 private:
73  typename std::vector<Value> mvVals;
75 
76 protected:
77  // default destructor deletes all contained elements
79  : mPolicy(policy) {}
80 
81 public:
82  bool empty() const { return mvVals.empty(); }
83  Value const& front() const { return mvVals.front(); }
84  size_t size() const { return mvVals.size(); }
85  iterator begin() { return mvVals.begin(); }
86  const_iterator begin() const { return mvVals.begin(); }
87  iterator end() { return mvVals.end(); }
88  const_iterator end() const { return mvVals.end(); }
89  void clear() { mvVals.clear(); }
90  iterator erase(iterator aIt) { return mvVals.erase(aIt); }
91  iterator erase(iterator aFirst, iterator aLast) { return mvVals.erase(aFirst, aLast); }
92  iterator insert(iterator aIt, Value const& rVal) { return mvVals.insert(aIt, rVal); }
93  template<typename TInputIterator>
94  void insert(iterator aIt, TInputIterator aFirst, TInputIterator aLast)
95  {
96  mvVals.insert(aIt, aFirst, aLast);
97  }
98  void push_back(Value const& rVal) { mvVals.push_back(rVal); }
99  void reserve(size_type nSize) { mvVals.reserve(nSize); }
100  Value const& at(size_type nPos) const { return mvVals.at(nPos); }
101  Value const& operator[](size_type nPos) const { return mvVals[nPos]; }
102  Value& operator[](size_type nPos) { return mvVals[nPos]; }
103 
104  // free any remaining child objects based on mPolicy
106  {
107  if (mPolicy == DestructorPolicy::FreeElements)
108  for(const_iterator it = begin(); it != end(); ++it)
109  delete *it;
110  }
111 
112  //TODO: These functions are apparently brittle (but the copy functions are actually used by the
113  // code; the move functions will be implicitly-defined as deleted anyway) and should probably
114  // only be used with DestructorPolicy::KeepELements:
115  SwVectorModifyBase(SwVectorModifyBase const &) = default;
117  SwVectorModifyBase & operator =(SwVectorModifyBase const &) = default;
119 
120  void DeleteAndDestroy(int aStartIdx, int aEndIdx)
121  {
122  if (aEndIdx < aStartIdx)
123  return;
124  for (const_iterator it = begin() + aStartIdx;
125  it != begin() + aEndIdx; ++it)
126  delete *it;
127  erase( begin() + aStartIdx, begin() + aEndIdx);
128  }
129 
130  size_t GetPos(Value const& p) const
131  {
132  const_iterator const it = std::find(begin(), end(), p);
133  return it == end() ? SIZE_MAX : it - begin();
134  }
135 
137  bool IsAlive(typename std::remove_pointer<Value>::type const*const p) const
138  { return std::find(begin(), end(), p) != end(); }
139 
140  static void dumpAsXml(xmlTextWriterPtr /*pWriter*/) {};
141 };
142 
143 template<typename Value>
145 {
146 protected:
149  : SwVectorModifyBase<Value>(policy) {}
150 
151 public:
152  virtual size_t GetFormatCount() const override
153  { return SwVectorModifyBase<Value>::size(); }
154 
155  virtual Value GetFormat(size_t idx) const override
157 
158  size_t GetPos(const SwFormat *p) const
159  { return SwVectorModifyBase<Value>::GetPos( static_cast<Value>( const_cast<SwFormat*>( p ) ) ); }
160 
163  bool ContainsFormat(SwFormat const*const pFormat) const {
164  Value p = dynamic_cast<Value>(const_cast<SwFormat*>(pFormat));
165  return p != nullptr && SwVectorModifyBase<Value>::IsAlive(p);
166  }
167 };
168 
169 class SwGrfFormatColls final : public SwFormatsModifyBase<SwGrfFormatColl*>
170 {
171 public:
173 };
174 
175 
177 class SwFrameFormatsV final : public SwFormatsModifyBase<SwFrameFormat*>
178 {
179 public:
181 };
182 
183 class SwCharFormats final : public SwFormatsModifyBase<SwCharFormat*>
184 {
185 public:
186  void dumpAsXml(xmlTextWriterPtr pWriter) const;
187 };
188 
189 class SwTextFormatColls final : public SwFormatsModifyBase<SwTextFormatColl*>
190 {
191 public:
193  void dumpAsXml(xmlTextWriterPtr pWriter) const;
194 };
195 
197 class SwSectionFormats final : public SwFormatsModifyBase<SwSectionFormat*>
198 {
199 public:
200  void dumpAsXml(xmlTextWriterPtr pWriter) const;
201 };
202 
203 class SwFieldTypes : public std::vector<std::unique_ptr<SwFieldType>> {
204 public:
205  void dumpAsXml(xmlTextWriterPtr pWriter) const;
206 };
207 
208 class SwTOXTypes : public std::vector<std::unique_ptr<SwTOXType>> {};
209 
210 class SwNumRuleTable final : public SwVectorModifyBase<SwNumRule*> {
211 public:
212  void dumpAsXml(xmlTextWriterPtr pWriter) const;
213 };
214 
216 {
217  bool operator()(SwRangeRedline* const &lhs, SwRangeRedline* const &rhs) const;
218 };
219 
220 // Notification type for notifying about redlines to LOK clients
222 
224 {
225 public:
229  static constexpr size_type npos = SAL_MAX_INT32;
230 private:
231  vector_type maVector;
232 public:
233  ~SwRedlineTable();
234  bool Contains(const SwRangeRedline* p) const { return maVector.find(const_cast<SwRangeRedline*>(p)) != maVector.end(); }
235  size_type GetPos(const SwRangeRedline* p) const;
236 
237  bool Insert(SwRangeRedline*& p);
238  bool Insert(SwRangeRedline*& p, size_type& rInsPos);
239  bool InsertWithValidRanges(SwRangeRedline*& p, size_type* pInsPos = nullptr);
240 
241  void Remove( size_type nPos );
242  void Remove( const SwRangeRedline* p );
243  void DeleteAndDestroy(size_type nPos);
244  void DeleteAndDestroyAll();
245 
246  void dumpAsXml(xmlTextWriterPtr pWriter) const;
247 
248  size_type FindNextOfSeqNo( size_type nSttPos ) const;
249  size_type FindPrevOfSeqNo( size_type nSttPos ) const;
253  size_type FindNextSeqNo( sal_uInt16 nSeqNo, size_type nSttPos ) const;
254  size_type FindPrevSeqNo( sal_uInt16 nSeqNo, size_type nSttPos ) const;
255 
263  const SwRangeRedline* FindAtPosition( const SwPosition& startPosition, size_type& tableIndex, bool next = true ) const;
264 
265  bool empty() const { return maVector.empty(); }
266  size_type size() const { return maVector.size(); }
267  SwRangeRedline* operator[]( size_type idx ) const { return maVector[idx]; }
268  vector_type::const_iterator begin() const { return maVector.begin(); }
269  vector_type::const_iterator end() const { return maVector.end(); }
270  void Resort() { maVector.Resort(); }
271 
272  // Notifies all LOK clients when redlines are added/modified/removed
273  static void LOKRedlineNotification(RedlineNotification eType, SwRangeRedline* pRedline);
274 };
275 
278 {
279 private:
280  std::vector<SwExtraRedline*> m_aExtraRedlines;
281 
282 public:
284 
285  void Insert( SwExtraRedline* p );
286 
287  void DeleteAndDestroy( sal_uInt16 nPos);
288  void DeleteAndDestroyAll();
289 
290  void dumpAsXml(xmlTextWriterPtr pWriter) const;
291 
292  sal_uInt16 GetSize() const { return m_aExtraRedlines.size(); }
293  SwExtraRedline* GetRedline( sal_uInt16 uIndex ) const { return m_aExtraRedlines.operator[]( uIndex ); }
294 
295  SW_DLLPUBLIC bool DeleteAllTableRedlines( SwDoc* pDoc, const SwTable& rTable, bool bSaveInUndo, RedlineType nRedlineTypeToDelete );
296  bool DeleteTableRowRedline ( SwDoc* pDoc, const SwTableLine& rTableLine, bool bSaveInUndo, RedlineType nRedlineTypeToDelete );
297  bool DeleteTableCellRedline( SwDoc* pDoc, const SwTableBox& rTableBox, bool bSaveInUndo, RedlineType nRedlineTypeToDelete );
298 };
299 
300 typedef std::vector<SwOLENode*> SwOLENodes;
301 
302 #endif // INCLUDED_SW_INC_DOCARY_HXX
303 
304 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void DeleteAndDestroy(int aStartIdx, int aEndIdx)
Definition: docary.hxx:120
void Resort()
Definition: docary.hxx:270
void insert(iterator aIt, TInputIterator aFirst, TInputIterator aLast)
Definition: docary.hxx:94
bool InsertWithValidRanges(SwRangeRedline *&p, size_type *pInsPos=nullptr)
Definition: docredln.cxx:557
void Insert(SwExtraRedline *p)
Definition: docredln.cxx:1848
static void dumpAsXml(xmlTextWriterPtr)
Definition: docary.hxx:140
Marks a position in the document model.
Definition: pam.hxx:35
void reserve(size_type nSize)
Definition: docary.hxx:99
vector_type::const_iterator end() const
Definition: docary.hxx:269
bool Contains(const SwRangeRedline *p) const
Definition: docary.hxx:234
size_type FindPrevOfSeqNo(size_type nSttPos) const
Definition: docredln.cxx:649
iterator erase(iterator aFirst, iterator aLast)
Definition: docary.hxx:91
void Remove(size_type nPos)
Definition: docredln.cxx:606
Definition: doc.hxx:184
size_t GetPos(Value const &p) const
Definition: docary.hxx:130
const_iterator find(const Value &x) const
virtual size_t GetFormatCount() const override
Definition: docary.hxx:152
SwTableLine is one table row in the document model.
Definition: swtable.hxx:344
SwExtraRedline * GetRedline(sal_uInt16 uIndex) const
Definition: docary.hxx:293
std::vector< Value >::const_iterator const_iterator
Definition: docary.hxx:62
Value const & at(size_type nPos) const
Definition: docary.hxx:100
std::vector< Value > mvVals
Definition: docary.hxx:73
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: number.cxx:1466
bool empty() const
Definition: docary.hxx:82
size_t GetPos(const SwFormat *p) const
Definition: docary.hxx:158
Array of Undo-history.
Definition: docary.hxx:197
size_type size() const
Definition: docary.hxx:266
Value
provides some methods for generic operations on lists that contain SwFormat* subclasses.
Definition: docary.hxx:43
const_iterator end() const
Definition: docary.hxx:88
SW_DLLPUBLIC bool DeleteAllTableRedlines(SwDoc *pDoc, const SwTable &rTable, bool bSaveInUndo, RedlineType nRedlineTypeToDelete)
Definition: docredln.cxx:130
bool empty() const
Definition: docary.hxx:265
Unsorted, undeleting SwFrameFormat vector.
Definition: docary.hxx:177
vector_type::const_iterator begin() const
Definition: docary.hxx:268
SwFormatsBase()=default
static void LOKRedlineNotification(RedlineNotification eType, SwRangeRedline *pRedline)
Emits LOK notification about one addition / removal of a redline item.
Definition: docredln.cxx:345
void DeleteAndDestroy(sal_uInt16 nPos)
Definition: docredln.cxx:1854
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fmtcol.cxx:470
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:137
Base class for various Writer styles.
Definition: format.hxx:43
vector_type maVector
Definition: docary.hxx:231
sal_uInt16 GetSize() const
Definition: docary.hxx:292
Table that holds 'extra' redlines, such as 'table row insert/delete', 'paragraph moves' etc...
Definition: docary.hxx:277
size_type FindPrevSeqNo(sal_uInt16 nSeqNo, size_type nSttPos) const
Definition: docredln.cxx:680
struct _xmlTextWriter * xmlTextWriterPtr
size_type GetPos(const SwRangeRedline *p) const
Definition: docredln.cxx:590
Value const & front() const
Definition: docary.hxx:83
#define SAL_MAX_INT32
std::vector< SwOLENode * > SwOLENodes
Definition: docary.hxx:300
std::vector< Value >::value_type value_type
Definition: docary.hxx:64
void DeleteAndDestroy(size_type nPos)
Definition: docredln.cxx:634
iterator begin()
Definition: docary.hxx:85
std::vector< Value >::size_type size_type
Definition: docary.hxx:63
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: section.cxx:1080
void DeleteAndDestroyAll()
Definition: docredln.cxx:623
virtual size_t GetFormatCount() const =0
vector_type::size_type size_type
Definition: docary.hxx:228
SwFormatsBase & operator=(SwFormatsBase const &)=default
bool DeleteTableRowRedline(SwDoc *pDoc, const SwTableLine &rTableLine, bool bSaveInUndo, RedlineType nRedlineTypeToDelete)
Definition: docredln.cxx:206
size_t size() const
Definition: docary.hxx:84
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:198
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: docredln.cxx:729
std::vector< Value >::iterator iterator
Definition: docary.hxx:61
const SwRangeRedline * FindAtPosition(const SwPosition &startPosition, size_type &tableIndex, bool next=true) const
Find the redline at the given position.
Definition: docredln.cxx:701
iterator erase(iterator aIt)
Definition: docary.hxx:90
Value const & operator[](size_type nPos) const
Definition: docary.hxx:101
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:268
SwVectorModifyBase & operator=(SwVectorModifyBase const &)=default
SwFormatsModifyBase(typename SwVectorModifyBase< Value >::DestructorPolicy policy=SwVectorModifyBase< Value >::DestructorPolicy::FreeElements)
Definition: docary.hxx:147
iterator end()
Definition: docary.hxx:87
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:110
SwVectorModifyBase(DestructorPolicy policy=DestructorPolicy::FreeElements)
Definition: docary.hxx:78
iterator insert(iterator aIt, Value const &rVal)
Definition: docary.hxx:92
void push_back(Value const &rVal)
Definition: docary.hxx:98
const_iterator begin() const
virtual Value GetFormat(size_t idx) const override
Definition: docary.hxx:155
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: chrfmt.cxx:34
size_type FindNextOfSeqNo(size_type nSttPos) const
Definition: docredln.cxx:642
const DestructorPolicy mPolicy
Definition: docary.hxx:74
SwRangeRedline * operator[](size_type idx) const
Definition: docary.hxx:267
const_iterator begin() const
Definition: docary.hxx:86
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: docredln.cxx:86
virtual ~SwFormatsBase()
Definition: docary.hxx:48
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:386
Value & operator[](size_type nPos)
Definition: docary.hxx:102
void * p
size_type FindNextSeqNo(sal_uInt16 nSeqNo, size_type nSttPos) const
Search next or previous Redline with the same Seq.
Definition: docredln.cxx:657
RedlineNotification
Definition: docary.hxx:221
void DeleteAndDestroyAll()
Definition: docredln.cxx:1873
bool ContainsFormat(SwFormat const *const pFormat) const
check if given format is contained here pFormat must not have been deleted
Definition: docary.hxx:163
o3tl::sorted_vector< SwRangeRedline *, CompareSwRedlineTable, o3tl::find_partialorder_ptrequals > vector_type
Definition: docary.hxx:227
RedlineType
virtual SwFormat * GetFormat(size_t idx) const =0
bool DeleteTableCellRedline(SwDoc *pDoc, const SwTableBox &rTableBox, bool bSaveInUndo, RedlineType nRedlineTypeToDelete)
Definition: docredln.cxx:250
bool Insert(SwRangeRedline *&p)
Definition: docredln.cxx:420
std::vector< Value >::size_type size_type
static constexpr size_type npos
Definition: docary.hxx:229
bool operator()(SwRangeRedline *const &lhs, SwRangeRedline *const &rhs) const
Definition: docredln.cxx:580
virtual ~SwVectorModifyBase()
Definition: docary.hxx:105
std::vector< SwExtraRedline * > m_aExtraRedlines
Definition: docary.hxx:280