File: | home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx |
Warning: | line 1250, column 9 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 | ||||
20 | #include <iostream> | |||
21 | #include <stdio.h> | |||
22 | #include "WW8TableInfo.hxx" | |||
23 | #include <fmtfsize.hxx> | |||
24 | #include "attributeoutputbase.hxx" | |||
25 | #include <swtable.hxx> | |||
26 | #include <frmfmt.hxx> | |||
27 | #include <pam.hxx> | |||
28 | #include <dbgoutsw.hxx> | |||
29 | #include <sal/log.hxx> | |||
30 | #include <osl/diagnose.h> | |||
31 | ||||
32 | namespace ww8 | |||
33 | { | |||
34 | ||||
35 | WW8TableNodeInfoInner::WW8TableNodeInfoInner(WW8TableNodeInfo * pParent) | |||
36 | : mpParent(pParent) | |||
37 | , mnDepth(0) | |||
38 | , mnCell(0) | |||
39 | , mnRow(0) | |||
40 | , mnShadowsBefore(0) | |||
41 | , mnShadowsAfter(0) | |||
42 | , mbEndOfLine(false) | |||
43 | , mbFinalEndOfLine(false) | |||
44 | , mbEndOfCell(false) | |||
45 | , mbFirstInTable(false) | |||
46 | , mbVertMerge(false) | |||
47 | , mpTableBox(nullptr) | |||
48 | , mpTable(nullptr) | |||
49 | { | |||
50 | } | |||
51 | ||||
52 | WW8TableNodeInfoInner::~WW8TableNodeInfoInner() | |||
53 | { | |||
54 | } | |||
55 | ||||
56 | void WW8TableNodeInfoInner::setDepth(sal_uInt32 nDepth) | |||
57 | { | |||
58 | mnDepth = nDepth; | |||
59 | } | |||
60 | ||||
61 | void WW8TableNodeInfoInner::setCell(sal_uInt32 nCell) | |||
62 | { | |||
63 | mnCell = nCell; | |||
64 | } | |||
65 | ||||
66 | void WW8TableNodeInfoInner::setRow(sal_uInt32 nRow) | |||
67 | { | |||
68 | mnRow = nRow; | |||
69 | } | |||
70 | ||||
71 | void WW8TableNodeInfoInner::setShadowsBefore(sal_uInt32 nShadowsBefore) | |||
72 | { | |||
73 | mnShadowsBefore = nShadowsBefore; | |||
74 | } | |||
75 | ||||
76 | void WW8TableNodeInfoInner::setShadowsAfter(sal_uInt32 nShadowsAfter) | |||
77 | { | |||
78 | mnShadowsAfter = nShadowsAfter; | |||
79 | } | |||
80 | ||||
81 | void WW8TableNodeInfoInner::setEndOfLine(bool bEndOfLine) | |||
82 | { | |||
83 | mbEndOfLine = bEndOfLine; | |||
84 | } | |||
85 | ||||
86 | void WW8TableNodeInfoInner::setFinalEndOfLine(bool bFinalEndOfLine) | |||
87 | { | |||
88 | mbFinalEndOfLine = bFinalEndOfLine; | |||
89 | } | |||
90 | ||||
91 | void WW8TableNodeInfoInner::setEndOfCell(bool bEndOfCell) | |||
92 | { | |||
93 | mbEndOfCell = bEndOfCell; | |||
94 | } | |||
95 | ||||
96 | void WW8TableNodeInfoInner::setFirstInTable(bool bFirstInTable) | |||
97 | { | |||
98 | mbFirstInTable = bFirstInTable; | |||
99 | } | |||
100 | ||||
101 | void WW8TableNodeInfoInner::setVertMerge(bool bVertMerge) | |||
102 | ||||
103 | { | |||
104 | mbVertMerge = bVertMerge; | |||
105 | } | |||
106 | ||||
107 | void WW8TableNodeInfoInner::setTableBox(const SwTableBox * pTableBox) | |||
108 | { | |||
109 | mpTableBox = pTableBox; | |||
110 | } | |||
111 | ||||
112 | void WW8TableNodeInfoInner::setTable(const SwTable * pTable) | |||
113 | { | |||
114 | mpTable = pTable; | |||
115 | } | |||
116 | ||||
117 | void WW8TableNodeInfoInner::setRect(const SwRect & rRect) | |||
118 | { | |||
119 | maRect = rRect; | |||
120 | } | |||
121 | ||||
122 | const SwNode * WW8TableNodeInfoInner::getNode() const | |||
123 | { | |||
124 | const SwNode * pResult = nullptr; | |||
125 | ||||
126 | if (mpParent != nullptr) | |||
127 | pResult = mpParent->getNode(); | |||
128 | ||||
129 | return pResult; | |||
130 | } | |||
131 | ||||
132 | TableBoxVectorPtr WW8TableNodeInfoInner::getTableBoxesOfRow() const | |||
133 | { | |||
134 | TableBoxVectorPtr pResult = std::make_shared<TableBoxVector>(); | |||
135 | ||||
136 | WW8TableCellGrid::Pointer_t pCellGrid = | |||
137 | mpParent->getParent()->getCellGridForTable(getTable(), false); | |||
138 | ||||
139 | if (!pCellGrid) | |||
140 | { | |||
141 | const SwTableLine * pTabLine = getTableBox()->GetUpper(); | |||
142 | const SwTableBoxes & rTableBoxes = pTabLine->GetTabBoxes(); | |||
143 | ||||
144 | sal_uInt8 nBoxes = rTableBoxes.size(); | |||
145 | if (nBoxes > MAXTABLECELLS) | |||
146 | nBoxes = MAXTABLECELLS; | |||
147 | for ( sal_uInt8 n = 0; n < nBoxes; n++ ) | |||
148 | { | |||
149 | pResult->push_back(rTableBoxes[n]); | |||
150 | } | |||
151 | } | |||
152 | else | |||
153 | pResult = pCellGrid->getTableBoxesOfRow(this); | |||
154 | ||||
155 | return pResult; | |||
156 | } | |||
157 | ||||
158 | GridColsPtr WW8TableNodeInfoInner::getGridColsOfRow(AttributeOutputBase & rBase, bool calculateColumnsFromAllRows) | |||
159 | { | |||
160 | GridColsPtr pResult = std::make_shared<GridCols>(); | |||
161 | WidthsPtr pWidths; | |||
162 | ||||
163 | // Check which columns should be checked - only the current row, | |||
164 | // or all the rows together | |||
165 | if (calculateColumnsFromAllRows) | |||
166 | { | |||
167 | // Calculate the width of all the columns based on ALL the rows. | |||
168 | // The difference is that this kind of draws vertical lines, | |||
169 | // so that if the rows look like this: | |||
170 | // | |||
171 | // ------------------------ | |||
172 | // | | | | |||
173 | // ------------------------ | |||
174 | // | | | | |||
175 | // ------------------------ | |||
176 | // | | | | |||
177 | // ------------------------ | |||
178 | ||||
179 | // then the actual column widths will be broken down like this: | |||
180 | // | |||
181 | // ------------------------ | |||
182 | // | | | | | | |||
183 | // ------------------------ | |||
184 | ||||
185 | // See the example at | |||
186 | // http://officeopenxml.com/WPtableGrid.php | |||
187 | // Under "Word 2007 Example" | |||
188 | pWidths = getColumnWidthsBasedOnAllRows(); | |||
189 | } | |||
190 | else | |||
191 | { | |||
192 | // Calculate the width of all the columns based on the current row | |||
193 | pWidths = getWidthsOfRow(); | |||
194 | } | |||
195 | ||||
196 | const SwFrameFormat *pFormat = getTable()->GetFrameFormat(); | |||
197 | OSL_ENSURE(pFormat,"Impossible")do { if (true && (!(pFormat))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "197" ": "), "%s", "Impossible"); } } while (false); | |||
198 | if (!pFormat) | |||
199 | return pResult; | |||
200 | ||||
201 | const SwFormatFrameSize &rSize = pFormat->GetFrameSize(); | |||
202 | unsigned long nTableSz = static_cast<unsigned long>(rSize.GetWidth()); | |||
203 | ||||
204 | long nPageSize = 0; | |||
205 | bool bRelBoxSize = false; | |||
206 | ||||
207 | rBase.GetTablePageSize( this, nPageSize, bRelBoxSize ); | |||
208 | ||||
209 | SwTwips nSz = 0; | |||
210 | for (const auto& rWidth : *pWidths) | |||
211 | { | |||
212 | nSz += rWidth; | |||
213 | SwTwips nCalc = nSz; | |||
214 | if ( bRelBoxSize ) | |||
215 | nCalc = ( nCalc * nPageSize ) / nTableSz; | |||
216 | ||||
217 | pResult->push_back( nCalc ); | |||
218 | } | |||
219 | ||||
220 | return pResult; | |||
221 | } | |||
222 | ||||
223 | WidthsPtr WW8TableNodeInfoInner::getColumnWidthsBasedOnAllRows() const | |||
224 | { | |||
225 | WidthsPtr pWidths; | |||
226 | ||||
227 | WW8TableCellGrid::Pointer_t pCellGrid = | |||
228 | mpParent->getParent()->getCellGridForTable(getTable(), false); | |||
229 | ||||
230 | if (!pCellGrid) | |||
231 | { | |||
232 | const SwTable * pTable = getTable(); | |||
233 | const SwTableLines& rTableLines = pTable->GetTabLines(); | |||
234 | const size_t nNumOfLines = rTableLines.size(); | |||
235 | ||||
236 | // Go over all the rows - and for each row - calculate where | |||
237 | // there is a separator between columns | |||
238 | WidthsPtr pSeparators = std::make_shared<Widths>(); | |||
239 | for ( size_t nLineIndex = 0; nLineIndex < nNumOfLines; ++nLineIndex ) | |||
240 | { | |||
241 | const SwTableLine *pCurrentLine = rTableLines[nLineIndex]; | |||
242 | const SwTableBoxes & rTabBoxes = pCurrentLine->GetTabBoxes(); | |||
243 | size_t nBoxes = rTabBoxes.size(); | |||
244 | if (nBoxes > MAXTABLECELLS) | |||
245 | nBoxes = MAXTABLECELLS; | |||
246 | ||||
247 | sal_uInt32 nSeparatorPosition = 0; | |||
248 | for (size_t nBoxIndex = 0; nBoxIndex < nBoxes; ++nBoxIndex) | |||
249 | { | |||
250 | const SwFrameFormat* pBoxFormat = rTabBoxes[ nBoxIndex ]->GetFrameFormat(); | |||
251 | const SwFormatFrameSize& rLSz = pBoxFormat->GetFrameSize(); | |||
252 | nSeparatorPosition += rLSz.GetWidth(); | |||
253 | pSeparators->push_back(nSeparatorPosition); | |||
254 | } | |||
255 | } | |||
256 | ||||
257 | // Sort the separator positions and remove any duplicates | |||
258 | std::sort(pSeparators->begin(), pSeparators->end()); | |||
259 | std::vector<sal_uInt32>::iterator it = std::unique(pSeparators->begin(), pSeparators->end()); | |||
260 | pSeparators->erase(it, pSeparators->end()); | |||
261 | ||||
262 | // Calculate the widths based on the position of the unique & sorted | |||
263 | // column separators | |||
264 | pWidths = std::make_shared<Widths>(); | |||
265 | sal_uInt32 nPreviousWidth = 0; | |||
266 | for (const sal_uInt32 nCurrentWidth : *pSeparators) | |||
267 | { | |||
268 | pWidths->push_back(nCurrentWidth - nPreviousWidth); | |||
269 | nPreviousWidth = nCurrentWidth; | |||
270 | } | |||
271 | } | |||
272 | else | |||
273 | { | |||
274 | pWidths = pCellGrid->getWidthsOfRow(this); | |||
275 | } | |||
276 | ||||
277 | return pWidths; | |||
278 | } | |||
279 | ||||
280 | WidthsPtr WW8TableNodeInfoInner::getWidthsOfRow() const | |||
281 | { | |||
282 | WidthsPtr pWidths; | |||
283 | ||||
284 | WW8TableCellGrid::Pointer_t pCellGrid = | |||
285 | mpParent->getParent()->getCellGridForTable(getTable(), false); | |||
286 | ||||
287 | if (!pCellGrid) | |||
288 | { | |||
289 | const SwTableBox * pTabBox = getTableBox(); | |||
290 | const SwTableLine * pTabLine = pTabBox->GetUpper(); | |||
291 | const SwTableBoxes & rTabBoxes = pTabLine->GetTabBoxes(); | |||
292 | ||||
293 | pWidths = std::make_shared<Widths>(); | |||
294 | // number of cell written | |||
295 | sal_uInt32 nBoxes = rTabBoxes.size(); | |||
296 | if (nBoxes > MAXTABLECELLS) | |||
297 | nBoxes = MAXTABLECELLS; | |||
298 | ||||
299 | for (sal_uInt32 n = 0; n < nBoxes; n++) | |||
300 | { | |||
301 | const SwFrameFormat* pBoxFormat = rTabBoxes[ n ]->GetFrameFormat(); | |||
302 | const SwFormatFrameSize& rLSz = pBoxFormat->GetFrameSize(); | |||
303 | ||||
304 | pWidths->push_back(rLSz.GetWidth()); | |||
305 | } | |||
306 | } | |||
307 | else | |||
308 | pWidths = pCellGrid->getWidthsOfRow(this); | |||
309 | ||||
310 | return pWidths; | |||
311 | } | |||
312 | ||||
313 | RowSpansPtr WW8TableNodeInfoInner::getRowSpansOfRow() const | |||
314 | { | |||
315 | RowSpansPtr pResult = std::make_shared<RowSpans>(); | |||
316 | ||||
317 | WW8TableCellGrid::Pointer_t pCellGrid = | |||
318 | mpParent->getParent()->getCellGridForTable(getTable(), false); | |||
319 | ||||
320 | if (!pCellGrid) | |||
321 | { | |||
322 | const SwTableBox * pTabBox = getTableBox(); | |||
323 | const SwTableLine * pTabLine = pTabBox->GetUpper(); | |||
324 | const SwTableBoxes & rTabBoxes = pTabLine->GetTabBoxes(); | |||
325 | ||||
326 | sal_uInt32 nBoxes = rTabBoxes.size(); | |||
327 | if (nBoxes > MAXTABLECELLS) | |||
328 | nBoxes = MAXTABLECELLS; | |||
329 | ||||
330 | for (sal_uInt32 n = 0; n < nBoxes; ++n) | |||
331 | { | |||
332 | pResult->push_back(rTabBoxes[n]->getRowSpan()); | |||
333 | } | |||
334 | } | |||
335 | else | |||
336 | pResult = pCellGrid->getRowSpansOfRow(this); | |||
337 | ||||
338 | return pResult; | |||
339 | } | |||
340 | ||||
341 | ||||
342 | #ifdef DBG_UTIL | |||
343 | std::string WW8TableNodeInfoInner::toString() const | |||
344 | { | |||
345 | static char buffer[256]; | |||
346 | snprintf(buffer, sizeof(buffer), | |||
347 | "<tableinner depth=\"%" SAL_PRIuUINT32"u" "\"" | |||
348 | " cell=\"%" SAL_PRIuUINT32"u" "\"" | |||
349 | " row=\"%" SAL_PRIuUINT32"u" "\"" | |||
350 | " endOfCell=\"%s\"" | |||
351 | " endOfLine=\"%s\"" | |||
352 | " shadowsBefore=\"%" SAL_PRIuUINT32"u" "\"" | |||
353 | " shadowsAfter=\"%" SAL_PRIuUINT32"u" "\"" | |||
354 | " vertMerge=\"%s\"/>", | |||
355 | mnDepth, mnCell, mnRow, | |||
356 | mbEndOfCell ? "yes" : "no", | |||
357 | mbEndOfLine ? "yes" : "no", | |||
358 | mnShadowsBefore, | |||
359 | mnShadowsAfter, | |||
360 | mbVertMerge ? "yes" : "no"); | |||
361 | ||||
362 | return std::string(buffer); | |||
363 | } | |||
364 | #endif | |||
365 | ||||
366 | WW8TableNodeInfo::WW8TableNodeInfo(WW8TableInfo * pParent, | |||
367 | const SwNode * pNode) | |||
368 | : mpParent(pParent), | |||
369 | mnDepth(0), | |||
370 | mpNode(pNode), | |||
371 | mpNext(nullptr), | |||
372 | mpNextNode(nullptr) | |||
373 | { | |||
374 | } | |||
375 | ||||
376 | WW8TableNodeInfo::~WW8TableNodeInfo() | |||
377 | { | |||
378 | } | |||
379 | ||||
380 | #ifdef DBG_UTIL | |||
381 | std::string WW8TableNodeInfo::toString() const | |||
382 | { | |||
383 | static char buffer[1024]; | |||
384 | snprintf(buffer, sizeof(buffer), | |||
385 | "<tableNodeInfo p=\"%p\" depth=\"%" SAL_PRIuUINT32"u" "\">" | |||
386 | ,this, getDepth()); | |||
387 | ||||
388 | std::string sResult(buffer); | |||
389 | ||||
390 | for (const auto& rInner : mInners) | |||
391 | { | |||
392 | WW8TableNodeInfoInner::Pointer_t pInner = rInner.second; | |||
393 | sResult += pInner->toString(); | |||
394 | } | |||
395 | sResult += dbg_out(*mpNode); | |||
396 | sResult += "</tableNodeInfo>"; | |||
397 | ||||
398 | return sResult; | |||
399 | } | |||
400 | #endif | |||
401 | ||||
402 | void WW8TableNodeInfo::setDepth(sal_uInt32 nDepth) | |||
403 | { | |||
404 | mnDepth = nDepth; | |||
405 | ||||
406 | Inners_t::iterator aIt = mInners.find(mnDepth); | |||
407 | ||||
408 | if (aIt == mInners.end()) | |||
409 | mInners[mnDepth] = std::make_shared<ww8::WW8TableNodeInfoInner>(this); | |||
410 | ||||
411 | mInners[mnDepth]->setDepth(mnDepth); | |||
412 | } | |||
413 | ||||
414 | void WW8TableNodeInfo::setEndOfLine(bool bEndOfLine) | |||
415 | { | |||
416 | WW8TableNodeInfoInner::Pointer_t pInner = getInnerForDepth(mnDepth); | |||
417 | pInner->setEndOfLine(bEndOfLine); | |||
418 | ||||
419 | #ifdef DBG_UTIL | |||
420 | SAL_INFO( "sw.ww8", "<endOfLine depth=\"" << mnDepth << "\">" << toString() << "</endOfLine>" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "<endOfLine depth=\"" << mnDepth << "\">" << toString() << "</endOfLine>") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "420" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<endOfLine depth=\"" << mnDepth << "\">" << toString() << "</endOfLine>" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<endOfLine depth=\"" << mnDepth << "\">" << toString() << "</endOfLine>"; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "420" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "<endOfLine depth=\"" << mnDepth << "\">" << toString() << "</endOfLine>") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8" ), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "420" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<endOfLine depth=\"" << mnDepth << "\">" << toString() << "</endOfLine>" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<endOfLine depth=\"" << mnDepth << "\">" << toString() << "</endOfLine>"; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "420" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
421 | #endif | |||
422 | } | |||
423 | ||||
424 | void WW8TableNodeInfo::setEndOfCell(bool bEndOfCell) | |||
425 | { | |||
426 | WW8TableNodeInfoInner::Pointer_t pInner = getInnerForDepth(mnDepth); | |||
427 | pInner->setEndOfCell(bEndOfCell); | |||
428 | ||||
429 | #ifdef DBG_UTIL | |||
430 | SAL_INFO( "sw.ww8", "<endOfCell depth=\"" << mnDepth << "\">" << toString() << "</endOfCell>" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "<endOfCell depth=\"" << mnDepth << "\">" << toString() << "</endOfCell>") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "430" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<endOfCell depth=\"" << mnDepth << "\">" << toString() << "</endOfCell>" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<endOfCell depth=\"" << mnDepth << "\">" << toString() << "</endOfCell>"; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "430" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "<endOfCell depth=\"" << mnDepth << "\">" << toString() << "</endOfCell>") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8" ), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "430" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<endOfCell depth=\"" << mnDepth << "\">" << toString() << "</endOfCell>" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<endOfCell depth=\"" << mnDepth << "\">" << toString() << "</endOfCell>"; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "430" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
431 | #endif | |||
432 | } | |||
433 | ||||
434 | void WW8TableNodeInfo::setFirstInTable(bool bFirstInTable) | |||
435 | { | |||
436 | WW8TableNodeInfoInner::Pointer_t pInner = getInnerForDepth(mnDepth); | |||
437 | ||||
438 | pInner->setFirstInTable(bFirstInTable); | |||
439 | ||||
440 | #ifdef DBG_UTIL | |||
441 | SAL_INFO( "sw.ww8", "<firstInTable depth=\"" << mnDepth << "\">" << toString() << "</firstInTable>" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "<firstInTable depth=\"" << mnDepth << "\">" << toString() << "</firstInTable>") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "441" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<firstInTable depth=\"" << mnDepth << "\">" << toString() << "</firstInTable>" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<firstInTable depth=\"" << mnDepth << "\">" << toString() << "</firstInTable>" ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8" ), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "441" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "<firstInTable depth=\"" << mnDepth << "\">" << toString() << "</firstInTable>" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8" ), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "441" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<firstInTable depth=\"" << mnDepth << "\">" << toString() << "</firstInTable>" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<firstInTable depth=\"" << mnDepth << "\">" << toString() << "</firstInTable>" ; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8" ), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "441" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
442 | #endif | |||
443 | } | |||
444 | ||||
445 | void WW8TableNodeInfo::setVertMerge(bool bVertMerge) | |||
446 | { | |||
447 | WW8TableNodeInfoInner::Pointer_t pInner = getInnerForDepth(mnDepth); | |||
448 | ||||
449 | pInner->setVertMerge(bVertMerge); | |||
450 | ||||
451 | #ifdef DBG_UTIL | |||
452 | SAL_INFO( "sw.ww8", "<vertMerge depth=\"" << mnDepth << "\">" << toString() << "</vertMerge>" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "<vertMerge depth=\"" << mnDepth << "\">" << toString() << "</vertMerge>") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "452" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<vertMerge depth=\"" << mnDepth << "\">" << toString() << "</vertMerge>" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<vertMerge depth=\"" << mnDepth << "\">" << toString() << "</vertMerge>"; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "452" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "<vertMerge depth=\"" << mnDepth << "\">" << toString() << "</vertMerge>") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8" ), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "452" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<vertMerge depth=\"" << mnDepth << "\">" << toString() << "</vertMerge>" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<vertMerge depth=\"" << mnDepth << "\">" << toString() << "</vertMerge>"; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "452" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
453 | #endif | |||
454 | } | |||
455 | ||||
456 | void WW8TableNodeInfo::setTableBox(const SwTableBox * pTableBox) | |||
457 | { | |||
458 | getInnerForDepth(mnDepth)->setTableBox(pTableBox); | |||
459 | } | |||
460 | ||||
461 | void WW8TableNodeInfo::setTable(const SwTable * pTable) | |||
462 | { | |||
463 | getInnerForDepth(mnDepth)->setTable(pTable); | |||
464 | } | |||
465 | ||||
466 | void WW8TableNodeInfo::setNext(WW8TableNodeInfo * pNext) | |||
467 | { | |||
468 | mpNext = pNext; | |||
469 | ||||
470 | #ifdef DBG_UTIL | |||
471 | SAL_INFO( "sw.ww8", "<setnext><from>" << toString() << "</from><to>" << pNext->toString() << "</to></setnext>" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "<setnext><from>" << toString() << "</from><to>" << pNext->toString() << "</to></setnext>") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8" ), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "471" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<setnext><from>" << toString() << "</from><to>" << pNext ->toString() << "</to></setnext>"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<setnext><from>" << toString() << "</from><to>" << pNext->toString() << "</to></setnext>"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "471" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "<setnext><from>" << toString() << "</from><to>" << pNext->toString () << "</to></setnext>") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "471" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<setnext><from>" << toString() << "</from><to>" << pNext ->toString() << "</to></setnext>"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<setnext><from>" << toString() << "</from><to>" << pNext->toString() << "</to></setnext>"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "471" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
472 | #endif | |||
473 | } | |||
474 | ||||
475 | void WW8TableNodeInfo::setNextNode(const SwNode * pNode) | |||
476 | { | |||
477 | mpNextNode = pNode; | |||
478 | } | |||
479 | ||||
480 | void WW8TableNodeInfo::setRect(const SwRect & rRect) | |||
481 | { | |||
482 | getInnerForDepth(mnDepth)->setRect(rRect); | |||
483 | } | |||
484 | ||||
485 | void WW8TableNodeInfo::setCell(sal_uInt32 nCell) | |||
486 | { | |||
487 | getInnerForDepth(mnDepth)->setCell(nCell); | |||
488 | } | |||
489 | ||||
490 | void WW8TableNodeInfo::setRow(sal_uInt32 nRow) | |||
491 | { | |||
492 | getInnerForDepth(mnDepth)->setRow(nRow); | |||
493 | } | |||
494 | ||||
495 | void WW8TableNodeInfo::setShadowsBefore(sal_uInt32 nShadowsBefore) | |||
496 | { | |||
497 | getInnerForDepth(mnDepth)->setShadowsBefore(nShadowsBefore); | |||
498 | } | |||
499 | ||||
500 | void WW8TableNodeInfo::setShadowsAfter(sal_uInt32 nShadowsAfter) | |||
501 | { | |||
502 | getInnerForDepth(mnDepth)->setShadowsAfter(nShadowsAfter); | |||
503 | } | |||
504 | ||||
505 | ||||
506 | sal_uInt32 WW8TableNodeInfo::getDepth() const | |||
507 | { | |||
508 | if (!mInners.empty()) | |||
509 | return mInners.begin()->second->getDepth(); | |||
510 | ||||
511 | return mnDepth; | |||
512 | } | |||
513 | ||||
514 | ||||
515 | const SwTableBox * WW8TableNodeInfo::getTableBox() const | |||
516 | { | |||
517 | return getInnerForDepth(mnDepth)->getTableBox(); | |||
518 | } | |||
519 | ||||
520 | sal_uInt32 WW8TableNodeInfo::getCell() const | |||
521 | { | |||
522 | return getInnerForDepth(mnDepth)->getCell(); | |||
523 | } | |||
524 | ||||
525 | sal_uInt32 WW8TableNodeInfo::getRow() const | |||
526 | { | |||
527 | return getInnerForDepth(mnDepth)->getRow(); | |||
528 | } | |||
529 | ||||
530 | WW8TableNodeInfoInner::Pointer_t WW8TableNodeInfo::getFirstInner() const | |||
531 | { | |||
532 | WW8TableNodeInfoInner::Pointer_t pResult; | |||
533 | ||||
534 | if (!mInners.empty()) | |||
535 | pResult = mInners.begin()->second; | |||
536 | ||||
537 | return pResult; | |||
538 | } | |||
539 | ||||
540 | WW8TableNodeInfoInner::Pointer_t WW8TableNodeInfo::getInnerForDepth(sal_uInt32 nDepth) const | |||
541 | { | |||
542 | WW8TableNodeInfoInner::Pointer_t pResult; | |||
543 | ||||
544 | Inners_t::const_iterator aIt = mInners.find(nDepth); | |||
545 | if (aIt != mInners.end()) | |||
546 | { | |||
547 | pResult = aIt->second; | |||
548 | } | |||
549 | ||||
550 | return pResult; | |||
551 | } | |||
552 | ||||
553 | WW8TableInfo::WW8TableInfo() | |||
554 | { | |||
555 | } | |||
556 | ||||
557 | WW8TableInfo::~WW8TableInfo() | |||
558 | { | |||
559 | } | |||
560 | ||||
561 | WW8TableNodeInfo * | |||
562 | WW8TableInfo::processSwTableByLayout(const SwTable * pTable, RowEndInners_t &rLastRowEnds) | |||
563 | { | |||
564 | SwTableCellInfo aTableCellInfo(pTable); | |||
565 | ||||
566 | while (aTableCellInfo.getNext()) | |||
567 | { | |||
568 | SwRect aRect = aTableCellInfo.getRect(); | |||
569 | ||||
570 | SAL_INFO( "sw.ww8", "<CellFrame>" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "<CellFrame>") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8" ), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "570" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<CellFrame>"), 0); } else { ::std ::ostringstream sal_detail_stream; sal_detail_stream << "<CellFrame>"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "570" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "<CellFrame>") == 1) { ::sal_detail_log( (:: SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "570" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<CellFrame>"), 0); } else { ::std ::ostringstream sal_detail_stream; sal_detail_stream << "<CellFrame>"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "570" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
571 | SAL_INFO( "sw.ww8", "<rect top=\"" << aRect.Top() << "\" bottom=\"" << aRect.Bottom()do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "<rect top=\"" << aRect.Top() << "\" bottom=\"" << aRect.Bottom() << "\" left=\"" << aRect.Left() << "\" right=\"" << aRect.Right() << "\"/>") == 1) { ::sal_detail_log( ( ::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "572" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<rect top=\"" << aRect.Top() << "\" bottom=\"" << aRect.Bottom() << "\" left=\"" << aRect.Left() << "\" right=\"" << aRect. Right() << "\"/>"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<rect top=\"" << aRect.Top() << "\" bottom=\"" << aRect. Bottom() << "\" left=\"" << aRect.Left() << "\" right=\"" << aRect.Right() << "\"/>"; ::sal ::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "572" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "<rect top=\"" << aRect.Top() << "\" bottom=\"" << aRect.Bottom() << "\" left=\"" << aRect .Left() << "\" right=\"" << aRect.Right() << "\"/>") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "572" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<rect top=\"" << aRect.Top() << "\" bottom=\"" << aRect.Bottom() << "\" left=\"" << aRect.Left() << "\" right=\"" << aRect. Right() << "\"/>"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<rect top=\"" << aRect.Top() << "\" bottom=\"" << aRect. Bottom() << "\" left=\"" << aRect.Left() << "\" right=\"" << aRect.Right() << "\"/>"; ::sal ::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "572" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false) | |||
572 | << "\" left=\"" << aRect.Left() << "\" right=\"" << aRect.Right() << "\"/>" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "<rect top=\"" << aRect.Top() << "\" bottom=\"" << aRect.Bottom() << "\" left=\"" << aRect.Left() << "\" right=\"" << aRect.Right() << "\"/>") == 1) { ::sal_detail_log( ( ::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "572" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<rect top=\"" << aRect.Top() << "\" bottom=\"" << aRect.Bottom() << "\" left=\"" << aRect.Left() << "\" right=\"" << aRect. Right() << "\"/>"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<rect top=\"" << aRect.Top() << "\" bottom=\"" << aRect. Bottom() << "\" left=\"" << aRect.Left() << "\" right=\"" << aRect.Right() << "\"/>"; ::sal ::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "572" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "<rect top=\"" << aRect.Top() << "\" bottom=\"" << aRect.Bottom() << "\" left=\"" << aRect .Left() << "\" right=\"" << aRect.Right() << "\"/>") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "572" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<rect top=\"" << aRect.Top() << "\" bottom=\"" << aRect.Bottom() << "\" left=\"" << aRect.Left() << "\" right=\"" << aRect. Right() << "\"/>"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<rect top=\"" << aRect.Top() << "\" bottom=\"" << aRect. Bottom() << "\" left=\"" << aRect.Left() << "\" right=\"" << aRect.Right() << "\"/>"; ::sal ::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "572" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
573 | const SwTableBox * pTableBox = aTableCellInfo.getTableBox(); | |||
574 | const SwStartNode * pSttNd = pTableBox->GetSttNd(); | |||
575 | ||||
576 | if (pSttNd != nullptr) | |||
577 | { | |||
578 | SwPaM aPam(*pSttNd, 0); | |||
579 | ||||
580 | bool bDone = false; | |||
581 | do | |||
582 | { | |||
583 | SwNode & rNode = aPam.GetPoint()->nNode.GetNode(); | |||
584 | ||||
585 | insertTableNodeInfo(&rNode, pTable, pTableBox, 0, 0, 1, & aRect); | |||
586 | ||||
587 | if (rNode.IsEndNode()) | |||
588 | { | |||
589 | SwEndNode * pEndNode = rNode.GetEndNode(); | |||
590 | SwStartNode * pTmpSttNd = pEndNode->StartOfSectionNode(); | |||
591 | ||||
592 | if (pTmpSttNd == pSttNd) | |||
593 | bDone = true; | |||
594 | } | |||
595 | ||||
596 | aPam.GetPoint()->nNode++; | |||
597 | } | |||
598 | while (!bDone); | |||
599 | } | |||
600 | ||||
601 | SAL_INFO( "sw.ww8", "</CellFrame>" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "</CellFrame>") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8" ), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "601" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "</CellFrame>"), 0); } else { :: std::ostringstream sal_detail_stream; sal_detail_stream << "</CellFrame>"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "601" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "</CellFrame>") == 1) { ::sal_detail_log( ( ::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "601" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "</CellFrame>"), 0); } else { :: std::ostringstream sal_detail_stream; sal_detail_stream << "</CellFrame>"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "601" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
602 | } | |||
603 | ||||
604 | return reorderByLayout(pTable, rLastRowEnds); | |||
605 | } | |||
606 | ||||
607 | void WW8TableInfo::processSwTable(const SwTable * pTable) | |||
608 | { | |||
609 | SAL_INFO( "sw.ww8", "<processSwTable>" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "<processSwTable>" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8" ), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "609" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<processSwTable>"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<processSwTable>"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "609" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "<processSwTable>") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "609" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<processSwTable>"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<processSwTable>"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "609" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
| ||||
610 | ||||
611 | WW8TableNodeInfo * pPrev = nullptr; | |||
612 | RowEndInners_t aLastRowEnds; | |||
613 | ||||
614 | if (pTable->IsTableComplex() && pTable->HasLayout()) | |||
615 | { | |||
616 | pPrev = processSwTableByLayout(pTable, aLastRowEnds); | |||
617 | #ifdef DBG_UTIL | |||
618 | SAL_INFO( "sw.ww8", getCellGridForTable(pTable)->toString())do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << getCellGridForTable(pTable )->toString()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "618" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << getCellGridForTable(pTable)->toString ()), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << getCellGridForTable(pTable)->toString(); ::sal:: detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "618" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << getCellGridForTable(pTable)->toString()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8" ), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "618" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << getCellGridForTable(pTable)->toString ()), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << getCellGridForTable(pTable)->toString(); ::sal:: detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "618" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
619 | #endif | |||
620 | } | |||
621 | else | |||
622 | { | |||
623 | const SwTableLines & rLines = pTable->GetTabLines(); | |||
624 | ||||
625 | for (size_t n = 0; n < rLines.size(); ++n) | |||
626 | { | |||
627 | const SwTableLine * pLine = rLines[n]; | |||
628 | ||||
629 | pPrev = processTableLine(pTable, pLine, static_cast<sal_uInt32>(n), 1, pPrev, aLastRowEnds); | |||
630 | } | |||
631 | ||||
632 | } | |||
633 | ||||
634 | if (pPrev) | |||
635 | { | |||
636 | SwTableNode * pTableNode = pTable->GetTableNode(); | |||
637 | SwEndNode * pEndNode = pTableNode->EndOfSectionNode(); | |||
638 | pPrev->setNextNode(pEndNode); | |||
639 | assert(!aLastRowEnds.empty())(static_cast <bool> (!aLastRowEnds.empty()) ? void (0) : __assert_fail ("!aLastRowEnds.empty()", "/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" , 639, __extension__ __PRETTY_FUNCTION__)); | |||
640 | for (auto &a : aLastRowEnds) | |||
641 | { | |||
642 | assert(a.second->isEndOfLine())(static_cast <bool> (a.second->isEndOfLine()) ? void (0) : __assert_fail ("a.second->isEndOfLine()", "/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" , 642, __extension__ __PRETTY_FUNCTION__)); | |||
643 | a.second->setFinalEndOfLine(true); | |||
644 | } | |||
645 | } | |||
646 | SAL_INFO( "sw.ww8", "</processSwTable>" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "</processSwTable>" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8" ), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "646" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "</processSwTable>"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "</processSwTable>"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "646" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "</processSwTable>") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "646" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "</processSwTable>"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "</processSwTable>"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "646" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
647 | } | |||
648 | ||||
649 | WW8TableNodeInfo * | |||
650 | WW8TableInfo::processTableLine(const SwTable * pTable, | |||
651 | const SwTableLine * pTableLine, | |||
652 | sal_uInt32 nRow, | |||
653 | sal_uInt32 nDepth, | |||
654 | WW8TableNodeInfo * pPrev, | |||
655 | RowEndInners_t &rLastRowEnds) | |||
656 | { | |||
657 | SAL_INFO( "sw.ww8", "<processTableLine row=\"" << nRow << "\" depth=\"" << nDepth << "\">" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "<processTableLine row=\"" << nRow << "\" depth=\"" << nDepth << "\">") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "657" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<processTableLine row=\"" << nRow << "\" depth=\"" << nDepth << "\">" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<processTableLine row=\"" << nRow << "\" depth=\"" << nDepth << "\">"; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "657" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "<processTableLine row=\"" << nRow << "\" depth=\"" << nDepth << "\">") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "657" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<processTableLine row=\"" << nRow << "\" depth=\"" << nDepth << "\">" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<processTableLine row=\"" << nRow << "\" depth=\"" << nDepth << "\">"; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "657" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
658 | ||||
659 | const SwTableBoxes & rBoxes = pTableLine->GetTabBoxes(); | |||
660 | ||||
661 | for (size_t n = 0; n < rBoxes.size(); ++n) | |||
662 | { | |||
663 | const SwTableBox * pBox = rBoxes[n]; | |||
664 | ||||
665 | pPrev = processTableBox(pTable, pBox, nRow, static_cast<sal_uInt32>(n), nDepth, n == rBoxes.size() - 1, pPrev, rLastRowEnds); | |||
666 | } | |||
667 | ||||
668 | SAL_INFO( "sw.ww8", "</processTableLine>" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "</processTableLine>" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8" ), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "668" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "</processTableLine>"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "</processTableLine>"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "668" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "</processTableLine>") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "668" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "</processTableLine>"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "</processTableLine>"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "668" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
669 | ||||
670 | return pPrev; | |||
671 | } | |||
672 | ||||
673 | WW8TableNodeInfo::Pointer_t | |||
674 | WW8TableInfo::processTableBoxLines(const SwTableBox * pBox, | |||
675 | const SwTable * pTable, | |||
676 | const SwTableBox * pBoxToSet, | |||
677 | sal_uInt32 nRow, | |||
678 | sal_uInt32 nCell, | |||
679 | sal_uInt32 nDepth) | |||
680 | { | |||
681 | SAL_INFO( "sw.ww8", "<processTableBoxLines depth=\"" << nDepth << "\" row=\"" << nRowdo { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "<processTableBoxLines depth=\"" << nDepth << "\" row=\"" << nRow << "\" cell=\"" << nCell << "\">") == 1) { ::sal_detail_log( ( ::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "682" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<processTableBoxLines depth=\"" << nDepth << "\" row=\"" << nRow << "\" cell=\"" << nCell << "\">"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<processTableBoxLines depth=\"" << nDepth << "\" row=\"" << nRow << "\" cell=\"" << nCell << "\">"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "682" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "<processTableBoxLines depth=\"" << nDepth << "\" row=\"" << nRow << "\" cell=\"" << nCell << "\">") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "682" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<processTableBoxLines depth=\"" << nDepth << "\" row=\"" << nRow << "\" cell=\"" << nCell << "\">"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<processTableBoxLines depth=\"" << nDepth << "\" row=\"" << nRow << "\" cell=\"" << nCell << "\">"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "682" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false) | |||
682 | << "\" cell=\"" << nCell << "\">" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "<processTableBoxLines depth=\"" << nDepth << "\" row=\"" << nRow << "\" cell=\"" << nCell << "\">") == 1) { ::sal_detail_log( ( ::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "682" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<processTableBoxLines depth=\"" << nDepth << "\" row=\"" << nRow << "\" cell=\"" << nCell << "\">"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<processTableBoxLines depth=\"" << nDepth << "\" row=\"" << nRow << "\" cell=\"" << nCell << "\">"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "682" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "<processTableBoxLines depth=\"" << nDepth << "\" row=\"" << nRow << "\" cell=\"" << nCell << "\">") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "682" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<processTableBoxLines depth=\"" << nDepth << "\" row=\"" << nRow << "\" cell=\"" << nCell << "\">"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<processTableBoxLines depth=\"" << nDepth << "\" row=\"" << nRow << "\" cell=\"" << nCell << "\">"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "682" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
683 | ||||
684 | const SwTableLines & rLines = pBox->GetTabLines(); | |||
685 | WW8TableNodeInfo::Pointer_t pNodeInfo; | |||
686 | ||||
687 | if (!rLines.empty()) | |||
688 | { | |||
689 | for (size_t n = 0; n < rLines.size(); ++n) | |||
690 | { | |||
691 | const SwTableLine * pLine = rLines[n]; | |||
692 | const SwTableBoxes & rBoxes = pLine->GetTabBoxes(); | |||
693 | ||||
694 | for (size_t nBox = 0; nBox < rBoxes.size(); ++nBox) | |||
695 | pNodeInfo = processTableBoxLines(rBoxes[nBox], pTable, pBoxToSet, nRow, nCell, nDepth); | |||
696 | } | |||
697 | } | |||
698 | else | |||
699 | { | |||
700 | const SwStartNode * pSttNd = pBox->GetSttNd(); | |||
701 | const SwEndNode * pEndNd = pSttNd->EndOfSectionNode(); | |||
702 | SwPaM aPaM(*pSttNd, 0); | |||
703 | SwPaM aEndPaM(*pEndNd, 0); | |||
704 | ||||
705 | bool bDone = false; | |||
706 | while (!bDone) | |||
707 | { | |||
708 | SwNode & rNode = aPaM.GetPoint()->nNode.GetNode(); | |||
709 | ||||
710 | pNodeInfo = insertTableNodeInfo(&rNode, pTable, pBoxToSet, nRow, nCell, nDepth); | |||
711 | ||||
712 | if (aPaM.GetPoint()->nNode == aEndPaM.GetPoint()->nNode) | |||
713 | bDone = true; | |||
714 | else | |||
715 | aPaM.GetPoint()->nNode++; | |||
716 | } | |||
717 | } | |||
718 | ||||
719 | SAL_INFO( "sw.ww8", "</processTableBoxLines>" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "</processTableBoxLines>" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8" ), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "719" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "</processTableBoxLines>"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "</processTableBoxLines>"; ::sal::detail::log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "719" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "</processTableBoxLines>") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "719" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "</processTableBoxLines>"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "</processTableBoxLines>"; ::sal::detail::log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "719" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
720 | ||||
721 | return pNodeInfo; | |||
722 | } | |||
723 | ||||
724 | static void updateFinalEndOfLine(RowEndInners_t &rLastRowEnds, WW8TableNodeInfo const * pEndOfCellInfo) | |||
725 | { | |||
726 | sal_Int32 nDepth = pEndOfCellInfo->getDepth(); | |||
727 | WW8TableNodeInfoInner::Pointer_t pInner = pEndOfCellInfo->getInnerForDepth(nDepth); | |||
728 | ||||
729 | auto aIt = rLastRowEnds.find(nDepth); | |||
730 | if (aIt == rLastRowEnds.end() || (pInner->getRow() > aIt->second->getRow())) | |||
731 | rLastRowEnds[nDepth] = pInner.get(); | |||
732 | } | |||
733 | ||||
734 | WW8TableNodeInfo * | |||
735 | WW8TableInfo::processTableBox(const SwTable * pTable, | |||
736 | const SwTableBox * pBox, | |||
737 | sal_uInt32 nRow, | |||
738 | sal_uInt32 nCell, | |||
739 | sal_uInt32 nDepth, | |||
740 | bool bEndOfLine, | |||
741 | WW8TableNodeInfo * pPrev, | |||
742 | RowEndInners_t &rLastRowEnds) | |||
743 | { | |||
744 | SAL_INFO( "sw.ww8", "<processTableBox row=\"" << nRow << "\" cell=\"" << nCelldo { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "<processTableBox row=\"" << nRow << "\" cell=\"" << nCell << "\" depth=\"" << nDepth << "\">") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "745" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<processTableBox row=\"" << nRow << "\" cell=\"" << nCell << "\" depth=\"" << nDepth << "\">"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<processTableBox row=\"" << nRow << "\" cell=\"" << nCell << "\" depth=\"" << nDepth << "\">"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "745" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "<processTableBox row=\"" << nRow << "\" cell=\"" << nCell << "\" depth=\"" << nDepth << "\">") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "745" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<processTableBox row=\"" << nRow << "\" cell=\"" << nCell << "\" depth=\"" << nDepth << "\">"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<processTableBox row=\"" << nRow << "\" cell=\"" << nCell << "\" depth=\"" << nDepth << "\">"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "745" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false) | |||
745 | << "\" depth=\"" << nDepth << "\">" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "<processTableBox row=\"" << nRow << "\" cell=\"" << nCell << "\" depth=\"" << nDepth << "\">") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "745" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<processTableBox row=\"" << nRow << "\" cell=\"" << nCell << "\" depth=\"" << nDepth << "\">"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<processTableBox row=\"" << nRow << "\" cell=\"" << nCell << "\" depth=\"" << nDepth << "\">"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "745" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "<processTableBox row=\"" << nRow << "\" cell=\"" << nCell << "\" depth=\"" << nDepth << "\">") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "745" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "<processTableBox row=\"" << nRow << "\" cell=\"" << nCell << "\" depth=\"" << nDepth << "\">"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<processTableBox row=\"" << nRow << "\" cell=\"" << nCell << "\" depth=\"" << nDepth << "\">"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "745" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
746 | ||||
747 | WW8TableNodeInfo::Pointer_t pNodeInfo; | |||
748 | const SwTableLines & rLines = pBox->GetTabLines(); | |||
749 | const SwStartNode * pSttNd = pBox->GetSttNd(); | |||
750 | WW8TableNodeInfo::Pointer_t pEndOfCellInfo; | |||
751 | ||||
752 | if (!rLines.empty()) | |||
753 | { | |||
754 | pNodeInfo = processTableBoxLines(pBox, pTable, pBox, nRow, nCell, nDepth); | |||
755 | pNodeInfo->setEndOfCell(true); | |||
756 | if (bEndOfLine) | |||
757 | { | |||
758 | pNodeInfo->setEndOfLine(true); | |||
759 | updateFinalEndOfLine(rLastRowEnds, pNodeInfo.get()); | |||
760 | } | |||
761 | ||||
762 | for (size_t n = 0; n < rLines.size(); n++) | |||
763 | { | |||
764 | const SwTableLine * pLine = rLines[n]; | |||
765 | ||||
766 | pPrev = processTableLine(pTable, pLine, n, 1, pPrev, rLastRowEnds); | |||
767 | } | |||
768 | } | |||
769 | else | |||
770 | { | |||
771 | SwPaM aPaM(*pSttNd, 0); | |||
772 | ||||
773 | bool bDone = false; | |||
774 | sal_uInt32 nDepthInsideCell = 0; | |||
775 | ||||
776 | do | |||
777 | { | |||
778 | SwNode & rNode = aPaM.GetPoint()->nNode.GetNode(); | |||
779 | ||||
780 | if (rNode.IsStartNode()) | |||
781 | { | |||
782 | if (nDepthInsideCell > 0) | |||
783 | pEndOfCellInfo.reset(); | |||
784 | ||||
785 | nDepthInsideCell++; | |||
786 | } | |||
787 | ||||
788 | pNodeInfo = insertTableNodeInfo(&rNode, pTable, pBox, nRow, nCell, nDepth); | |||
789 | ||||
790 | if (pPrev) | |||
791 | pPrev->setNext(pNodeInfo.get()); | |||
792 | ||||
793 | pPrev = pNodeInfo.get(); | |||
794 | ||||
795 | if (nDepthInsideCell == 1 && rNode.IsTextNode()) | |||
796 | pEndOfCellInfo = pNodeInfo; | |||
797 | ||||
798 | if (rNode.IsEndNode()) | |||
799 | { | |||
800 | nDepthInsideCell--; | |||
801 | ||||
802 | if (nDepthInsideCell == 0 && !pEndOfCellInfo) | |||
803 | pEndOfCellInfo = pNodeInfo; | |||
804 | ||||
805 | SwEndNode * pEndNode = rNode.GetEndNode( ); | |||
806 | SwStartNode * pTmpSttNd = pEndNode->StartOfSectionNode(); | |||
807 | if (pTmpSttNd == pSttNd) | |||
808 | bDone = true; | |||
809 | } | |||
810 | ||||
811 | aPaM.GetPoint()->nNode++; | |||
812 | } | |||
813 | while (!bDone); | |||
814 | ||||
815 | if (pEndOfCellInfo) | |||
816 | { | |||
817 | pEndOfCellInfo->setEndOfCell(true); | |||
818 | ||||
819 | if (bEndOfLine) | |||
820 | { | |||
821 | pEndOfCellInfo->setEndOfLine(true); | |||
822 | updateFinalEndOfLine(rLastRowEnds, pEndOfCellInfo.get()); | |||
823 | } | |||
824 | } | |||
825 | } | |||
826 | ||||
827 | SAL_INFO( "sw.ww8", "</processTableBox>" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "</processTableBox>" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8" ), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "827" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "</processTableBox>"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "</processTableBox>"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "827" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "</processTableBox>") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "827" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "</processTableBox>"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "</processTableBox>"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "827" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
828 | ||||
829 | return pPrev; | |||
830 | } | |||
831 | ||||
832 | WW8TableNodeInfo::Pointer_t WW8TableInfo::insertTableNodeInfo | |||
833 | (const SwNode * pNode, | |||
834 | const SwTable * pTable, | |||
835 | const SwTableBox * pTableBox, | |||
836 | sal_uInt32 nRow, | |||
837 | sal_uInt32 nCell, | |||
838 | sal_uInt32 nDepth, | |||
839 | SwRect const * pRect) | |||
840 | { | |||
841 | WW8TableNodeInfo::Pointer_t pNodeInfo = getTableNodeInfo(pNode); | |||
842 | ||||
843 | if (!pNodeInfo) | |||
844 | { | |||
845 | pNodeInfo = | |||
846 | std::make_shared<ww8::WW8TableNodeInfo>(this, pNode); | |||
847 | mMap.emplace(pNode, pNodeInfo); | |||
848 | } | |||
849 | ||||
850 | pNodeInfo->setDepth(nDepth + pNodeInfo->getDepth()); | |||
851 | ||||
852 | pNodeInfo->setTable(pTable); | |||
853 | pNodeInfo->setTableBox(pTableBox); | |||
854 | ||||
855 | pNodeInfo->setCell(nCell); | |||
856 | pNodeInfo->setRow(nRow); | |||
857 | ||||
858 | if (pNode->IsTextNode()) | |||
859 | { | |||
860 | FirstInTableMap_t::const_iterator aIt = mFirstInTableMap.find(pTable); | |||
861 | if (aIt == mFirstInTableMap.end()) | |||
862 | { | |||
863 | mFirstInTableMap[pTable] = pNode; | |||
864 | pNodeInfo->setFirstInTable(true); | |||
865 | } | |||
866 | } | |||
867 | ||||
868 | if (pRect) | |||
869 | { | |||
870 | WW8TableCellGrid::Pointer_t pCellGrid = getCellGridForTable(pTable); | |||
871 | ||||
872 | pCellGrid->insert(*pRect, pNodeInfo.get()); | |||
873 | pNodeInfo->setRect(*pRect); | |||
874 | } | |||
875 | ||||
876 | #ifdef DBG_UTIL | |||
877 | SAL_INFO( "sw.ww8", pNodeInfo->toString())do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << pNodeInfo->toString ()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ( "sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "877" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << pNodeInfo->toString()), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << pNodeInfo->toString(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "877" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << pNodeInfo->toString()) == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "877" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << pNodeInfo->toString()), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << pNodeInfo->toString(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "877" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
878 | #endif | |||
879 | return pNodeInfo; | |||
880 | } | |||
881 | ||||
882 | WW8TableCellGrid::Pointer_t WW8TableInfo::getCellGridForTable | |||
883 | (const SwTable * pTable, bool bCreate) | |||
884 | { | |||
885 | WW8TableCellGrid::Pointer_t pResult; | |||
886 | CellGridMap_t::iterator aIt = mCellGridMap.find(pTable); | |||
887 | ||||
888 | if (aIt == mCellGridMap.end()) | |||
889 | { | |||
890 | if (bCreate) | |||
891 | { | |||
892 | pResult = std::make_shared<ww8::WW8TableCellGrid>(); | |||
893 | mCellGridMap[pTable] = pResult; | |||
894 | } | |||
895 | } | |||
896 | else | |||
897 | pResult = mCellGridMap[pTable]; | |||
898 | ||||
899 | return pResult; | |||
900 | } | |||
901 | ||||
902 | WW8TableNodeInfo::Pointer_t WW8TableInfo::getTableNodeInfo | |||
903 | (const SwNode * pNode) | |||
904 | { | |||
905 | WW8TableNodeInfo::Pointer_t pResult; | |||
906 | Map_t::iterator aIt = mMap.find(pNode); | |||
907 | ||||
908 | if (aIt != mMap.end()) | |||
909 | pResult = (*aIt).second; | |||
910 | ||||
911 | return pResult; | |||
912 | } | |||
913 | ||||
914 | const SwNode * WW8TableInfo::getNextNode(const SwNode * pNode) | |||
915 | { | |||
916 | const SwNode * pResult = nullptr; | |||
917 | ||||
918 | WW8TableNodeInfo::Pointer_t pNodeInfo = getTableNodeInfo(pNode); | |||
919 | ||||
920 | if (pNodeInfo) | |||
921 | { | |||
922 | WW8TableNodeInfo * pNextInfo = pNodeInfo->getNext(); | |||
923 | ||||
924 | if (pNextInfo != nullptr) | |||
925 | pResult = pNextInfo->getNode(); | |||
926 | else | |||
927 | { | |||
928 | const SwNode * pNextNode = pNodeInfo->getNextNode(); | |||
929 | ||||
930 | if (pNextNode != nullptr) | |||
931 | pResult = pNextNode; | |||
932 | } | |||
933 | } | |||
934 | ||||
935 | return pResult; | |||
936 | } | |||
937 | ||||
938 | bool WW8TableNodeInfo::operator < (const WW8TableNodeInfo & rInfo) const | |||
939 | { | |||
940 | bool bRet = false; | |||
941 | ||||
942 | if (rInfo.mpNode != nullptr) | |||
943 | { | |||
944 | if (mpNode == nullptr) | |||
945 | { | |||
946 | bRet = true; | |||
947 | } | |||
948 | else | |||
949 | { | |||
950 | if (mpNode->GetIndex() < rInfo.mpNode->GetIndex()) | |||
951 | bRet = true; | |||
952 | } | |||
953 | } | |||
954 | ||||
955 | return bRet; | |||
956 | } | |||
957 | ||||
958 | bool CellInfo::operator < (const CellInfo & aCellInfo) const | |||
959 | { | |||
960 | bool aRet = false; | |||
961 | ||||
962 | if (top() < aCellInfo.top()) | |||
963 | aRet = true; | |||
964 | else if (top() == aCellInfo.top()) | |||
965 | { | |||
966 | if (left() < aCellInfo.left()) | |||
967 | aRet = true; | |||
968 | else if (left() == aCellInfo.left()) | |||
969 | { | |||
970 | if (width() < aCellInfo.width()) | |||
971 | aRet = true; | |||
972 | else if (width() == aCellInfo.width()) | |||
973 | { | |||
974 | if (height() < aCellInfo.height()) | |||
975 | aRet = true; | |||
976 | else if (height() == aCellInfo.height()) | |||
977 | { | |||
978 | if (aCellInfo.getTableNodeInfo()) | |||
979 | { | |||
980 | if (m_pNodeInfo == nullptr) | |||
981 | aRet = true; | |||
982 | else | |||
983 | { | |||
984 | aRet = *m_pNodeInfo < *aCellInfo.getTableNodeInfo(); | |||
985 | } | |||
986 | } | |||
987 | } | |||
988 | } | |||
989 | } | |||
990 | } | |||
991 | ||||
992 | return aRet; | |||
993 | } | |||
994 | ||||
995 | #ifdef DBG_UTIL | |||
996 | std::string CellInfo::toString() const | |||
997 | { | |||
998 | static char sBuffer[256]; | |||
999 | ||||
1000 | snprintf(sBuffer, sizeof(sBuffer), | |||
1001 | "<cellinfo left=\"%ld\"" | |||
1002 | " right=\"%ld\"" | |||
1003 | " top=\"%ld\"" | |||
1004 | " bottom=\"%ld\"" | |||
1005 | " node=\"%p\"/>", | |||
1006 | left(), | |||
1007 | right(), | |||
1008 | top(), | |||
1009 | bottom(), | |||
1010 | m_pNodeInfo); | |||
1011 | ||||
1012 | return sBuffer; | |||
1013 | } | |||
1014 | #endif | |||
1015 | ||||
1016 | WW8TableNodeInfo * WW8TableInfo::reorderByLayout(const SwTable * pTable, RowEndInners_t &rLastRowEnds) | |||
1017 | { | |||
1018 | WW8TableCellGrid::Pointer_t pCellGrid = getCellGridForTable(pTable); | |||
1019 | ||||
1020 | #ifdef DBG_UTIL | |||
1021 | SAL_INFO( "sw.ww8", pCellGrid->toString())do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << pCellGrid->toString ()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ( "sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "1021" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << pCellGrid->toString()), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << pCellGrid->toString(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "1021" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << pCellGrid->toString()) == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "1021" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << pCellGrid->toString()), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << pCellGrid->toString(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "1021" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1022 | #endif | |||
1023 | ||||
1024 | pCellGrid->addShadowCells(); | |||
1025 | return pCellGrid->connectCells(rLastRowEnds); | |||
1026 | } | |||
1027 | ||||
1028 | WW8TableCellGrid::WW8TableCellGrid() | |||
1029 | { | |||
1030 | } | |||
1031 | ||||
1032 | WW8TableCellGrid::~WW8TableCellGrid() | |||
1033 | { | |||
1034 | } | |||
1035 | ||||
1036 | WW8TableCellGridRow::Pointer_t WW8TableCellGrid::getRow(long nTop, bool bCreate) | |||
1037 | { | |||
1038 | WW8TableCellGridRow::Pointer_t pResult; | |||
1039 | ||||
1040 | RowTops_t::iterator aIt = m_aRowTops.find(nTop); | |||
1041 | ||||
1042 | if (aIt == m_aRowTops.end()) | |||
1043 | { | |||
1044 | if (bCreate) | |||
1045 | { | |||
1046 | pResult = std::make_shared<ww8::WW8TableCellGridRow>(); | |||
1047 | m_aRows[nTop] = pResult; | |||
1048 | m_aRowTops.insert(nTop); | |||
1049 | } | |||
1050 | } | |||
1051 | else | |||
1052 | pResult = m_aRows[nTop]; | |||
1053 | ||||
1054 | return pResult; | |||
1055 | } | |||
1056 | ||||
1057 | WW8TableCellGrid::RowTops_t::const_iterator WW8TableCellGrid::getRowTopsBegin() const | |||
1058 | { | |||
1059 | return m_aRowTops.begin(); | |||
1060 | } | |||
1061 | ||||
1062 | WW8TableCellGrid::RowTops_t::const_iterator WW8TableCellGrid::getRowTopsEnd() const | |||
1063 | { | |||
1064 | return m_aRowTops.end(); | |||
1065 | } | |||
1066 | ||||
1067 | CellInfoMultiSet::const_iterator WW8TableCellGrid::getCellsBegin(long nTop) | |||
1068 | { | |||
1069 | return getRow(nTop)->begin(); | |||
1070 | } | |||
1071 | ||||
1072 | CellInfoMultiSet::const_iterator WW8TableCellGrid::getCellsEnd(long nTop) | |||
1073 | { | |||
1074 | return getRow(nTop)->end(); | |||
1075 | } | |||
1076 | ||||
1077 | void WW8TableCellGrid::insert(const SwRect & rRect, | |||
1078 | WW8TableNodeInfo * pNodeInfo, | |||
1079 | const unsigned long * pFormatFrameWidth) | |||
1080 | { | |||
1081 | CellInfo aCellInfo(rRect, pNodeInfo); | |||
1082 | ||||
1083 | if (pFormatFrameWidth != nullptr) | |||
1084 | aCellInfo.setFormatFrameWidth(*pFormatFrameWidth); | |||
1085 | ||||
1086 | WW8TableCellGridRow::Pointer_t pRow = getRow(rRect.Top()); | |||
1087 | pRow->insert(aCellInfo); | |||
1088 | } | |||
1089 | ||||
1090 | void WW8TableCellGrid::addShadowCells() | |||
1091 | { | |||
1092 | SAL_INFO( "sw.ww8", "<addShadowCells>" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "<addShadowCells>" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8" ), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "1092" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "<addShadowCells>"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<addShadowCells>"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "1092" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "<addShadowCells>") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "1092" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "<addShadowCells>"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "<addShadowCells>"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "1092" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1093 | ||||
1094 | RowTops_t::const_iterator aTopsIt = getRowTopsBegin(); | |||
1095 | ||||
1096 | while (aTopsIt != getRowTopsEnd()) | |||
1097 | { | |||
1098 | CellInfoMultiSet::const_iterator aCellIt = getCellsBegin(*aTopsIt); | |||
1099 | CellInfoMultiSet::const_iterator aCellEndIt = getCellsEnd(*aTopsIt); | |||
1100 | ||||
1101 | RowSpansPtr pRowSpans = std::make_shared<RowSpans>(); | |||
1102 | ||||
1103 | bool bBeginningOfCell = true; | |||
1104 | bool bVertMerge = false; | |||
1105 | SwRect aRect = aCellIt->getRect(); | |||
1106 | long nRowSpan = 1; | |||
1107 | while (aCellIt != aCellEndIt) | |||
1108 | { | |||
1109 | WW8TableNodeInfo * pNodeInfo = aCellIt->getTableNodeInfo(); | |||
1110 | ||||
1111 | if (bBeginningOfCell) | |||
1112 | { | |||
1113 | RowTops_t::const_iterator aRowSpanIt(aTopsIt); | |||
1114 | ++aRowSpanIt; | |||
1115 | ||||
1116 | if (aRowSpanIt != getRowTopsEnd() && | |||
1117 | *aRowSpanIt < aCellIt->bottom()) | |||
1118 | { | |||
1119 | aRect.Top(*aRowSpanIt); | |||
1120 | unsigned long nFormatFrameWidth = aCellIt->getFormatFrameWidth(); | |||
1121 | insert(aRect, nullptr, &nFormatFrameWidth); | |||
1122 | ||||
1123 | bVertMerge = true; | |||
1124 | } | |||
1125 | else | |||
1126 | bVertMerge = false; | |||
1127 | ||||
1128 | nRowSpan = 1; | |||
1129 | while (aRowSpanIt != getRowTopsEnd() && | |||
1130 | *aRowSpanIt < aCellIt->bottom()) | |||
1131 | { | |||
1132 | ++aRowSpanIt; | |||
1133 | nRowSpan++; | |||
1134 | } | |||
1135 | ||||
1136 | if (pNodeInfo) | |||
1137 | pRowSpans->push_back(nRowSpan); | |||
1138 | else | |||
1139 | pRowSpans->push_back(-nRowSpan); | |||
1140 | } | |||
1141 | ||||
1142 | if (pNodeInfo) | |||
1143 | { | |||
1144 | pNodeInfo->setVertMerge(bVertMerge); | |||
1145 | } | |||
1146 | ||||
1147 | ++aCellIt; | |||
1148 | if (aCellIt != aCellEndIt) | |||
1149 | { | |||
1150 | bBeginningOfCell = (aRect.Left() != aCellIt->left()); | |||
1151 | aRect = aCellIt->getRect(); | |||
1152 | } | |||
1153 | } | |||
1154 | ||||
1155 | WW8TableCellGridRow::Pointer_t pRow = getRow(*aTopsIt); | |||
1156 | if (pRow) | |||
1157 | pRow->setRowSpans(pRowSpans); | |||
1158 | ||||
1159 | ++aTopsIt; | |||
1160 | } | |||
1161 | SAL_INFO( "sw.ww8", "</addShadowCells>" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "</addShadowCells>" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8" ), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "1161" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "</addShadowCells>"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "</addShadowCells>"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "1161" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "</addShadowCells>") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "1161" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "</addShadowCells>"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "</addShadowCells>"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "1161" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1162 | } | |||
1163 | ||||
1164 | WW8TableNodeInfo * WW8TableCellGrid::connectCells(RowEndInners_t &rLastRowEnds) | |||
1165 | { | |||
1166 | RowTops_t::const_iterator aTopsIt = getRowTopsBegin(); | |||
1167 | sal_uInt32 nRow = 0; | |||
1168 | WW8TableNodeInfo * pLastNodeInfo = nullptr; | |||
1169 | ||||
1170 | while (aTopsIt != getRowTopsEnd()) | |||
1171 | { | |||
1172 | CellInfoMultiSet::const_iterator aCellIt = getCellsBegin(*aTopsIt); | |||
1173 | CellInfoMultiSet::const_iterator aCellEndIt = getCellsEnd(*aTopsIt); | |||
1174 | GridColsPtr pWidths = std::make_shared<Widths>(); | |||
1175 | TableBoxVectorPtr pTableBoxes = std::make_shared<TableBoxVector>(); | |||
1176 | ||||
1177 | sal_uInt32 nShadows = 0; | |||
1178 | sal_uInt32 nCell = 0; | |||
1179 | bool bBeginningOfCell = true; | |||
1180 | WW8TableNodeInfo * pEndOfCellInfo = nullptr; | |||
1181 | sal_uInt32 nDepthInCell = 0; | |||
1182 | while (aCellIt != aCellEndIt) | |||
1183 | { | |||
1184 | long nCellX = aCellIt->left(); | |||
1185 | WW8TableNodeInfo * pNodeInfo = aCellIt->getTableNodeInfo(); | |||
1186 | if (pNodeInfo) | |||
1187 | { | |||
1188 | const SwNode * pNode = pNodeInfo->getNode(); | |||
1189 | ||||
1190 | if (pNode->IsStartNode()) | |||
1191 | { | |||
1192 | nDepthInCell++; | |||
1193 | pEndOfCellInfo = nullptr; | |||
1194 | } | |||
1195 | ||||
1196 | if (nDepthInCell == 1 && pNode->IsTextNode()) | |||
1197 | pEndOfCellInfo = pNodeInfo; | |||
1198 | ||||
1199 | pNodeInfo->setShadowsBefore(nShadows); | |||
1200 | pNodeInfo->setCell(nCell); | |||
1201 | pNodeInfo->setRow(nRow); | |||
1202 | if (pLastNodeInfo) | |||
1203 | { | |||
1204 | pLastNodeInfo->setNext(pNodeInfo); | |||
1205 | pLastNodeInfo->setNextNode(pNode); | |||
1206 | } | |||
1207 | pLastNodeInfo = pNodeInfo; | |||
1208 | nShadows = 0; | |||
1209 | ||||
1210 | if (pNode->IsEndNode()) | |||
1211 | { | |||
1212 | nDepthInCell--; | |||
1213 | ||||
1214 | if (nDepthInCell == 0 && !pEndOfCellInfo) | |||
1215 | pEndOfCellInfo = pNodeInfo; | |||
1216 | } | |||
1217 | } | |||
1218 | else | |||
1219 | { | |||
1220 | nShadows++; | |||
1221 | } | |||
1222 | ||||
1223 | if (bBeginningOfCell) | |||
1224 | { | |||
1225 | pWidths->push_back(aCellIt->getFormatFrameWidth()); | |||
1226 | ||||
1227 | if (pNodeInfo) | |||
1228 | pTableBoxes->push_back(pNodeInfo->getTableBox()); | |||
1229 | else | |||
1230 | pTableBoxes->push_back(nullptr); | |||
1231 | } | |||
1232 | ||||
1233 | ++aCellIt; | |||
1234 | bBeginningOfCell = false; | |||
1235 | ||||
1236 | if (aCellIt != aCellEndIt && aCellIt->left() != nCellX) | |||
1237 | { | |||
1238 | nCell++; | |||
1239 | bBeginningOfCell = true; | |||
1240 | ||||
1241 | if (pEndOfCellInfo) | |||
1242 | { | |||
1243 | pEndOfCellInfo->setEndOfCell(true); | |||
1244 | } | |||
1245 | ||||
1246 | pEndOfCellInfo = nullptr; | |||
1247 | } | |||
1248 | } | |||
1249 | ||||
1250 | pLastNodeInfo->setShadowsAfter(nShadows); | |||
| ||||
1251 | ||||
1252 | if (!pEndOfCellInfo) | |||
1253 | { | |||
1254 | pEndOfCellInfo = pLastNodeInfo; | |||
1255 | } | |||
1256 | ||||
1257 | pEndOfCellInfo->setEndOfCell(true); | |||
1258 | pLastNodeInfo->setEndOfLine(true); | |||
1259 | updateFinalEndOfLine(rLastRowEnds, pLastNodeInfo); | |||
1260 | ||||
1261 | WW8TableCellGridRow::Pointer_t pRow(getRow(*aTopsIt)); | |||
1262 | pRow->setTableBoxVector(pTableBoxes); | |||
1263 | pRow->setWidths(pWidths); | |||
1264 | ||||
1265 | ++aTopsIt; | |||
1266 | nRow++; | |||
1267 | } | |||
1268 | ||||
1269 | return pLastNodeInfo; | |||
1270 | } | |||
1271 | ||||
1272 | #ifdef DBG_UTIL | |||
1273 | std::string WW8TableCellGrid::toString() | |||
1274 | { | |||
1275 | std::string sResult = "<WW8TableCellGrid>"; | |||
1276 | ||||
1277 | RowTops_t::const_iterator aTopsIt = getRowTopsBegin(); | |||
1278 | static char sBuffer[1024]; | |||
1279 | while (aTopsIt != getRowTopsEnd()) | |||
1280 | { | |||
1281 | sprintf(sBuffer, "<row y=\"%ld\">", *aTopsIt); | |||
1282 | sResult += sBuffer; | |||
1283 | ||||
1284 | CellInfoMultiSet::const_iterator aCellIt = getCellsBegin(*aTopsIt); | |||
1285 | CellInfoMultiSet::const_iterator aCellsEnd = getCellsEnd(*aTopsIt); | |||
1286 | ||||
1287 | while (aCellIt != aCellsEnd) | |||
1288 | { | |||
1289 | snprintf(sBuffer, sizeof(sBuffer), "<cellInfo top=\"%ld\" bottom=\"%ld\" left=\"%ld\" right=\"%ld\">", | |||
1290 | aCellIt->top(), aCellIt->bottom(), aCellIt->left(), aCellIt->right()); | |||
1291 | sResult += sBuffer; | |||
1292 | ||||
1293 | WW8TableNodeInfo * pInfo = aCellIt->getTableNodeInfo(); | |||
1294 | if (pInfo) | |||
1295 | sResult += pInfo->toString(); | |||
1296 | else | |||
1297 | sResult += "<shadow/>\n"; | |||
1298 | ||||
1299 | sResult += "</cellInfo>\n"; | |||
1300 | ++aCellIt; | |||
1301 | } | |||
1302 | ||||
1303 | WW8TableCellGridRow::Pointer_t pRow = getRow(*aTopsIt); | |||
1304 | WidthsPtr pWidths = pRow->getWidths(); | |||
1305 | if (pWidths != nullptr) | |||
1306 | { | |||
1307 | sResult += "<widths>"; | |||
1308 | ||||
1309 | Widths::const_iterator aItEnd = pWidths->end(); | |||
1310 | for (Widths::const_iterator aIt = pWidths->begin(); | |||
1311 | aIt != aItEnd; | |||
1312 | ++aIt) | |||
1313 | { | |||
1314 | if (aIt != pWidths->begin()) | |||
1315 | sResult += ", "; | |||
1316 | ||||
1317 | snprintf(sBuffer, sizeof(sBuffer), "%" SAL_PRIxUINT32"x" "", *aIt); | |||
1318 | sResult += sBuffer; | |||
1319 | } | |||
1320 | ||||
1321 | sResult += "</widths>"; | |||
1322 | } | |||
1323 | ||||
1324 | RowSpansPtr pRowSpans = pRow->getRowSpans(); | |||
1325 | if (pRowSpans) | |||
1326 | { | |||
1327 | sResult += "<rowspans>"; | |||
1328 | ||||
1329 | RowSpans::const_iterator aItEnd = pRowSpans->end(); | |||
1330 | for (RowSpans::const_iterator aIt = pRowSpans->begin(); | |||
1331 | aIt != aItEnd; | |||
1332 | ++aIt) | |||
1333 | { | |||
1334 | if (aIt != pRowSpans->begin()) | |||
1335 | sResult += ", "; | |||
1336 | ||||
1337 | snprintf(sBuffer, sizeof(sBuffer), "%" SAL_PRIxUINT32"x" "", *aIt); | |||
1338 | sResult += sBuffer; | |||
1339 | } | |||
1340 | ||||
1341 | sResult += "</rowspans>"; | |||
1342 | } | |||
1343 | ||||
1344 | sResult += "</row>\n"; | |||
1345 | ++aTopsIt; | |||
1346 | } | |||
1347 | ||||
1348 | sResult += "</WW8TableCellGrid>\n"; | |||
1349 | ||||
1350 | return sResult; | |||
1351 | } | |||
1352 | #endif | |||
1353 | ||||
1354 | TableBoxVectorPtr WW8TableCellGrid::getTableBoxesOfRow | |||
1355 | (WW8TableNodeInfoInner const * pNodeInfoInner) | |||
1356 | { | |||
1357 | TableBoxVectorPtr pResult; | |||
1358 | WW8TableCellGridRow::Pointer_t pRow = | |||
1359 | getRow(pNodeInfoInner->getRect().Top(), false); | |||
1360 | ||||
1361 | if (pRow) | |||
1362 | { | |||
1363 | pResult = pRow->getTableBoxVector(); | |||
1364 | } | |||
1365 | ||||
1366 | return pResult; | |||
1367 | } | |||
1368 | ||||
1369 | WidthsPtr WW8TableCellGrid::getWidthsOfRow | |||
1370 | (WW8TableNodeInfoInner const * pNodeInfoInner) | |||
1371 | { | |||
1372 | GridColsPtr pResult; | |||
1373 | ||||
1374 | WW8TableCellGridRow::Pointer_t pRow = | |||
1375 | getRow(pNodeInfoInner->getRect().Top(), false); | |||
1376 | ||||
1377 | if (pRow) | |||
1378 | { | |||
1379 | pResult = pRow->getWidths(); | |||
1380 | } | |||
1381 | ||||
1382 | return pResult; | |||
1383 | } | |||
1384 | ||||
1385 | RowSpansPtr WW8TableCellGrid::getRowSpansOfRow | |||
1386 | (WW8TableNodeInfoInner const * pNodeInfoInner) | |||
1387 | { | |||
1388 | RowSpansPtr pResult; | |||
1389 | ||||
1390 | WW8TableCellGridRow::Pointer_t pRow = | |||
1391 | getRow(pNodeInfoInner->getRect().Top(), false); | |||
1392 | ||||
1393 | if (pRow) | |||
1394 | { | |||
1395 | pResult = pRow->getRowSpans(); | |||
1396 | } | |||
1397 | ||||
1398 | return pResult; | |||
1399 | } | |||
1400 | ||||
1401 | WW8TableCellGridRow::WW8TableCellGridRow() | |||
1402 | : m_pCellInfos(std::make_shared<CellInfoMultiSet>()) | |||
1403 | { | |||
1404 | } | |||
1405 | ||||
1406 | WW8TableCellGridRow::~WW8TableCellGridRow() | |||
1407 | { | |||
1408 | } | |||
1409 | ||||
1410 | void WW8TableCellGridRow::insert(const CellInfo & rCellInfo) | |||
1411 | { | |||
1412 | m_pCellInfos->insert(rCellInfo); | |||
1413 | ||||
1414 | #ifdef DBG_UTIL | |||
1415 | SAL_INFO( "sw.ww8", "<gridRowInsert>" << rCellInfo.toString() << "</gridRowInsert>" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "sw.ww8")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult ( ::sal::detail::StreamStart() << "<gridRowInsert>" << rCellInfo.toString() << "</gridRowInsert>" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8" ), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "1415" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "<gridRowInsert>" << rCellInfo .toString() << "</gridRowInsert>"), 0); } else { :: std::ostringstream sal_detail_stream; sal_detail_stream << "<gridRowInsert>" << rCellInfo.toString() << "</gridRowInsert>"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "1415" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "<gridRowInsert>" << rCellInfo.toString () << "</gridRowInsert>") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "1415" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "<gridRowInsert>" << rCellInfo .toString() << "</gridRowInsert>"), 0); } else { :: std::ostringstream sal_detail_stream; sal_detail_stream << "<gridRowInsert>" << rCellInfo.toString() << "</gridRowInsert>"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("sw.ww8"), ("/home/maarten/src/libreoffice/core/sw/source/filter/ww8/WW8TableInfo.cxx" ":" "1415" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1416 | #endif | |||
1417 | } | |||
1418 | ||||
1419 | CellInfoMultiSet::const_iterator WW8TableCellGridRow::begin() const | |||
1420 | { | |||
1421 | return m_pCellInfos->begin(); | |||
1422 | } | |||
1423 | ||||
1424 | CellInfoMultiSet::const_iterator WW8TableCellGridRow::end() const | |||
1425 | { | |||
1426 | return m_pCellInfos->end(); | |||
1427 | } | |||
1428 | ||||
1429 | void WW8TableCellGridRow::setTableBoxVector(TableBoxVectorPtr const & pTableBoxVector) | |||
1430 | { | |||
1431 | if (pTableBoxVector->size() > MAXTABLECELLS) | |||
1432 | pTableBoxVector->resize(MAXTABLECELLS); | |||
1433 | m_pTableBoxVector = pTableBoxVector; | |||
1434 | } | |||
1435 | ||||
1436 | void WW8TableCellGridRow::setWidths(WidthsPtr const & pWidths) | |||
1437 | { | |||
1438 | m_pWidths = pWidths; | |||
1439 | } | |||
1440 | ||||
1441 | void WW8TableCellGridRow::setRowSpans(RowSpansPtr const & pRowSpans) | |||
1442 | { | |||
1443 | m_pRowSpans = pRowSpans; | |||
1444 | } | |||
1445 | ||||
1446 | ||||
1447 | CellInfo::CellInfo(const SwRect & aRect, WW8TableNodeInfo * pNodeInfo) | |||
1448 | : m_aRect(aRect), m_pNodeInfo(pNodeInfo), m_nFormatFrameWidth(0) | |||
1449 | { | |||
1450 | if (pNodeInfo != nullptr) | |||
1451 | { | |||
1452 | const SwTableBox * pBox = pNodeInfo->getTableBox(); | |||
1453 | const SwFrameFormat * pFrameFormat = pBox->GetFrameFormat(); | |||
1454 | const SwFormatFrameSize & rSize = pFrameFormat->GetFrameSize(); | |||
1455 | ||||
1456 | m_nFormatFrameWidth = rSize.GetWidth(); | |||
1457 | } | |||
1458 | } | |||
1459 | ||||
1460 | } | |||
1461 | ||||
1462 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
1 | // RB tree implementation -*- C++ -*- |
2 | |
3 | // Copyright (C) 2001-2020 Free Software Foundation, Inc. |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free |
6 | // software; you can redistribute it and/or modify it under the |
7 | // terms of the GNU General Public License as published by the |
8 | // Free Software Foundation; either version 3, or (at your option) |
9 | // any later version. |
10 | |
11 | // This library is distributed in the hope that it will be useful, |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | // GNU General Public License for more details. |
15 | |
16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version |
18 | // 3.1, as published by the Free Software Foundation. |
19 | |
20 | // You should have received a copy of the GNU General Public License and |
21 | // a copy of the GCC Runtime Library Exception along with this program; |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
23 | // <http://www.gnu.org/licenses/>. |
24 | |
25 | /* |
26 | * |
27 | * Copyright (c) 1996,1997 |
28 | * Silicon Graphics Computer Systems, Inc. |
29 | * |
30 | * Permission to use, copy, modify, distribute and sell this software |
31 | * and its documentation for any purpose is hereby granted without fee, |
32 | * provided that the above copyright notice appear in all copies and |
33 | * that both that copyright notice and this permission notice appear |
34 | * in supporting documentation. Silicon Graphics makes no |
35 | * representations about the suitability of this software for any |
36 | * purpose. It is provided "as is" without express or implied warranty. |
37 | * |
38 | * |
39 | * Copyright (c) 1994 |
40 | * Hewlett-Packard Company |
41 | * |
42 | * Permission to use, copy, modify, distribute and sell this software |
43 | * and its documentation for any purpose is hereby granted without fee, |
44 | * provided that the above copyright notice appear in all copies and |
45 | * that both that copyright notice and this permission notice appear |
46 | * in supporting documentation. Hewlett-Packard Company makes no |
47 | * representations about the suitability of this software for any |
48 | * purpose. It is provided "as is" without express or implied warranty. |
49 | * |
50 | * |
51 | */ |
52 | |
53 | /** @file bits/stl_tree.h |
54 | * This is an internal header file, included by other library headers. |
55 | * Do not attempt to use it directly. @headername{map,set} |
56 | */ |
57 | |
58 | #ifndef _STL_TREE_H1 |
59 | #define _STL_TREE_H1 1 |
60 | |
61 | #pragma GCC system_header |
62 | |
63 | #include <bits/stl_algobase.h> |
64 | #include <bits/allocator.h> |
65 | #include <bits/stl_function.h> |
66 | #include <bits/cpp_type_traits.h> |
67 | #include <ext/alloc_traits.h> |
68 | #if __cplusplus201703L >= 201103L |
69 | # include <ext/aligned_buffer.h> |
70 | #endif |
71 | #if __cplusplus201703L > 201402L |
72 | # include <bits/node_handle.h> |
73 | #endif |
74 | |
75 | namespace std _GLIBCXX_VISIBILITY(default)__attribute__ ((__visibility__ ("default"))) |
76 | { |
77 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
78 | |
79 | #if __cplusplus201703L > 201103L |
80 | # define __cpp_lib_generic_associative_lookup201304 201304 |
81 | #endif |
82 | |
83 | // Red-black tree class, designed for use in implementing STL |
84 | // associative containers (set, multiset, map, and multimap). The |
85 | // insertion and deletion algorithms are based on those in Cormen, |
86 | // Leiserson, and Rivest, Introduction to Algorithms (MIT Press, |
87 | // 1990), except that |
88 | // |
89 | // (1) the header cell is maintained with links not only to the root |
90 | // but also to the leftmost node of the tree, to enable constant |
91 | // time begin(), and to the rightmost node of the tree, to enable |
92 | // linear time performance when used with the generic set algorithms |
93 | // (set_union, etc.) |
94 | // |
95 | // (2) when a node being deleted has two children its successor node |
96 | // is relinked into its place, rather than copied, so that the only |
97 | // iterators invalidated are those referring to the deleted node. |
98 | |
99 | enum _Rb_tree_color { _S_red = false, _S_black = true }; |
100 | |
101 | struct _Rb_tree_node_base |
102 | { |
103 | typedef _Rb_tree_node_base* _Base_ptr; |
104 | typedef const _Rb_tree_node_base* _Const_Base_ptr; |
105 | |
106 | _Rb_tree_color _M_color; |
107 | _Base_ptr _M_parent; |
108 | _Base_ptr _M_left; |
109 | _Base_ptr _M_right; |
110 | |
111 | static _Base_ptr |
112 | _S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPTnoexcept |
113 | { |
114 | while (__x->_M_left != 0) __x = __x->_M_left; |
115 | return __x; |
116 | } |
117 | |
118 | static _Const_Base_ptr |
119 | _S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPTnoexcept |
120 | { |
121 | while (__x->_M_left != 0) __x = __x->_M_left; |
122 | return __x; |
123 | } |
124 | |
125 | static _Base_ptr |
126 | _S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPTnoexcept |
127 | { |
128 | while (__x->_M_right != 0) __x = __x->_M_right; |
129 | return __x; |
130 | } |
131 | |
132 | static _Const_Base_ptr |
133 | _S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPTnoexcept |
134 | { |
135 | while (__x->_M_right != 0) __x = __x->_M_right; |
136 | return __x; |
137 | } |
138 | }; |
139 | |
140 | // Helper type offering value initialization guarantee on the compare functor. |
141 | template<typename _Key_compare> |
142 | struct _Rb_tree_key_compare |
143 | { |
144 | _Key_compare _M_key_compare; |
145 | |
146 | _Rb_tree_key_compare() |
147 | _GLIBCXX_NOEXCEPT_IF(noexcept(is_nothrow_default_constructible<_Key_compare> ::value) |
148 | is_nothrow_default_constructible<_Key_compare>::value)noexcept(is_nothrow_default_constructible<_Key_compare> ::value) |
149 | : _M_key_compare() |
150 | { } |
151 | |
152 | _Rb_tree_key_compare(const _Key_compare& __comp) |
153 | : _M_key_compare(__comp) |
154 | { } |
155 | |
156 | #if __cplusplus201703L >= 201103L |
157 | // Copy constructor added for consistency with C++98 mode. |
158 | _Rb_tree_key_compare(const _Rb_tree_key_compare&) = default; |
159 | |
160 | _Rb_tree_key_compare(_Rb_tree_key_compare&& __x) |
161 | noexcept(is_nothrow_copy_constructible<_Key_compare>::value) |
162 | : _M_key_compare(__x._M_key_compare) |
163 | { } |
164 | #endif |
165 | }; |
166 | |
167 | // Helper type to manage default initialization of node count and header. |
168 | struct _Rb_tree_header |
169 | { |
170 | _Rb_tree_node_base _M_header; |
171 | size_t _M_node_count; // Keeps track of size of tree. |
172 | |
173 | _Rb_tree_header() _GLIBCXX_NOEXCEPTnoexcept |
174 | { |
175 | _M_header._M_color = _S_red; |
176 | _M_reset(); |
177 | } |
178 | |
179 | #if __cplusplus201703L >= 201103L |
180 | _Rb_tree_header(_Rb_tree_header&& __x) noexcept |
181 | { |
182 | if (__x._M_header._M_parent != nullptr) |
183 | _M_move_data(__x); |
184 | else |
185 | { |
186 | _M_header._M_color = _S_red; |
187 | _M_reset(); |
188 | } |
189 | } |
190 | #endif |
191 | |
192 | void |
193 | _M_move_data(_Rb_tree_header& __from) |
194 | { |
195 | _M_header._M_color = __from._M_header._M_color; |
196 | _M_header._M_parent = __from._M_header._M_parent; |
197 | _M_header._M_left = __from._M_header._M_left; |
198 | _M_header._M_right = __from._M_header._M_right; |
199 | _M_header._M_parent->_M_parent = &_M_header; |
200 | _M_node_count = __from._M_node_count; |
201 | |
202 | __from._M_reset(); |
203 | } |
204 | |
205 | void |
206 | _M_reset() |
207 | { |
208 | _M_header._M_parent = 0; |
209 | _M_header._M_left = &_M_header; |
210 | _M_header._M_right = &_M_header; |
211 | _M_node_count = 0; |
212 | } |
213 | }; |
214 | |
215 | template<typename _Val> |
216 | struct _Rb_tree_node : public _Rb_tree_node_base |
217 | { |
218 | typedef _Rb_tree_node<_Val>* _Link_type; |
219 | |
220 | #if __cplusplus201703L < 201103L |
221 | _Val _M_value_field; |
222 | |
223 | _Val* |
224 | _M_valptr() |
225 | { return std::__addressof(_M_value_field); } |
226 | |
227 | const _Val* |
228 | _M_valptr() const |
229 | { return std::__addressof(_M_value_field); } |
230 | #else |
231 | __gnu_cxx::__aligned_membuf<_Val> _M_storage; |
232 | |
233 | _Val* |
234 | _M_valptr() |
235 | { return _M_storage._M_ptr(); } |
236 | |
237 | const _Val* |
238 | _M_valptr() const |
239 | { return _M_storage._M_ptr(); } |
240 | #endif |
241 | }; |
242 | |
243 | _GLIBCXX_PURE__attribute__ ((__pure__)) _Rb_tree_node_base* |
244 | _Rb_tree_increment(_Rb_tree_node_base* __x) throw (); |
245 | |
246 | _GLIBCXX_PURE__attribute__ ((__pure__)) const _Rb_tree_node_base* |
247 | _Rb_tree_increment(const _Rb_tree_node_base* __x) throw (); |
248 | |
249 | _GLIBCXX_PURE__attribute__ ((__pure__)) _Rb_tree_node_base* |
250 | _Rb_tree_decrement(_Rb_tree_node_base* __x) throw (); |
251 | |
252 | _GLIBCXX_PURE__attribute__ ((__pure__)) const _Rb_tree_node_base* |
253 | _Rb_tree_decrement(const _Rb_tree_node_base* __x) throw (); |
254 | |
255 | template<typename _Tp> |
256 | struct _Rb_tree_iterator |
257 | { |
258 | typedef _Tp value_type; |
259 | typedef _Tp& reference; |
260 | typedef _Tp* pointer; |
261 | |
262 | typedef bidirectional_iterator_tag iterator_category; |
263 | typedef ptrdiff_t difference_type; |
264 | |
265 | typedef _Rb_tree_iterator<_Tp> _Self; |
266 | typedef _Rb_tree_node_base::_Base_ptr _Base_ptr; |
267 | typedef _Rb_tree_node<_Tp>* _Link_type; |
268 | |
269 | _Rb_tree_iterator() _GLIBCXX_NOEXCEPTnoexcept |
270 | : _M_node() { } |
271 | |
272 | explicit |
273 | _Rb_tree_iterator(_Base_ptr __x) _GLIBCXX_NOEXCEPTnoexcept |
274 | : _M_node(__x) { } |
275 | |
276 | reference |
277 | operator*() const _GLIBCXX_NOEXCEPTnoexcept |
278 | { return *static_cast<_Link_type>(_M_node)->_M_valptr(); } |
279 | |
280 | pointer |
281 | operator->() const _GLIBCXX_NOEXCEPTnoexcept |
282 | { return static_cast<_Link_type> (_M_node)->_M_valptr(); } |
283 | |
284 | _Self& |
285 | operator++() _GLIBCXX_NOEXCEPTnoexcept |
286 | { |
287 | _M_node = _Rb_tree_increment(_M_node); |
288 | return *this; |
289 | } |
290 | |
291 | _Self |
292 | operator++(int) _GLIBCXX_NOEXCEPTnoexcept |
293 | { |
294 | _Self __tmp = *this; |
295 | _M_node = _Rb_tree_increment(_M_node); |
296 | return __tmp; |
297 | } |
298 | |
299 | _Self& |
300 | operator--() _GLIBCXX_NOEXCEPTnoexcept |
301 | { |
302 | _M_node = _Rb_tree_decrement(_M_node); |
303 | return *this; |
304 | } |
305 | |
306 | _Self |
307 | operator--(int) _GLIBCXX_NOEXCEPTnoexcept |
308 | { |
309 | _Self __tmp = *this; |
310 | _M_node = _Rb_tree_decrement(_M_node); |
311 | return __tmp; |
312 | } |
313 | |
314 | friend bool |
315 | operator==(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPTnoexcept |
316 | { return __x._M_node == __y._M_node; } |
317 | |
318 | #if ! __cpp_lib_three_way_comparison |
319 | friend bool |
320 | operator!=(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPTnoexcept |
321 | { return __x._M_node != __y._M_node; } |
322 | #endif |
323 | |
324 | _Base_ptr _M_node; |
325 | }; |
326 | |
327 | template<typename _Tp> |
328 | struct _Rb_tree_const_iterator |
329 | { |
330 | typedef _Tp value_type; |
331 | typedef const _Tp& reference; |
332 | typedef const _Tp* pointer; |
333 | |
334 | typedef _Rb_tree_iterator<_Tp> iterator; |
335 | |
336 | typedef bidirectional_iterator_tag iterator_category; |
337 | typedef ptrdiff_t difference_type; |
338 | |
339 | typedef _Rb_tree_const_iterator<_Tp> _Self; |
340 | typedef _Rb_tree_node_base::_Const_Base_ptr _Base_ptr; |
341 | typedef const _Rb_tree_node<_Tp>* _Link_type; |
342 | |
343 | _Rb_tree_const_iterator() _GLIBCXX_NOEXCEPTnoexcept |
344 | : _M_node() { } |
345 | |
346 | explicit |
347 | _Rb_tree_const_iterator(_Base_ptr __x) _GLIBCXX_NOEXCEPTnoexcept |
348 | : _M_node(__x) { } |
349 | |
350 | _Rb_tree_const_iterator(const iterator& __it) _GLIBCXX_NOEXCEPTnoexcept |
351 | : _M_node(__it._M_node) { } |
352 | |
353 | iterator |
354 | _M_const_cast() const _GLIBCXX_NOEXCEPTnoexcept |
355 | { return iterator(const_cast<typename iterator::_Base_ptr>(_M_node)); } |
356 | |
357 | reference |
358 | operator*() const _GLIBCXX_NOEXCEPTnoexcept |
359 | { return *static_cast<_Link_type>(_M_node)->_M_valptr(); } |
360 | |
361 | pointer |
362 | operator->() const _GLIBCXX_NOEXCEPTnoexcept |
363 | { return static_cast<_Link_type>(_M_node)->_M_valptr(); } |
364 | |
365 | _Self& |
366 | operator++() _GLIBCXX_NOEXCEPTnoexcept |
367 | { |
368 | _M_node = _Rb_tree_increment(_M_node); |
369 | return *this; |
370 | } |
371 | |
372 | _Self |
373 | operator++(int) _GLIBCXX_NOEXCEPTnoexcept |
374 | { |
375 | _Self __tmp = *this; |
376 | _M_node = _Rb_tree_increment(_M_node); |
377 | return __tmp; |
378 | } |
379 | |
380 | _Self& |
381 | operator--() _GLIBCXX_NOEXCEPTnoexcept |
382 | { |
383 | _M_node = _Rb_tree_decrement(_M_node); |
384 | return *this; |
385 | } |
386 | |
387 | _Self |
388 | operator--(int) _GLIBCXX_NOEXCEPTnoexcept |
389 | { |
390 | _Self __tmp = *this; |
391 | _M_node = _Rb_tree_decrement(_M_node); |
392 | return __tmp; |
393 | } |
394 | |
395 | friend bool |
396 | operator==(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPTnoexcept |
397 | { return __x._M_node == __y._M_node; } |
398 | |
399 | #if ! __cpp_lib_three_way_comparison |
400 | friend bool |
401 | operator!=(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPTnoexcept |
402 | { return __x._M_node != __y._M_node; } |
403 | #endif |
404 | |
405 | _Base_ptr _M_node; |
406 | }; |
407 | |
408 | void |
409 | _Rb_tree_insert_and_rebalance(const bool __insert_left, |
410 | _Rb_tree_node_base* __x, |
411 | _Rb_tree_node_base* __p, |
412 | _Rb_tree_node_base& __header) throw (); |
413 | |
414 | _Rb_tree_node_base* |
415 | _Rb_tree_rebalance_for_erase(_Rb_tree_node_base* const __z, |
416 | _Rb_tree_node_base& __header) throw (); |
417 | |
418 | #if __cplusplus201703L >= 201402L |
419 | template<typename _Cmp, typename _SfinaeType, typename = __void_t<>> |
420 | struct __has_is_transparent |
421 | { }; |
422 | |
423 | template<typename _Cmp, typename _SfinaeType> |
424 | struct __has_is_transparent<_Cmp, _SfinaeType, |
425 | __void_t<typename _Cmp::is_transparent>> |
426 | { typedef void type; }; |
427 | |
428 | template<typename _Cmp, typename _SfinaeType> |
429 | using __has_is_transparent_t |
430 | = typename __has_is_transparent<_Cmp, _SfinaeType>::type; |
431 | #endif |
432 | |
433 | #if __cplusplus201703L > 201402L |
434 | template<typename _Tree1, typename _Cmp2> |
435 | struct _Rb_tree_merge_helper { }; |
436 | #endif |
437 | |
438 | template<typename _Key, typename _Val, typename _KeyOfValue, |
439 | typename _Compare, typename _Alloc = allocator<_Val> > |
440 | class _Rb_tree |
441 | { |
442 | typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template |
443 | rebind<_Rb_tree_node<_Val> >::other _Node_allocator; |
444 | |
445 | typedef __gnu_cxx::__alloc_traits<_Node_allocator> _Alloc_traits; |
446 | |
447 | protected: |
448 | typedef _Rb_tree_node_base* _Base_ptr; |
449 | typedef const _Rb_tree_node_base* _Const_Base_ptr; |
450 | typedef _Rb_tree_node<_Val>* _Link_type; |
451 | typedef const _Rb_tree_node<_Val>* _Const_Link_type; |
452 | |
453 | private: |
454 | // Functor recycling a pool of nodes and using allocation once the pool |
455 | // is empty. |
456 | struct _Reuse_or_alloc_node |
457 | { |
458 | _Reuse_or_alloc_node(_Rb_tree& __t) |
459 | : _M_root(__t._M_root()), _M_nodes(__t._M_rightmost()), _M_t(__t) |
460 | { |
461 | if (_M_root) |
462 | { |
463 | _M_root->_M_parent = 0; |
464 | |
465 | if (_M_nodes->_M_left) |
466 | _M_nodes = _M_nodes->_M_left; |
467 | } |
468 | else |
469 | _M_nodes = 0; |
470 | } |
471 | |
472 | #if __cplusplus201703L >= 201103L |
473 | _Reuse_or_alloc_node(const _Reuse_or_alloc_node&) = delete; |
474 | #endif |
475 | |
476 | ~_Reuse_or_alloc_node() |
477 | { _M_t._M_erase(static_cast<_Link_type>(_M_root)); } |
478 | |
479 | template<typename _Arg> |
480 | _Link_type |
481 | #if __cplusplus201703L < 201103L |
482 | operator()(const _Arg& __arg) |
483 | #else |
484 | operator()(_Arg&& __arg) |
485 | #endif |
486 | { |
487 | _Link_type __node = static_cast<_Link_type>(_M_extract()); |
488 | if (__node) |
489 | { |
490 | _M_t._M_destroy_node(__node); |
491 | _M_t._M_construct_node(__node, _GLIBCXX_FORWARD(_Arg, __arg)std::forward<_Arg>(__arg)); |
492 | return __node; |
493 | } |
494 | |
495 | return _M_t._M_create_node(_GLIBCXX_FORWARD(_Arg, __arg)std::forward<_Arg>(__arg)); |
496 | } |
497 | |
498 | private: |
499 | _Base_ptr |
500 | _M_extract() |
501 | { |
502 | if (!_M_nodes) |
503 | return _M_nodes; |
504 | |
505 | _Base_ptr __node = _M_nodes; |
506 | _M_nodes = _M_nodes->_M_parent; |
507 | if (_M_nodes) |
508 | { |
509 | if (_M_nodes->_M_right == __node) |
510 | { |
511 | _M_nodes->_M_right = 0; |
512 | |
513 | if (_M_nodes->_M_left) |
514 | { |
515 | _M_nodes = _M_nodes->_M_left; |
516 | |
517 | while (_M_nodes->_M_right) |
518 | _M_nodes = _M_nodes->_M_right; |
519 | |
520 | if (_M_nodes->_M_left) |
521 | _M_nodes = _M_nodes->_M_left; |
522 | } |
523 | } |
524 | else // __node is on the left. |
525 | _M_nodes->_M_left = 0; |
526 | } |
527 | else |
528 | _M_root = 0; |
529 | |
530 | return __node; |
531 | } |
532 | |
533 | _Base_ptr _M_root; |
534 | _Base_ptr _M_nodes; |
535 | _Rb_tree& _M_t; |
536 | }; |
537 | |
538 | // Functor similar to the previous one but without any pool of nodes to |
539 | // recycle. |
540 | struct _Alloc_node |
541 | { |
542 | _Alloc_node(_Rb_tree& __t) |
543 | : _M_t(__t) { } |
544 | |
545 | template<typename _Arg> |
546 | _Link_type |
547 | #if __cplusplus201703L < 201103L |
548 | operator()(const _Arg& __arg) const |
549 | #else |
550 | operator()(_Arg&& __arg) const |
551 | #endif |
552 | { return _M_t._M_create_node(_GLIBCXX_FORWARD(_Arg, __arg)std::forward<_Arg>(__arg)); } |
553 | |
554 | private: |
555 | _Rb_tree& _M_t; |
556 | }; |
557 | |
558 | public: |
559 | typedef _Key key_type; |
560 | typedef _Val value_type; |
561 | typedef value_type* pointer; |
562 | typedef const value_type* const_pointer; |
563 | typedef value_type& reference; |
564 | typedef const value_type& const_reference; |
565 | typedef size_t size_type; |
566 | typedef ptrdiff_t difference_type; |
567 | typedef _Alloc allocator_type; |
568 | |
569 | _Node_allocator& |
570 | _M_get_Node_allocator() _GLIBCXX_NOEXCEPTnoexcept |
571 | { return this->_M_impl; } |
572 | |
573 | const _Node_allocator& |
574 | _M_get_Node_allocator() const _GLIBCXX_NOEXCEPTnoexcept |
575 | { return this->_M_impl; } |
576 | |
577 | allocator_type |
578 | get_allocator() const _GLIBCXX_NOEXCEPTnoexcept |
579 | { return allocator_type(_M_get_Node_allocator()); } |
580 | |
581 | protected: |
582 | _Link_type |
583 | _M_get_node() |
584 | { return _Alloc_traits::allocate(_M_get_Node_allocator(), 1); } |
585 | |
586 | void |
587 | _M_put_node(_Link_type __p) _GLIBCXX_NOEXCEPTnoexcept |
588 | { _Alloc_traits::deallocate(_M_get_Node_allocator(), __p, 1); } |
589 | |
590 | #if __cplusplus201703L < 201103L |
591 | void |
592 | _M_construct_node(_Link_type __node, const value_type& __x) |
593 | { |
594 | __trytry |
595 | { get_allocator().construct(__node->_M_valptr(), __x); } |
596 | __catch(...)catch(...) |
597 | { |
598 | _M_put_node(__node); |
599 | __throw_exception_againthrow; |
600 | } |
601 | } |
602 | |
603 | _Link_type |
604 | _M_create_node(const value_type& __x) |
605 | { |
606 | _Link_type __tmp = _M_get_node(); |
607 | _M_construct_node(__tmp, __x); |
608 | return __tmp; |
609 | } |
610 | #else |
611 | template<typename... _Args> |
612 | void |
613 | _M_construct_node(_Link_type __node, _Args&&... __args) |
614 | { |
615 | __trytry |
616 | { |
617 | ::new(__node) _Rb_tree_node<_Val>; |
618 | _Alloc_traits::construct(_M_get_Node_allocator(), |
619 | __node->_M_valptr(), |
620 | std::forward<_Args>(__args)...); |
621 | } |
622 | __catch(...)catch(...) |
623 | { |
624 | __node->~_Rb_tree_node<_Val>(); |
625 | _M_put_node(__node); |
626 | __throw_exception_againthrow; |
627 | } |
628 | } |
629 | |
630 | template<typename... _Args> |
631 | _Link_type |
632 | _M_create_node(_Args&&... __args) |
633 | { |
634 | _Link_type __tmp = _M_get_node(); |
635 | _M_construct_node(__tmp, std::forward<_Args>(__args)...); |
636 | return __tmp; |
637 | } |
638 | #endif |
639 | |
640 | void |
641 | _M_destroy_node(_Link_type __p) _GLIBCXX_NOEXCEPTnoexcept |
642 | { |
643 | #if __cplusplus201703L < 201103L |
644 | get_allocator().destroy(__p->_M_valptr()); |
645 | #else |
646 | _Alloc_traits::destroy(_M_get_Node_allocator(), __p->_M_valptr()); |
647 | __p->~_Rb_tree_node<_Val>(); |
648 | #endif |
649 | } |
650 | |
651 | void |
652 | _M_drop_node(_Link_type __p) _GLIBCXX_NOEXCEPTnoexcept |
653 | { |
654 | _M_destroy_node(__p); |
655 | _M_put_node(__p); |
656 | } |
657 | |
658 | template<typename _NodeGen> |
659 | _Link_type |
660 | _M_clone_node(_Const_Link_type __x, _NodeGen& __node_gen) |
661 | { |
662 | _Link_type __tmp = __node_gen(*__x->_M_valptr()); |
663 | __tmp->_M_color = __x->_M_color; |
664 | __tmp->_M_left = 0; |
665 | __tmp->_M_right = 0; |
666 | return __tmp; |
667 | } |
668 | |
669 | protected: |
670 | #if _GLIBCXX_INLINE_VERSION0 |
671 | template<typename _Key_compare> |
672 | #else |
673 | // Unused _Is_pod_comparator is kept as it is part of mangled name. |
674 | template<typename _Key_compare, |
675 | bool /* _Is_pod_comparator */ = __is_pod(_Key_compare)> |
676 | #endif |
677 | struct _Rb_tree_impl |
678 | : public _Node_allocator |
679 | , public _Rb_tree_key_compare<_Key_compare> |
680 | , public _Rb_tree_header |
681 | { |
682 | typedef _Rb_tree_key_compare<_Key_compare> _Base_key_compare; |
683 | |
684 | _Rb_tree_impl() |
685 | _GLIBCXX_NOEXCEPT_IF(noexcept(is_nothrow_default_constructible<_Node_allocator> ::value && is_nothrow_default_constructible<_Base_key_compare >::value) |
686 | is_nothrow_default_constructible<_Node_allocator>::valuenoexcept(is_nothrow_default_constructible<_Node_allocator> ::value && is_nothrow_default_constructible<_Base_key_compare >::value) |
687 | && is_nothrow_default_constructible<_Base_key_compare>::value )noexcept(is_nothrow_default_constructible<_Node_allocator> ::value && is_nothrow_default_constructible<_Base_key_compare >::value) |
688 | : _Node_allocator() |
689 | { } |
690 | |
691 | _Rb_tree_impl(const _Rb_tree_impl& __x) |
692 | : _Node_allocator(_Alloc_traits::_S_select_on_copy(__x)) |
693 | , _Base_key_compare(__x._M_key_compare) |
694 | { } |
695 | |
696 | #if __cplusplus201703L < 201103L |
697 | _Rb_tree_impl(const _Key_compare& __comp, const _Node_allocator& __a) |
698 | : _Node_allocator(__a), _Base_key_compare(__comp) |
699 | { } |
700 | #else |
701 | _Rb_tree_impl(_Rb_tree_impl&&) = default; |
702 | |
703 | explicit |
704 | _Rb_tree_impl(_Node_allocator&& __a) |
705 | : _Node_allocator(std::move(__a)) |
706 | { } |
707 | |
708 | _Rb_tree_impl(_Rb_tree_impl&& __x, _Node_allocator&& __a) |
709 | : _Node_allocator(std::move(__a)), |
710 | _Base_key_compare(std::move(__x)), |
711 | _Rb_tree_header(std::move(__x)) |
712 | { } |
713 | |
714 | _Rb_tree_impl(const _Key_compare& __comp, _Node_allocator&& __a) |
715 | : _Node_allocator(std::move(__a)), _Base_key_compare(__comp) |
716 | { } |
717 | #endif |
718 | }; |
719 | |
720 | _Rb_tree_impl<_Compare> _M_impl; |
721 | |
722 | protected: |
723 | _Base_ptr& |
724 | _M_root() _GLIBCXX_NOEXCEPTnoexcept |
725 | { return this->_M_impl._M_header._M_parent; } |
726 | |
727 | _Const_Base_ptr |
728 | _M_root() const _GLIBCXX_NOEXCEPTnoexcept |
729 | { return this->_M_impl._M_header._M_parent; } |
730 | |
731 | _Base_ptr& |
732 | _M_leftmost() _GLIBCXX_NOEXCEPTnoexcept |
733 | { return this->_M_impl._M_header._M_left; } |
734 | |
735 | _Const_Base_ptr |
736 | _M_leftmost() const _GLIBCXX_NOEXCEPTnoexcept |
737 | { return this->_M_impl._M_header._M_left; } |
738 | |
739 | _Base_ptr& |
740 | _M_rightmost() _GLIBCXX_NOEXCEPTnoexcept |
741 | { return this->_M_impl._M_header._M_right; } |
742 | |
743 | _Const_Base_ptr |
744 | _M_rightmost() const _GLIBCXX_NOEXCEPTnoexcept |
745 | { return this->_M_impl._M_header._M_right; } |
746 | |
747 | _Link_type |
748 | _M_begin() _GLIBCXX_NOEXCEPTnoexcept |
749 | { return static_cast<_Link_type>(this->_M_impl._M_header._M_parent); } |
750 | |
751 | _Const_Link_type |
752 | _M_begin() const _GLIBCXX_NOEXCEPTnoexcept |
753 | { |
754 | return static_cast<_Const_Link_type> |
755 | (this->_M_impl._M_header._M_parent); |
756 | } |
757 | |
758 | _Base_ptr |
759 | _M_end() _GLIBCXX_NOEXCEPTnoexcept |
760 | { return &this->_M_impl._M_header; } |
761 | |
762 | _Const_Base_ptr |
763 | _M_end() const _GLIBCXX_NOEXCEPTnoexcept |
764 | { return &this->_M_impl._M_header; } |
765 | |
766 | static const _Key& |
767 | _S_key(_Const_Link_type __x) |
768 | { |
769 | #if __cplusplus201703L >= 201103L |
770 | // If we're asking for the key we're presumably using the comparison |
771 | // object, and so this is a good place to sanity check it. |
772 | static_assert(__is_invocable<_Compare&, const _Key&, const _Key&>{}, |
773 | "comparison object must be invocable " |
774 | "with two arguments of key type"); |
775 | # if __cplusplus201703L >= 201703L |
776 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
777 | // 2542. Missing const requirements for associative containers |
778 | if constexpr (__is_invocable<_Compare&, const _Key&, const _Key&>{}) |
779 | static_assert( |
780 | is_invocable_v<const _Compare&, const _Key&, const _Key&>, |
781 | "comparison object must be invocable as const"); |
782 | # endif // C++17 |
783 | #endif // C++11 |
784 | |
785 | return _KeyOfValue()(*__x->_M_valptr()); |
786 | } |
787 | |
788 | static _Link_type |
789 | _S_left(_Base_ptr __x) _GLIBCXX_NOEXCEPTnoexcept |
790 | { return static_cast<_Link_type>(__x->_M_left); } |
791 | |
792 | static _Const_Link_type |
793 | _S_left(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPTnoexcept |
794 | { return static_cast<_Const_Link_type>(__x->_M_left); } |
795 | |
796 | static _Link_type |
797 | _S_right(_Base_ptr __x) _GLIBCXX_NOEXCEPTnoexcept |
798 | { return static_cast<_Link_type>(__x->_M_right); } |
799 | |
800 | static _Const_Link_type |
801 | _S_right(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPTnoexcept |
802 | { return static_cast<_Const_Link_type>(__x->_M_right); } |
803 | |
804 | static const _Key& |
805 | _S_key(_Const_Base_ptr __x) |
806 | { return _S_key(static_cast<_Const_Link_type>(__x)); } |
807 | |
808 | static _Base_ptr |
809 | _S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPTnoexcept |
810 | { return _Rb_tree_node_base::_S_minimum(__x); } |
811 | |
812 | static _Const_Base_ptr |
813 | _S_minimum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPTnoexcept |
814 | { return _Rb_tree_node_base::_S_minimum(__x); } |
815 | |
816 | static _Base_ptr |
817 | _S_maximum(_Base_ptr __x) _GLIBCXX_NOEXCEPTnoexcept |
818 | { return _Rb_tree_node_base::_S_maximum(__x); } |
819 | |
820 | static _Const_Base_ptr |
821 | _S_maximum(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPTnoexcept |
822 | { return _Rb_tree_node_base::_S_maximum(__x); } |
823 | |
824 | public: |
825 | typedef _Rb_tree_iterator<value_type> iterator; |
826 | typedef _Rb_tree_const_iterator<value_type> const_iterator; |
827 | |
828 | typedef std::reverse_iterator<iterator> reverse_iterator; |
829 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
830 | |
831 | #if __cplusplus201703L > 201402L |
832 | using node_type = _Node_handle<_Key, _Val, _Node_allocator>; |
833 | using insert_return_type = _Node_insert_return< |
834 | conditional_t<is_same_v<_Key, _Val>, const_iterator, iterator>, |
835 | node_type>; |
836 | #endif |
837 | |
838 | pair<_Base_ptr, _Base_ptr> |
839 | _M_get_insert_unique_pos(const key_type& __k); |
840 | |
841 | pair<_Base_ptr, _Base_ptr> |
842 | _M_get_insert_equal_pos(const key_type& __k); |
843 | |
844 | pair<_Base_ptr, _Base_ptr> |
845 | _M_get_insert_hint_unique_pos(const_iterator __pos, |
846 | const key_type& __k); |
847 | |
848 | pair<_Base_ptr, _Base_ptr> |
849 | _M_get_insert_hint_equal_pos(const_iterator __pos, |
850 | const key_type& __k); |
851 | |
852 | private: |
853 | #if __cplusplus201703L >= 201103L |
854 | template<typename _Arg, typename _NodeGen> |
855 | iterator |
856 | _M_insert_(_Base_ptr __x, _Base_ptr __y, _Arg&& __v, _NodeGen&); |
857 | |
858 | iterator |
859 | _M_insert_node(_Base_ptr __x, _Base_ptr __y, _Link_type __z); |
860 | |
861 | template<typename _Arg> |
862 | iterator |
863 | _M_insert_lower(_Base_ptr __y, _Arg&& __v); |
864 | |
865 | template<typename _Arg> |
866 | iterator |
867 | _M_insert_equal_lower(_Arg&& __x); |
868 | |
869 | iterator |
870 | _M_insert_lower_node(_Base_ptr __p, _Link_type __z); |
871 | |
872 | iterator |
873 | _M_insert_equal_lower_node(_Link_type __z); |
874 | #else |
875 | template<typename _NodeGen> |
876 | iterator |
877 | _M_insert_(_Base_ptr __x, _Base_ptr __y, |
878 | const value_type& __v, _NodeGen&); |
879 | |
880 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
881 | // 233. Insertion hints in associative containers. |
882 | iterator |
883 | _M_insert_lower(_Base_ptr __y, const value_type& __v); |
884 | |
885 | iterator |
886 | _M_insert_equal_lower(const value_type& __x); |
887 | #endif |
888 | |
889 | template<typename _NodeGen> |
890 | _Link_type |
891 | _M_copy(_Const_Link_type __x, _Base_ptr __p, _NodeGen&); |
892 | |
893 | template<typename _NodeGen> |
894 | _Link_type |
895 | _M_copy(const _Rb_tree& __x, _NodeGen& __gen) |
896 | { |
897 | _Link_type __root = _M_copy(__x._M_begin(), _M_end(), __gen); |
898 | _M_leftmost() = _S_minimum(__root); |
899 | _M_rightmost() = _S_maximum(__root); |
900 | _M_impl._M_node_count = __x._M_impl._M_node_count; |
901 | return __root; |
902 | } |
903 | |
904 | _Link_type |
905 | _M_copy(const _Rb_tree& __x) |
906 | { |
907 | _Alloc_node __an(*this); |
908 | return _M_copy(__x, __an); |
909 | } |
910 | |
911 | void |
912 | _M_erase(_Link_type __x); |
913 | |
914 | iterator |
915 | _M_lower_bound(_Link_type __x, _Base_ptr __y, |
916 | const _Key& __k); |
917 | |
918 | const_iterator |
919 | _M_lower_bound(_Const_Link_type __x, _Const_Base_ptr __y, |
920 | const _Key& __k) const; |
921 | |
922 | iterator |
923 | _M_upper_bound(_Link_type __x, _Base_ptr __y, |
924 | const _Key& __k); |
925 | |
926 | const_iterator |
927 | _M_upper_bound(_Const_Link_type __x, _Const_Base_ptr __y, |
928 | const _Key& __k) const; |
929 | |
930 | public: |
931 | // allocation/deallocation |
932 | #if __cplusplus201703L < 201103L |
933 | _Rb_tree() { } |
934 | #else |
935 | _Rb_tree() = default; |
936 | #endif |
937 | |
938 | _Rb_tree(const _Compare& __comp, |
939 | const allocator_type& __a = allocator_type()) |
940 | : _M_impl(__comp, _Node_allocator(__a)) { } |
941 | |
942 | _Rb_tree(const _Rb_tree& __x) |
943 | : _M_impl(__x._M_impl) |
944 | { |
945 | if (__x._M_root() != 0) |
946 | _M_root() = _M_copy(__x); |
947 | } |
948 | |
949 | #if __cplusplus201703L >= 201103L |
950 | _Rb_tree(const allocator_type& __a) |
951 | : _M_impl(_Node_allocator(__a)) |
952 | { } |
953 | |
954 | _Rb_tree(const _Rb_tree& __x, const allocator_type& __a) |
955 | : _M_impl(__x._M_impl._M_key_compare, _Node_allocator(__a)) |
956 | { |
957 | if (__x._M_root() != nullptr) |
958 | _M_root() = _M_copy(__x); |
959 | } |
960 | |
961 | _Rb_tree(_Rb_tree&&) = default; |
962 | |
963 | _Rb_tree(_Rb_tree&& __x, const allocator_type& __a) |
964 | : _Rb_tree(std::move(__x), _Node_allocator(__a)) |
965 | { } |
966 | |
967 | private: |
968 | _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a, true_type) |
969 | noexcept(is_nothrow_default_constructible<_Compare>::value) |
970 | : _M_impl(std::move(__x._M_impl), std::move(__a)) |
971 | { } |
972 | |
973 | _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a, false_type) |
974 | : _M_impl(__x._M_impl._M_key_compare, std::move(__a)) |
975 | { |
976 | if (__x._M_root() != nullptr) |
977 | _M_move_data(__x, false_type{}); |
978 | } |
979 | |
980 | public: |
981 | _Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a) |
982 | noexcept( noexcept( |
983 | _Rb_tree(std::declval<_Rb_tree&&>(), std::declval<_Node_allocator&&>(), |
984 | std::declval<typename _Alloc_traits::is_always_equal>())) ) |
985 | : _Rb_tree(std::move(__x), std::move(__a), |
986 | typename _Alloc_traits::is_always_equal{}) |
987 | { } |
988 | #endif |
989 | |
990 | ~_Rb_tree() _GLIBCXX_NOEXCEPTnoexcept |
991 | { _M_erase(_M_begin()); } |
992 | |
993 | _Rb_tree& |
994 | operator=(const _Rb_tree& __x); |
995 | |
996 | // Accessors. |
997 | _Compare |
998 | key_comp() const |
999 | { return _M_impl._M_key_compare; } |
1000 | |
1001 | iterator |
1002 | begin() _GLIBCXX_NOEXCEPTnoexcept |
1003 | { return iterator(this->_M_impl._M_header._M_left); } |
1004 | |
1005 | const_iterator |
1006 | begin() const _GLIBCXX_NOEXCEPTnoexcept |
1007 | { return const_iterator(this->_M_impl._M_header._M_left); } |
1008 | |
1009 | iterator |
1010 | end() _GLIBCXX_NOEXCEPTnoexcept |
1011 | { return iterator(&this->_M_impl._M_header); } |
1012 | |
1013 | const_iterator |
1014 | end() const _GLIBCXX_NOEXCEPTnoexcept |
1015 | { return const_iterator(&this->_M_impl._M_header); } |
1016 | |
1017 | reverse_iterator |
1018 | rbegin() _GLIBCXX_NOEXCEPTnoexcept |
1019 | { return reverse_iterator(end()); } |
1020 | |
1021 | const_reverse_iterator |
1022 | rbegin() const _GLIBCXX_NOEXCEPTnoexcept |
1023 | { return const_reverse_iterator(end()); } |
1024 | |
1025 | reverse_iterator |
1026 | rend() _GLIBCXX_NOEXCEPTnoexcept |
1027 | { return reverse_iterator(begin()); } |
1028 | |
1029 | const_reverse_iterator |
1030 | rend() const _GLIBCXX_NOEXCEPTnoexcept |
1031 | { return const_reverse_iterator(begin()); } |
1032 | |
1033 | _GLIBCXX_NODISCARD[[__nodiscard__]] bool |
1034 | empty() const _GLIBCXX_NOEXCEPTnoexcept |
1035 | { return _M_impl._M_node_count == 0; } |
1036 | |
1037 | size_type |
1038 | size() const _GLIBCXX_NOEXCEPTnoexcept |
1039 | { return _M_impl._M_node_count; } |
1040 | |
1041 | size_type |
1042 | max_size() const _GLIBCXX_NOEXCEPTnoexcept |
1043 | { return _Alloc_traits::max_size(_M_get_Node_allocator()); } |
1044 | |
1045 | void |
1046 | swap(_Rb_tree& __t) |
1047 | _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)noexcept(__is_nothrow_swappable<_Compare>::value); |
1048 | |
1049 | // Insert/erase. |
1050 | #if __cplusplus201703L >= 201103L |
1051 | template<typename _Arg> |
1052 | pair<iterator, bool> |
1053 | _M_insert_unique(_Arg&& __x); |
1054 | |
1055 | template<typename _Arg> |
1056 | iterator |
1057 | _M_insert_equal(_Arg&& __x); |
1058 | |
1059 | template<typename _Arg, typename _NodeGen> |
1060 | iterator |
1061 | _M_insert_unique_(const_iterator __pos, _Arg&& __x, _NodeGen&); |
1062 | |
1063 | template<typename _Arg> |
1064 | iterator |
1065 | _M_insert_unique_(const_iterator __pos, _Arg&& __x) |
1066 | { |
1067 | _Alloc_node __an(*this); |
1068 | return _M_insert_unique_(__pos, std::forward<_Arg>(__x), __an); |
1069 | } |
1070 | |
1071 | template<typename _Arg, typename _NodeGen> |
1072 | iterator |
1073 | _M_insert_equal_(const_iterator __pos, _Arg&& __x, _NodeGen&); |
1074 | |
1075 | template<typename _Arg> |
1076 | iterator |
1077 | _M_insert_equal_(const_iterator __pos, _Arg&& __x) |
1078 | { |
1079 | _Alloc_node __an(*this); |
1080 | return _M_insert_equal_(__pos, std::forward<_Arg>(__x), __an); |
1081 | } |
1082 | |
1083 | template<typename... _Args> |
1084 | pair<iterator, bool> |
1085 | _M_emplace_unique(_Args&&... __args); |
1086 | |
1087 | template<typename... _Args> |
1088 | iterator |
1089 | _M_emplace_equal(_Args&&... __args); |
1090 | |
1091 | template<typename... _Args> |
1092 | iterator |
1093 | _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args); |
1094 | |
1095 | template<typename... _Args> |
1096 | iterator |
1097 | _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args); |
1098 | |
1099 | template<typename _Iter> |
1100 | using __same_value_type |
1101 | = is_same<value_type, typename iterator_traits<_Iter>::value_type>; |
1102 | |
1103 | template<typename _InputIterator> |
1104 | __enable_if_t<__same_value_type<_InputIterator>::value> |
1105 | _M_insert_range_unique(_InputIterator __first, _InputIterator __last) |
1106 | { |
1107 | _Alloc_node __an(*this); |
1108 | for (; __first != __last; ++__first) |
1109 | _M_insert_unique_(end(), *__first, __an); |
1110 | } |
1111 | |
1112 | template<typename _InputIterator> |
1113 | __enable_if_t<!__same_value_type<_InputIterator>::value> |
1114 | _M_insert_range_unique(_InputIterator __first, _InputIterator __last) |
1115 | { |
1116 | for (; __first != __last; ++__first) |
1117 | _M_emplace_unique(*__first); |
1118 | } |
1119 | |
1120 | template<typename _InputIterator> |
1121 | __enable_if_t<__same_value_type<_InputIterator>::value> |
1122 | _M_insert_range_equal(_InputIterator __first, _InputIterator __last) |
1123 | { |
1124 | _Alloc_node __an(*this); |
1125 | for (; __first != __last; ++__first) |
1126 | _M_insert_equal_(end(), *__first, __an); |
1127 | } |
1128 | |
1129 | template<typename _InputIterator> |
1130 | __enable_if_t<!__same_value_type<_InputIterator>::value> |
1131 | _M_insert_range_equal(_InputIterator __first, _InputIterator __last) |
1132 | { |
1133 | _Alloc_node __an(*this); |
1134 | for (; __first != __last; ++__first) |
1135 | _M_emplace_equal(*__first); |
1136 | } |
1137 | #else |
1138 | pair<iterator, bool> |
1139 | _M_insert_unique(const value_type& __x); |
1140 | |
1141 | iterator |
1142 | _M_insert_equal(const value_type& __x); |
1143 | |
1144 | template<typename _NodeGen> |
1145 | iterator |
1146 | _M_insert_unique_(const_iterator __pos, const value_type& __x, |
1147 | _NodeGen&); |
1148 | |
1149 | iterator |
1150 | _M_insert_unique_(const_iterator __pos, const value_type& __x) |
1151 | { |
1152 | _Alloc_node __an(*this); |
1153 | return _M_insert_unique_(__pos, __x, __an); |
1154 | } |
1155 | |
1156 | template<typename _NodeGen> |
1157 | iterator |
1158 | _M_insert_equal_(const_iterator __pos, const value_type& __x, |
1159 | _NodeGen&); |
1160 | iterator |
1161 | _M_insert_equal_(const_iterator __pos, const value_type& __x) |
1162 | { |
1163 | _Alloc_node __an(*this); |
1164 | return _M_insert_equal_(__pos, __x, __an); |
1165 | } |
1166 | |
1167 | template<typename _InputIterator> |
1168 | void |
1169 | _M_insert_range_unique(_InputIterator __first, _InputIterator __last) |
1170 | { |
1171 | _Alloc_node __an(*this); |
1172 | for (; __first != __last; ++__first) |
1173 | _M_insert_unique_(end(), *__first, __an); |
1174 | } |
1175 | |
1176 | template<typename _InputIterator> |
1177 | void |
1178 | _M_insert_range_equal(_InputIterator __first, _InputIterator __last) |
1179 | { |
1180 | _Alloc_node __an(*this); |
1181 | for (; __first != __last; ++__first) |
1182 | _M_insert_equal_(end(), *__first, __an); |
1183 | } |
1184 | #endif |
1185 | |
1186 | private: |
1187 | void |
1188 | _M_erase_aux(const_iterator __position); |
1189 | |
1190 | void |
1191 | _M_erase_aux(const_iterator __first, const_iterator __last); |
1192 | |
1193 | public: |
1194 | #if __cplusplus201703L >= 201103L |
1195 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
1196 | // DR 130. Associative erase should return an iterator. |
1197 | _GLIBCXX_ABI_TAG_CXX11__attribute ((__abi_tag__ ("cxx11"))) |
1198 | iterator |
1199 | erase(const_iterator __position) |
1200 | { |
1201 | __glibcxx_assert(__position != end()); |
1202 | const_iterator __result = __position; |
1203 | ++__result; |
1204 | _M_erase_aux(__position); |
1205 | return __result._M_const_cast(); |
1206 | } |
1207 | |
1208 | // LWG 2059. |
1209 | _GLIBCXX_ABI_TAG_CXX11__attribute ((__abi_tag__ ("cxx11"))) |
1210 | iterator |
1211 | erase(iterator __position) |
1212 | { |
1213 | __glibcxx_assert(__position != end()); |
1214 | iterator __result = __position; |
1215 | ++__result; |
1216 | _M_erase_aux(__position); |
1217 | return __result; |
1218 | } |
1219 | #else |
1220 | void |
1221 | erase(iterator __position) |
1222 | { |
1223 | __glibcxx_assert(__position != end()); |
1224 | _M_erase_aux(__position); |
1225 | } |
1226 | |
1227 | void |
1228 | erase(const_iterator __position) |
1229 | { |
1230 | __glibcxx_assert(__position != end()); |
1231 | _M_erase_aux(__position); |
1232 | } |
1233 | #endif |
1234 | |
1235 | size_type |
1236 | erase(const key_type& __x); |
1237 | |
1238 | #if __cplusplus201703L >= 201103L |
1239 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
1240 | // DR 130. Associative erase should return an iterator. |
1241 | _GLIBCXX_ABI_TAG_CXX11__attribute ((__abi_tag__ ("cxx11"))) |
1242 | iterator |
1243 | erase(const_iterator __first, const_iterator __last) |
1244 | { |
1245 | _M_erase_aux(__first, __last); |
1246 | return __last._M_const_cast(); |
1247 | } |
1248 | #else |
1249 | void |
1250 | erase(iterator __first, iterator __last) |
1251 | { _M_erase_aux(__first, __last); } |
1252 | |
1253 | void |
1254 | erase(const_iterator __first, const_iterator __last) |
1255 | { _M_erase_aux(__first, __last); } |
1256 | #endif |
1257 | |
1258 | void |
1259 | clear() _GLIBCXX_NOEXCEPTnoexcept |
1260 | { |
1261 | _M_erase(_M_begin()); |
1262 | _M_impl._M_reset(); |
1263 | } |
1264 | |
1265 | // Set operations. |
1266 | iterator |
1267 | find(const key_type& __k); |
1268 | |
1269 | const_iterator |
1270 | find(const key_type& __k) const; |
1271 | |
1272 | size_type |
1273 | count(const key_type& __k) const; |
1274 | |
1275 | iterator |
1276 | lower_bound(const key_type& __k) |
1277 | { return _M_lower_bound(_M_begin(), _M_end(), __k); } |
1278 | |
1279 | const_iterator |
1280 | lower_bound(const key_type& __k) const |
1281 | { return _M_lower_bound(_M_begin(), _M_end(), __k); } |
1282 | |
1283 | iterator |
1284 | upper_bound(const key_type& __k) |
1285 | { return _M_upper_bound(_M_begin(), _M_end(), __k); } |
1286 | |
1287 | const_iterator |
1288 | upper_bound(const key_type& __k) const |
1289 | { return _M_upper_bound(_M_begin(), _M_end(), __k); } |
1290 | |
1291 | pair<iterator, iterator> |
1292 | equal_range(const key_type& __k); |
1293 | |
1294 | pair<const_iterator, const_iterator> |
1295 | equal_range(const key_type& __k) const; |
1296 | |
1297 | #if __cplusplus201703L >= 201402L |
1298 | template<typename _Kt, |
1299 | typename _Req = __has_is_transparent_t<_Compare, _Kt>> |
1300 | iterator |
1301 | _M_find_tr(const _Kt& __k) |
1302 | { |
1303 | const _Rb_tree* __const_this = this; |
1304 | return __const_this->_M_find_tr(__k)._M_const_cast(); |
1305 | } |
1306 | |
1307 | template<typename _Kt, |
1308 | typename _Req = __has_is_transparent_t<_Compare, _Kt>> |
1309 | const_iterator |
1310 | _M_find_tr(const _Kt& __k) const |
1311 | { |
1312 | auto __j = _M_lower_bound_tr(__k); |
1313 | if (__j != end() && _M_impl._M_key_compare(__k, _S_key(__j._M_node))) |
1314 | __j = end(); |
1315 | return __j; |
1316 | } |
1317 | |
1318 | template<typename _Kt, |
1319 | typename _Req = __has_is_transparent_t<_Compare, _Kt>> |
1320 | size_type |
1321 | _M_count_tr(const _Kt& __k) const |
1322 | { |
1323 | auto __p = _M_equal_range_tr(__k); |
1324 | return std::distance(__p.first, __p.second); |
1325 | } |
1326 | |
1327 | template<typename _Kt, |
1328 | typename _Req = __has_is_transparent_t<_Compare, _Kt>> |
1329 | iterator |
1330 | _M_lower_bound_tr(const _Kt& __k) |
1331 | { |
1332 | const _Rb_tree* __const_this = this; |
1333 | return __const_this->_M_lower_bound_tr(__k)._M_const_cast(); |
1334 | } |
1335 | |
1336 | template<typename _Kt, |
1337 | typename _Req = __has_is_transparent_t<_Compare, _Kt>> |
1338 | const_iterator |
1339 | _M_lower_bound_tr(const _Kt& __k) const |
1340 | { |
1341 | auto __x = _M_begin(); |
1342 | auto __y = _M_end(); |
1343 | while (__x != 0) |
1344 | if (!_M_impl._M_key_compare(_S_key(__x), __k)) |
1345 | { |
1346 | __y = __x; |
1347 | __x = _S_left(__x); |
1348 | } |
1349 | else |
1350 | __x = _S_right(__x); |
1351 | return const_iterator(__y); |
1352 | } |
1353 | |
1354 | template<typename _Kt, |
1355 | typename _Req = __has_is_transparent_t<_Compare, _Kt>> |
1356 | iterator |
1357 | _M_upper_bound_tr(const _Kt& __k) |
1358 | { |
1359 | const _Rb_tree* __const_this = this; |
1360 | return __const_this->_M_upper_bound_tr(__k)._M_const_cast(); |
1361 | } |
1362 | |
1363 | template<typename _Kt, |
1364 | typename _Req = __has_is_transparent_t<_Compare, _Kt>> |
1365 | const_iterator |
1366 | _M_upper_bound_tr(const _Kt& __k) const |
1367 | { |
1368 | auto __x = _M_begin(); |
1369 | auto __y = _M_end(); |
1370 | while (__x != 0) |
1371 | if (_M_impl._M_key_compare(__k, _S_key(__x))) |
1372 | { |
1373 | __y = __x; |
1374 | __x = _S_left(__x); |
1375 | } |
1376 | else |
1377 | __x = _S_right(__x); |
1378 | return const_iterator(__y); |
1379 | } |
1380 | |
1381 | template<typename _Kt, |
1382 | typename _Req = __has_is_transparent_t<_Compare, _Kt>> |
1383 | pair<iterator, iterator> |
1384 | _M_equal_range_tr(const _Kt& __k) |
1385 | { |
1386 | const _Rb_tree* __const_this = this; |
1387 | auto __ret = __const_this->_M_equal_range_tr(__k); |
1388 | return { __ret.first._M_const_cast(), __ret.second._M_const_cast() }; |
1389 | } |
1390 | |
1391 | template<typename _Kt, |
1392 | typename _Req = __has_is_transparent_t<_Compare, _Kt>> |
1393 | pair<const_iterator, const_iterator> |
1394 | _M_equal_range_tr(const _Kt& __k) const |
1395 | { |
1396 | auto __low = _M_lower_bound_tr(__k); |
1397 | auto __high = __low; |
1398 | auto& __cmp = _M_impl._M_key_compare; |
1399 | while (__high != end() && !__cmp(__k, _S_key(__high._M_node))) |
1400 | ++__high; |
1401 | return { __low, __high }; |
1402 | } |
1403 | #endif |
1404 | |
1405 | // Debugging. |
1406 | bool |
1407 | __rb_verify() const; |
1408 | |
1409 | #if __cplusplus201703L >= 201103L |
1410 | _Rb_tree& |
1411 | operator=(_Rb_tree&&) |
1412 | noexcept(_Alloc_traits::_S_nothrow_move() |
1413 | && is_nothrow_move_assignable<_Compare>::value); |
1414 | |
1415 | template<typename _Iterator> |
1416 | void |
1417 | _M_assign_unique(_Iterator, _Iterator); |
1418 | |
1419 | template<typename _Iterator> |
1420 | void |
1421 | _M_assign_equal(_Iterator, _Iterator); |
1422 | |
1423 | private: |
1424 | // Move elements from container with equal allocator. |
1425 | void |
1426 | _M_move_data(_Rb_tree& __x, true_type) |
1427 | { _M_impl._M_move_data(__x._M_impl); } |
1428 | |
1429 | // Move elements from container with possibly non-equal allocator, |
1430 | // which might result in a copy not a move. |
1431 | void |
1432 | _M_move_data(_Rb_tree&, false_type); |
1433 | |
1434 | // Move assignment from container with equal allocator. |
1435 | void |
1436 | _M_move_assign(_Rb_tree&, true_type); |
1437 | |
1438 | // Move assignment from container with possibly non-equal allocator, |
1439 | // which might result in a copy not a move. |
1440 | void |
1441 | _M_move_assign(_Rb_tree&, false_type); |
1442 | #endif |
1443 | |
1444 | #if __cplusplus201703L > 201402L |
1445 | public: |
1446 | /// Re-insert an extracted node. |
1447 | insert_return_type |
1448 | _M_reinsert_node_unique(node_type&& __nh) |
1449 | { |
1450 | insert_return_type __ret; |
1451 | if (__nh.empty()) |
1452 | __ret.position = end(); |
1453 | else |
1454 | { |
1455 | __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc); |
1456 | |
1457 | auto __res = _M_get_insert_unique_pos(__nh._M_key()); |
1458 | if (__res.second) |
1459 | { |
1460 | __ret.position |
1461 | = _M_insert_node(__res.first, __res.second, __nh._M_ptr); |
1462 | __nh._M_ptr = nullptr; |
1463 | __ret.inserted = true; |
1464 | } |
1465 | else |
1466 | { |
1467 | __ret.node = std::move(__nh); |
1468 | __ret.position = iterator(__res.first); |
1469 | __ret.inserted = false; |
1470 | } |
1471 | } |
1472 | return __ret; |
1473 | } |
1474 | |
1475 | /// Re-insert an extracted node. |
1476 | iterator |
1477 | _M_reinsert_node_equal(node_type&& __nh) |
1478 | { |
1479 | iterator __ret; |
1480 | if (__nh.empty()) |
1481 | __ret = end(); |
1482 | else |
1483 | { |
1484 | __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc); |
1485 | auto __res = _M_get_insert_equal_pos(__nh._M_key()); |
1486 | if (__res.second) |
1487 | __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr); |
1488 | else |
1489 | __ret = _M_insert_equal_lower_node(__nh._M_ptr); |
1490 | __nh._M_ptr = nullptr; |
1491 | } |
1492 | return __ret; |
1493 | } |
1494 | |
1495 | /// Re-insert an extracted node. |
1496 | iterator |
1497 | _M_reinsert_node_hint_unique(const_iterator __hint, node_type&& __nh) |
1498 | { |
1499 | iterator __ret; |
1500 | if (__nh.empty()) |
1501 | __ret = end(); |
1502 | else |
1503 | { |
1504 | __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc); |
1505 | auto __res = _M_get_insert_hint_unique_pos(__hint, __nh._M_key()); |
1506 | if (__res.second) |
1507 | { |
1508 | __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr); |
1509 | __nh._M_ptr = nullptr; |
1510 | } |
1511 | else |
1512 | __ret = iterator(__res.first); |
1513 | } |
1514 | return __ret; |
1515 | } |
1516 | |
1517 | /// Re-insert an extracted node. |
1518 | iterator |
1519 | _M_reinsert_node_hint_equal(const_iterator __hint, node_type&& __nh) |
1520 | { |
1521 | iterator __ret; |
1522 | if (__nh.empty()) |
1523 | __ret = end(); |
1524 | else |
1525 | { |
1526 | __glibcxx_assert(_M_get_Node_allocator() == *__nh._M_alloc); |
1527 | auto __res = _M_get_insert_hint_equal_pos(__hint, __nh._M_key()); |
1528 | if (__res.second) |
1529 | __ret = _M_insert_node(__res.first, __res.second, __nh._M_ptr); |
1530 | else |
1531 | __ret = _M_insert_equal_lower_node(__nh._M_ptr); |
1532 | __nh._M_ptr = nullptr; |
1533 | } |
1534 | return __ret; |
1535 | } |
1536 | |
1537 | /// Extract a node. |
1538 | node_type |
1539 | extract(const_iterator __pos) |
1540 | { |
1541 | auto __ptr = _Rb_tree_rebalance_for_erase( |
1542 | __pos._M_const_cast()._M_node, _M_impl._M_header); |
1543 | --_M_impl._M_node_count; |
1544 | return { static_cast<_Link_type>(__ptr), _M_get_Node_allocator() }; |
1545 | } |
1546 | |
1547 | /// Extract a node. |
1548 | node_type |
1549 | extract(const key_type& __k) |
1550 | { |
1551 | node_type __nh; |
1552 | auto __pos = find(__k); |
1553 | if (__pos != end()) |
1554 | __nh = extract(const_iterator(__pos)); |
1555 | return __nh; |
1556 | } |
1557 | |
1558 | template<typename _Compare2> |
1559 | using _Compatible_tree |
1560 | = _Rb_tree<_Key, _Val, _KeyOfValue, _Compare2, _Alloc>; |
1561 | |
1562 | template<typename, typename> |
1563 | friend class _Rb_tree_merge_helper; |
1564 | |
1565 | /// Merge from a compatible container into one with unique keys. |
1566 | template<typename _Compare2> |
1567 | void |
1568 | _M_merge_unique(_Compatible_tree<_Compare2>& __src) noexcept |
1569 | { |
1570 | using _Merge_helper = _Rb_tree_merge_helper<_Rb_tree, _Compare2>; |
1571 | for (auto __i = __src.begin(), __end = __src.end(); __i != __end;) |
1572 | { |
1573 | auto __pos = __i++; |
1574 | auto __res = _M_get_insert_unique_pos(_KeyOfValue()(*__pos)); |
1575 | if (__res.second) |
1576 | { |
1577 | auto& __src_impl = _Merge_helper::_S_get_impl(__src); |
1578 | auto __ptr = _Rb_tree_rebalance_for_erase( |
1579 | __pos._M_node, __src_impl._M_header); |
1580 | --__src_impl._M_node_count; |
1581 | _M_insert_node(__res.first, __res.second, |
1582 | static_cast<_Link_type>(__ptr)); |
1583 | } |
1584 | } |
1585 | } |
1586 | |
1587 | /// Merge from a compatible container into one with equivalent keys. |
1588 | template<typename _Compare2> |
1589 | void |
1590 | _M_merge_equal(_Compatible_tree<_Compare2>& __src) noexcept |
1591 | { |
1592 | using _Merge_helper = _Rb_tree_merge_helper<_Rb_tree, _Compare2>; |
1593 | for (auto __i = __src.begin(), __end = __src.end(); __i != __end;) |
1594 | { |
1595 | auto __pos = __i++; |
1596 | auto __res = _M_get_insert_equal_pos(_KeyOfValue()(*__pos)); |
1597 | if (__res.second) |
1598 | { |
1599 | auto& __src_impl = _Merge_helper::_S_get_impl(__src); |
1600 | auto __ptr = _Rb_tree_rebalance_for_erase( |
1601 | __pos._M_node, __src_impl._M_header); |
1602 | --__src_impl._M_node_count; |
1603 | _M_insert_node(__res.first, __res.second, |
1604 | static_cast<_Link_type>(__ptr)); |
1605 | } |
1606 | } |
1607 | } |
1608 | #endif // C++17 |
1609 | |
1610 | friend bool |
1611 | operator==(const _Rb_tree& __x, const _Rb_tree& __y) |
1612 | { |
1613 | return __x.size() == __y.size() |
1614 | && std::equal(__x.begin(), __x.end(), __y.begin()); |
1615 | } |
1616 | |
1617 | #if __cpp_lib_three_way_comparison |
1618 | friend auto |
1619 | operator<=>(const _Rb_tree& __x, const _Rb_tree& __y) |
1620 | { |
1621 | if constexpr (requires { typename __detail::__synth3way_t<_Val>; }) |
1622 | return std::lexicographical_compare_three_way(__x.begin(), __x.end(), |
1623 | __y.begin(), __y.end(), |
1624 | __detail::__synth3way); |
1625 | } |
1626 | #else |
1627 | friend bool |
1628 | operator<(const _Rb_tree& __x, const _Rb_tree& __y) |
1629 | { |
1630 | return std::lexicographical_compare(__x.begin(), __x.end(), |
1631 | __y.begin(), __y.end()); |
1632 | } |
1633 | |
1634 | friend bool _GLIBCXX_DEPRECATED__attribute__ ((__deprecated__)) |
1635 | operator!=(const _Rb_tree& __x, const _Rb_tree& __y) |
1636 | { return !(__x == __y); } |
1637 | |
1638 | friend bool _GLIBCXX_DEPRECATED__attribute__ ((__deprecated__)) |
1639 | operator>(const _Rb_tree& __x, const _Rb_tree& __y) |
1640 | { return __y < __x; } |
1641 | |
1642 | friend bool _GLIBCXX_DEPRECATED__attribute__ ((__deprecated__)) |
1643 | operator<=(const _Rb_tree& __x, const _Rb_tree& __y) |
1644 | { return !(__y < __x); } |
1645 | |
1646 | friend bool _GLIBCXX_DEPRECATED__attribute__ ((__deprecated__)) |
1647 | operator>=(const _Rb_tree& __x, const _Rb_tree& __y) |
1648 | { return !(__x < __y); } |
1649 | #endif |
1650 | }; |
1651 | |
1652 | template<typename _Key, typename _Val, typename _KeyOfValue, |
1653 | typename _Compare, typename _Alloc> |
1654 | inline void |
1655 | swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x, |
1656 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y) |
1657 | { __x.swap(__y); } |
1658 | |
1659 | #if __cplusplus201703L >= 201103L |
1660 | template<typename _Key, typename _Val, typename _KeyOfValue, |
1661 | typename _Compare, typename _Alloc> |
1662 | void |
1663 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
1664 | _M_move_data(_Rb_tree& __x, false_type) |
1665 | { |
1666 | if (_M_get_Node_allocator() == __x._M_get_Node_allocator()) |
1667 | _M_move_data(__x, true_type()); |
1668 | else |
1669 | { |
1670 | _Alloc_node __an(*this); |
1671 | auto __lbd = |
1672 | [&__an](const value_type& __cval) |
1673 | { |
1674 | auto& __val = const_cast<value_type&>(__cval); |
1675 | return __an(std::move_if_noexcept(__val)); |
1676 | }; |
1677 | _M_root() = _M_copy(__x, __lbd); |
1678 | } |
1679 | } |
1680 | |
1681 | template<typename _Key, typename _Val, typename _KeyOfValue, |
1682 | typename _Compare, typename _Alloc> |
1683 | inline void |
1684 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
1685 | _M_move_assign(_Rb_tree& __x, true_type) |
1686 | { |
1687 | clear(); |
1688 | if (__x._M_root() != nullptr) |
1689 | _M_move_data(__x, true_type()); |
1690 | std::__alloc_on_move(_M_get_Node_allocator(), |
1691 | __x._M_get_Node_allocator()); |
1692 | } |
1693 | |
1694 | template<typename _Key, typename _Val, typename _KeyOfValue, |
1695 | typename _Compare, typename _Alloc> |
1696 | void |
1697 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
1698 | _M_move_assign(_Rb_tree& __x, false_type) |
1699 | { |
1700 | if (_M_get_Node_allocator() == __x._M_get_Node_allocator()) |
1701 | return _M_move_assign(__x, true_type{}); |
1702 | |
1703 | // Try to move each node reusing existing nodes and copying __x nodes |
1704 | // structure. |
1705 | _Reuse_or_alloc_node __roan(*this); |
1706 | _M_impl._M_reset(); |
1707 | if (__x._M_root() != nullptr) |
1708 | { |
1709 | auto __lbd = |
1710 | [&__roan](const value_type& __cval) |
1711 | { |
1712 | auto& __val = const_cast<value_type&>(__cval); |
1713 | return __roan(std::move(__val)); |
1714 | }; |
1715 | _M_root() = _M_copy(__x, __lbd); |
1716 | __x.clear(); |
1717 | } |
1718 | } |
1719 | |
1720 | template<typename _Key, typename _Val, typename _KeyOfValue, |
1721 | typename _Compare, typename _Alloc> |
1722 | inline _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& |
1723 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
1724 | operator=(_Rb_tree&& __x) |
1725 | noexcept(_Alloc_traits::_S_nothrow_move() |
1726 | && is_nothrow_move_assignable<_Compare>::value) |
1727 | { |
1728 | _M_impl._M_key_compare = std::move(__x._M_impl._M_key_compare); |
1729 | _M_move_assign(__x, __bool_constant<_Alloc_traits::_S_nothrow_move()>()); |
1730 | return *this; |
1731 | } |
1732 | |
1733 | template<typename _Key, typename _Val, typename _KeyOfValue, |
1734 | typename _Compare, typename _Alloc> |
1735 | template<typename _Iterator> |
1736 | void |
1737 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
1738 | _M_assign_unique(_Iterator __first, _Iterator __last) |
1739 | { |
1740 | _Reuse_or_alloc_node __roan(*this); |
1741 | _M_impl._M_reset(); |
1742 | for (; __first != __last; ++__first) |
1743 | _M_insert_unique_(end(), *__first, __roan); |
1744 | } |
1745 | |
1746 | template<typename _Key, typename _Val, typename _KeyOfValue, |
1747 | typename _Compare, typename _Alloc> |
1748 | template<typename _Iterator> |
1749 | void |
1750 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
1751 | _M_assign_equal(_Iterator __first, _Iterator __last) |
1752 | { |
1753 | _Reuse_or_alloc_node __roan(*this); |
1754 | _M_impl._M_reset(); |
1755 | for (; __first != __last; ++__first) |
1756 | _M_insert_equal_(end(), *__first, __roan); |
1757 | } |
1758 | #endif |
1759 | |
1760 | template<typename _Key, typename _Val, typename _KeyOfValue, |
1761 | typename _Compare, typename _Alloc> |
1762 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& |
1763 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
1764 | operator=(const _Rb_tree& __x) |
1765 | { |
1766 | if (this != &__x) |
1767 | { |
1768 | // Note that _Key may be a constant type. |
1769 | #if __cplusplus201703L >= 201103L |
1770 | if (_Alloc_traits::_S_propagate_on_copy_assign()) |
1771 | { |
1772 | auto& __this_alloc = this->_M_get_Node_allocator(); |
1773 | auto& __that_alloc = __x._M_get_Node_allocator(); |
1774 | if (!_Alloc_traits::_S_always_equal() |
1775 | && __this_alloc != __that_alloc) |
1776 | { |
1777 | // Replacement allocator cannot free existing storage, we need |
1778 | // to erase nodes first. |
1779 | clear(); |
1780 | std::__alloc_on_copy(__this_alloc, __that_alloc); |
1781 | } |
1782 | } |
1783 | #endif |
1784 | |
1785 | _Reuse_or_alloc_node __roan(*this); |
1786 | _M_impl._M_reset(); |
1787 | _M_impl._M_key_compare = __x._M_impl._M_key_compare; |
1788 | if (__x._M_root() != 0) |
1789 | _M_root() = _M_copy(__x, __roan); |
1790 | } |
1791 | |
1792 | return *this; |
1793 | } |
1794 | |
1795 | template<typename _Key, typename _Val, typename _KeyOfValue, |
1796 | typename _Compare, typename _Alloc> |
1797 | #if __cplusplus201703L >= 201103L |
1798 | template<typename _Arg, typename _NodeGen> |
1799 | #else |
1800 | template<typename _NodeGen> |
1801 | #endif |
1802 | typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator |
1803 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
1804 | _M_insert_(_Base_ptr __x, _Base_ptr __p, |
1805 | #if __cplusplus201703L >= 201103L |
1806 | _Arg&& __v, |
1807 | #else |
1808 | const _Val& __v, |
1809 | #endif |
1810 | _NodeGen& __node_gen) |
1811 | { |
1812 | bool __insert_left = (__x != 0 || __p == _M_end() |
1813 | || _M_impl._M_key_compare(_KeyOfValue()(__v), |
1814 | _S_key(__p))); |
1815 | |
1816 | _Link_type __z = __node_gen(_GLIBCXX_FORWARD(_Arg, __v)std::forward<_Arg>(__v)); |
1817 | |
1818 | _Rb_tree_insert_and_rebalance(__insert_left, __z, __p, |
1819 | this->_M_impl._M_header); |
1820 | ++_M_impl._M_node_count; |
1821 | return iterator(__z); |
1822 | } |
1823 | |
1824 | template<typename _Key, typename _Val, typename _KeyOfValue, |
1825 | typename _Compare, typename _Alloc> |
1826 | #if __cplusplus201703L >= 201103L |
1827 | template<typename _Arg> |
1828 | #endif |
1829 | typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator |
1830 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
1831 | #if __cplusplus201703L >= 201103L |
1832 | _M_insert_lower(_Base_ptr __p, _Arg&& __v) |
1833 | #else |
1834 | _M_insert_lower(_Base_ptr __p, const _Val& __v) |
1835 | #endif |
1836 | { |
1837 | bool __insert_left = (__p == _M_end() |
1838 | || !_M_impl._M_key_compare(_S_key(__p), |
1839 | _KeyOfValue()(__v))); |
1840 | |
1841 | _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v)std::forward<_Arg>(__v)); |
1842 | |
1843 | _Rb_tree_insert_and_rebalance(__insert_left, __z, __p, |
1844 | this->_M_impl._M_header); |
1845 | ++_M_impl._M_node_count; |
1846 | return iterator(__z); |
1847 | } |
1848 | |
1849 | template<typename _Key, typename _Val, typename _KeyOfValue, |
1850 | typename _Compare, typename _Alloc> |
1851 | #if __cplusplus201703L >= 201103L |
1852 | template<typename _Arg> |
1853 | #endif |
1854 | typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator |
1855 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
1856 | #if __cplusplus201703L >= 201103L |
1857 | _M_insert_equal_lower(_Arg&& __v) |
1858 | #else |
1859 | _M_insert_equal_lower(const _Val& __v) |
1860 | #endif |
1861 | { |
1862 | _Link_type __x = _M_begin(); |
1863 | _Base_ptr __y = _M_end(); |
1864 | while (__x != 0) |
1865 | { |
1866 | __y = __x; |
1867 | __x = !_M_impl._M_key_compare(_S_key(__x), _KeyOfValue()(__v)) ? |
1868 | _S_left(__x) : _S_right(__x); |
1869 | } |
1870 | return _M_insert_lower(__y, _GLIBCXX_FORWARD(_Arg, __v)std::forward<_Arg>(__v)); |
1871 | } |
1872 | |
1873 | template<typename _Key, typename _Val, typename _KoV, |
1874 | typename _Compare, typename _Alloc> |
1875 | template<typename _NodeGen> |
1876 | typename _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::_Link_type |
1877 | _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>:: |
1878 | _M_copy(_Const_Link_type __x, _Base_ptr __p, _NodeGen& __node_gen) |
1879 | { |
1880 | // Structural copy. __x and __p must be non-null. |
1881 | _Link_type __top = _M_clone_node(__x, __node_gen); |
1882 | __top->_M_parent = __p; |
1883 | |
1884 | __trytry |
1885 | { |
1886 | if (__x->_M_right) |
1887 | __top->_M_right = _M_copy(_S_right(__x), __top, __node_gen); |
1888 | __p = __top; |
1889 | __x = _S_left(__x); |
1890 | |
1891 | while (__x != 0) |
1892 | { |
1893 | _Link_type __y = _M_clone_node(__x, __node_gen); |
1894 | __p->_M_left = __y; |
1895 | __y->_M_parent = __p; |
1896 | if (__x->_M_right) |
1897 | __y->_M_right = _M_copy(_S_right(__x), __y, __node_gen); |
1898 | __p = __y; |
1899 | __x = _S_left(__x); |
1900 | } |
1901 | } |
1902 | __catch(...)catch(...) |
1903 | { |
1904 | _M_erase(__top); |
1905 | __throw_exception_againthrow; |
1906 | } |
1907 | return __top; |
1908 | } |
1909 | |
1910 | template<typename _Key, typename _Val, typename _KeyOfValue, |
1911 | typename _Compare, typename _Alloc> |
1912 | void |
1913 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
1914 | _M_erase(_Link_type __x) |
1915 | { |
1916 | // Erase without rebalancing. |
1917 | while (__x != 0) |
1918 | { |
1919 | _M_erase(_S_right(__x)); |
1920 | _Link_type __y = _S_left(__x); |
1921 | _M_drop_node(__x); |
1922 | __x = __y; |
1923 | } |
1924 | } |
1925 | |
1926 | template<typename _Key, typename _Val, typename _KeyOfValue, |
1927 | typename _Compare, typename _Alloc> |
1928 | typename _Rb_tree<_Key, _Val, _KeyOfValue, |
1929 | _Compare, _Alloc>::iterator |
1930 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
1931 | _M_lower_bound(_Link_type __x, _Base_ptr __y, |
1932 | const _Key& __k) |
1933 | { |
1934 | while (__x != 0) |
1935 | if (!_M_impl._M_key_compare(_S_key(__x), __k)) |
1936 | __y = __x, __x = _S_left(__x); |
1937 | else |
1938 | __x = _S_right(__x); |
1939 | return iterator(__y); |
1940 | } |
1941 | |
1942 | template<typename _Key, typename _Val, typename _KeyOfValue, |
1943 | typename _Compare, typename _Alloc> |
1944 | typename _Rb_tree<_Key, _Val, _KeyOfValue, |
1945 | _Compare, _Alloc>::const_iterator |
1946 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
1947 | _M_lower_bound(_Const_Link_type __x, _Const_Base_ptr __y, |
1948 | const _Key& __k) const |
1949 | { |
1950 | while (__x != 0) |
1951 | if (!_M_impl._M_key_compare(_S_key(__x), __k)) |
1952 | __y = __x, __x = _S_left(__x); |
1953 | else |
1954 | __x = _S_right(__x); |
1955 | return const_iterator(__y); |
1956 | } |
1957 | |
1958 | template<typename _Key, typename _Val, typename _KeyOfValue, |
1959 | typename _Compare, typename _Alloc> |
1960 | typename _Rb_tree<_Key, _Val, _KeyOfValue, |
1961 | _Compare, _Alloc>::iterator |
1962 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
1963 | _M_upper_bound(_Link_type __x, _Base_ptr __y, |
1964 | const _Key& __k) |
1965 | { |
1966 | while (__x != 0) |
1967 | if (_M_impl._M_key_compare(__k, _S_key(__x))) |
1968 | __y = __x, __x = _S_left(__x); |
1969 | else |
1970 | __x = _S_right(__x); |
1971 | return iterator(__y); |
1972 | } |
1973 | |
1974 | template<typename _Key, typename _Val, typename _KeyOfValue, |
1975 | typename _Compare, typename _Alloc> |
1976 | typename _Rb_tree<_Key, _Val, _KeyOfValue, |
1977 | _Compare, _Alloc>::const_iterator |
1978 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
1979 | _M_upper_bound(_Const_Link_type __x, _Const_Base_ptr __y, |
1980 | const _Key& __k) const |
1981 | { |
1982 | while (__x != 0) |
1983 | if (_M_impl._M_key_compare(__k, _S_key(__x))) |
1984 | __y = __x, __x = _S_left(__x); |
1985 | else |
1986 | __x = _S_right(__x); |
1987 | return const_iterator(__y); |
1988 | } |
1989 | |
1990 | template<typename _Key, typename _Val, typename _KeyOfValue, |
1991 | typename _Compare, typename _Alloc> |
1992 | pair<typename _Rb_tree<_Key, _Val, _KeyOfValue, |
1993 | _Compare, _Alloc>::iterator, |
1994 | typename _Rb_tree<_Key, _Val, _KeyOfValue, |
1995 | _Compare, _Alloc>::iterator> |
1996 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
1997 | equal_range(const _Key& __k) |
1998 | { |
1999 | _Link_type __x = _M_begin(); |
2000 | _Base_ptr __y = _M_end(); |
2001 | while (__x != 0) |
2002 | { |
2003 | if (_M_impl._M_key_compare(_S_key(__x), __k)) |
2004 | __x = _S_right(__x); |
2005 | else if (_M_impl._M_key_compare(__k, _S_key(__x))) |
2006 | __y = __x, __x = _S_left(__x); |
2007 | else |
2008 | { |
2009 | _Link_type __xu(__x); |
2010 | _Base_ptr __yu(__y); |
2011 | __y = __x, __x = _S_left(__x); |
2012 | __xu = _S_right(__xu); |
2013 | return pair<iterator, |
2014 | iterator>(_M_lower_bound(__x, __y, __k), |
2015 | _M_upper_bound(__xu, __yu, __k)); |
2016 | } |
2017 | } |
2018 | return pair<iterator, iterator>(iterator(__y), |
2019 | iterator(__y)); |
2020 | } |
2021 | |
2022 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2023 | typename _Compare, typename _Alloc> |
2024 | pair<typename _Rb_tree<_Key, _Val, _KeyOfValue, |
2025 | _Compare, _Alloc>::const_iterator, |
2026 | typename _Rb_tree<_Key, _Val, _KeyOfValue, |
2027 | _Compare, _Alloc>::const_iterator> |
2028 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
2029 | equal_range(const _Key& __k) const |
2030 | { |
2031 | _Const_Link_type __x = _M_begin(); |
2032 | _Const_Base_ptr __y = _M_end(); |
2033 | while (__x != 0) |
2034 | { |
2035 | if (_M_impl._M_key_compare(_S_key(__x), __k)) |
2036 | __x = _S_right(__x); |
2037 | else if (_M_impl._M_key_compare(__k, _S_key(__x))) |
2038 | __y = __x, __x = _S_left(__x); |
2039 | else |
2040 | { |
2041 | _Const_Link_type __xu(__x); |
2042 | _Const_Base_ptr __yu(__y); |
2043 | __y = __x, __x = _S_left(__x); |
2044 | __xu = _S_right(__xu); |
2045 | return pair<const_iterator, |
2046 | const_iterator>(_M_lower_bound(__x, __y, __k), |
2047 | _M_upper_bound(__xu, __yu, __k)); |
2048 | } |
2049 | } |
2050 | return pair<const_iterator, const_iterator>(const_iterator(__y), |
2051 | const_iterator(__y)); |
2052 | } |
2053 | |
2054 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2055 | typename _Compare, typename _Alloc> |
2056 | void |
2057 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
2058 | swap(_Rb_tree& __t) |
2059 | _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)noexcept(__is_nothrow_swappable<_Compare>::value) |
2060 | { |
2061 | if (_M_root() == 0) |
2062 | { |
2063 | if (__t._M_root() != 0) |
2064 | _M_impl._M_move_data(__t._M_impl); |
2065 | } |
2066 | else if (__t._M_root() == 0) |
2067 | __t._M_impl._M_move_data(_M_impl); |
2068 | else |
2069 | { |
2070 | std::swap(_M_root(),__t._M_root()); |
2071 | std::swap(_M_leftmost(),__t._M_leftmost()); |
2072 | std::swap(_M_rightmost(),__t._M_rightmost()); |
2073 | |
2074 | _M_root()->_M_parent = _M_end(); |
2075 | __t._M_root()->_M_parent = __t._M_end(); |
2076 | std::swap(this->_M_impl._M_node_count, __t._M_impl._M_node_count); |
2077 | } |
2078 | // No need to swap header's color as it does not change. |
2079 | std::swap(this->_M_impl._M_key_compare, __t._M_impl._M_key_compare); |
2080 | |
2081 | _Alloc_traits::_S_on_swap(_M_get_Node_allocator(), |
2082 | __t._M_get_Node_allocator()); |
2083 | } |
2084 | |
2085 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2086 | typename _Compare, typename _Alloc> |
2087 | pair<typename _Rb_tree<_Key, _Val, _KeyOfValue, |
2088 | _Compare, _Alloc>::_Base_ptr, |
2089 | typename _Rb_tree<_Key, _Val, _KeyOfValue, |
2090 | _Compare, _Alloc>::_Base_ptr> |
2091 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
2092 | _M_get_insert_unique_pos(const key_type& __k) |
2093 | { |
2094 | typedef pair<_Base_ptr, _Base_ptr> _Res; |
2095 | _Link_type __x = _M_begin(); |
2096 | _Base_ptr __y = _M_end(); |
2097 | bool __comp = true; |
2098 | while (__x != 0) |
2099 | { |
2100 | __y = __x; |
2101 | __comp = _M_impl._M_key_compare(__k, _S_key(__x)); |
2102 | __x = __comp ? _S_left(__x) : _S_right(__x); |
2103 | } |
2104 | iterator __j = iterator(__y); |
2105 | if (__comp) |
2106 | { |
2107 | if (__j == begin()) |
2108 | return _Res(__x, __y); |
2109 | else |
2110 | --__j; |
2111 | } |
2112 | if (_M_impl._M_key_compare(_S_key(__j._M_node), __k)) |
2113 | return _Res(__x, __y); |
2114 | return _Res(__j._M_node, 0); |
2115 | } |
2116 | |
2117 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2118 | typename _Compare, typename _Alloc> |
2119 | pair<typename _Rb_tree<_Key, _Val, _KeyOfValue, |
2120 | _Compare, _Alloc>::_Base_ptr, |
2121 | typename _Rb_tree<_Key, _Val, _KeyOfValue, |
2122 | _Compare, _Alloc>::_Base_ptr> |
2123 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
2124 | _M_get_insert_equal_pos(const key_type& __k) |
2125 | { |
2126 | typedef pair<_Base_ptr, _Base_ptr> _Res; |
2127 | _Link_type __x = _M_begin(); |
2128 | _Base_ptr __y = _M_end(); |
2129 | while (__x != 0) |
2130 | { |
2131 | __y = __x; |
2132 | __x = _M_impl._M_key_compare(__k, _S_key(__x)) ? |
2133 | _S_left(__x) : _S_right(__x); |
2134 | } |
2135 | return _Res(__x, __y); |
2136 | } |
2137 | |
2138 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2139 | typename _Compare, typename _Alloc> |
2140 | #if __cplusplus201703L >= 201103L |
2141 | template<typename _Arg> |
2142 | #endif |
2143 | pair<typename _Rb_tree<_Key, _Val, _KeyOfValue, |
2144 | _Compare, _Alloc>::iterator, bool> |
2145 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
2146 | #if __cplusplus201703L >= 201103L |
2147 | _M_insert_unique(_Arg&& __v) |
2148 | #else |
2149 | _M_insert_unique(const _Val& __v) |
2150 | #endif |
2151 | { |
2152 | typedef pair<iterator, bool> _Res; |
2153 | pair<_Base_ptr, _Base_ptr> __res |
2154 | = _M_get_insert_unique_pos(_KeyOfValue()(__v)); |
2155 | |
2156 | if (__res.second) |
2157 | { |
2158 | _Alloc_node __an(*this); |
2159 | return _Res(_M_insert_(__res.first, __res.second, |
2160 | _GLIBCXX_FORWARD(_Arg, __v)std::forward<_Arg>(__v), __an), |
2161 | true); |
2162 | } |
2163 | |
2164 | return _Res(iterator(__res.first), false); |
2165 | } |
2166 | |
2167 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2168 | typename _Compare, typename _Alloc> |
2169 | #if __cplusplus201703L >= 201103L |
2170 | template<typename _Arg> |
2171 | #endif |
2172 | typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator |
2173 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
2174 | #if __cplusplus201703L >= 201103L |
2175 | _M_insert_equal(_Arg&& __v) |
2176 | #else |
2177 | _M_insert_equal(const _Val& __v) |
2178 | #endif |
2179 | { |
2180 | pair<_Base_ptr, _Base_ptr> __res |
2181 | = _M_get_insert_equal_pos(_KeyOfValue()(__v)); |
2182 | _Alloc_node __an(*this); |
2183 | return _M_insert_(__res.first, __res.second, |
2184 | _GLIBCXX_FORWARD(_Arg, __v)std::forward<_Arg>(__v), __an); |
2185 | } |
2186 | |
2187 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2188 | typename _Compare, typename _Alloc> |
2189 | pair<typename _Rb_tree<_Key, _Val, _KeyOfValue, |
2190 | _Compare, _Alloc>::_Base_ptr, |
2191 | typename _Rb_tree<_Key, _Val, _KeyOfValue, |
2192 | _Compare, _Alloc>::_Base_ptr> |
2193 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
2194 | _M_get_insert_hint_unique_pos(const_iterator __position, |
2195 | const key_type& __k) |
2196 | { |
2197 | iterator __pos = __position._M_const_cast(); |
2198 | typedef pair<_Base_ptr, _Base_ptr> _Res; |
2199 | |
2200 | // end() |
2201 | if (__pos._M_node == _M_end()) |
2202 | { |
2203 | if (size() > 0 |
2204 | && _M_impl._M_key_compare(_S_key(_M_rightmost()), __k)) |
2205 | return _Res(0, _M_rightmost()); |
2206 | else |
2207 | return _M_get_insert_unique_pos(__k); |
2208 | } |
2209 | else if (_M_impl._M_key_compare(__k, _S_key(__pos._M_node))) |
2210 | { |
2211 | // First, try before... |
2212 | iterator __before = __pos; |
2213 | if (__pos._M_node == _M_leftmost()) // begin() |
2214 | return _Res(_M_leftmost(), _M_leftmost()); |
2215 | else if (_M_impl._M_key_compare(_S_key((--__before)._M_node), __k)) |
2216 | { |
2217 | if (_S_right(__before._M_node) == 0) |
2218 | return _Res(0, __before._M_node); |
2219 | else |
2220 | return _Res(__pos._M_node, __pos._M_node); |
2221 | } |
2222 | else |
2223 | return _M_get_insert_unique_pos(__k); |
2224 | } |
2225 | else if (_M_impl._M_key_compare(_S_key(__pos._M_node), __k)) |
2226 | { |
2227 | // ... then try after. |
2228 | iterator __after = __pos; |
2229 | if (__pos._M_node == _M_rightmost()) |
2230 | return _Res(0, _M_rightmost()); |
2231 | else if (_M_impl._M_key_compare(__k, _S_key((++__after)._M_node))) |
2232 | { |
2233 | if (_S_right(__pos._M_node) == 0) |
2234 | return _Res(0, __pos._M_node); |
2235 | else |
2236 | return _Res(__after._M_node, __after._M_node); |
2237 | } |
2238 | else |
2239 | return _M_get_insert_unique_pos(__k); |
2240 | } |
2241 | else |
2242 | // Equivalent keys. |
2243 | return _Res(__pos._M_node, 0); |
2244 | } |
2245 | |
2246 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2247 | typename _Compare, typename _Alloc> |
2248 | #if __cplusplus201703L >= 201103L |
2249 | template<typename _Arg, typename _NodeGen> |
2250 | #else |
2251 | template<typename _NodeGen> |
2252 | #endif |
2253 | typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator |
2254 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
2255 | _M_insert_unique_(const_iterator __position, |
2256 | #if __cplusplus201703L >= 201103L |
2257 | _Arg&& __v, |
2258 | #else |
2259 | const _Val& __v, |
2260 | #endif |
2261 | _NodeGen& __node_gen) |
2262 | { |
2263 | pair<_Base_ptr, _Base_ptr> __res |
2264 | = _M_get_insert_hint_unique_pos(__position, _KeyOfValue()(__v)); |
2265 | |
2266 | if (__res.second) |
2267 | return _M_insert_(__res.first, __res.second, |
2268 | _GLIBCXX_FORWARD(_Arg, __v)std::forward<_Arg>(__v), |
2269 | __node_gen); |
2270 | return iterator(__res.first); |
2271 | } |
2272 | |
2273 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2274 | typename _Compare, typename _Alloc> |
2275 | pair<typename _Rb_tree<_Key, _Val, _KeyOfValue, |
2276 | _Compare, _Alloc>::_Base_ptr, |
2277 | typename _Rb_tree<_Key, _Val, _KeyOfValue, |
2278 | _Compare, _Alloc>::_Base_ptr> |
2279 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
2280 | _M_get_insert_hint_equal_pos(const_iterator __position, const key_type& __k) |
2281 | { |
2282 | iterator __pos = __position._M_const_cast(); |
2283 | typedef pair<_Base_ptr, _Base_ptr> _Res; |
2284 | |
2285 | // end() |
2286 | if (__pos._M_node == _M_end()) |
2287 | { |
2288 | if (size() > 0 |
2289 | && !_M_impl._M_key_compare(__k, _S_key(_M_rightmost()))) |
2290 | return _Res(0, _M_rightmost()); |
2291 | else |
2292 | return _M_get_insert_equal_pos(__k); |
2293 | } |
2294 | else if (!_M_impl._M_key_compare(_S_key(__pos._M_node), __k)) |
2295 | { |
2296 | // First, try before... |
2297 | iterator __before = __pos; |
2298 | if (__pos._M_node == _M_leftmost()) // begin() |
2299 | return _Res(_M_leftmost(), _M_leftmost()); |
2300 | else if (!_M_impl._M_key_compare(__k, _S_key((--__before)._M_node))) |
2301 | { |
2302 | if (_S_right(__before._M_node) == 0) |
2303 | return _Res(0, __before._M_node); |
2304 | else |
2305 | return _Res(__pos._M_node, __pos._M_node); |
2306 | } |
2307 | else |
2308 | return _M_get_insert_equal_pos(__k); |
2309 | } |
2310 | else |
2311 | { |
2312 | // ... then try after. |
2313 | iterator __after = __pos; |
2314 | if (__pos._M_node == _M_rightmost()) |
2315 | return _Res(0, _M_rightmost()); |
2316 | else if (!_M_impl._M_key_compare(_S_key((++__after)._M_node), __k)) |
2317 | { |
2318 | if (_S_right(__pos._M_node) == 0) |
2319 | return _Res(0, __pos._M_node); |
2320 | else |
2321 | return _Res(__after._M_node, __after._M_node); |
2322 | } |
2323 | else |
2324 | return _Res(0, 0); |
2325 | } |
2326 | } |
2327 | |
2328 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2329 | typename _Compare, typename _Alloc> |
2330 | #if __cplusplus201703L >= 201103L |
2331 | template<typename _Arg, typename _NodeGen> |
2332 | #else |
2333 | template<typename _NodeGen> |
2334 | #endif |
2335 | typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator |
2336 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
2337 | _M_insert_equal_(const_iterator __position, |
2338 | #if __cplusplus201703L >= 201103L |
2339 | _Arg&& __v, |
2340 | #else |
2341 | const _Val& __v, |
2342 | #endif |
2343 | _NodeGen& __node_gen) |
2344 | { |
2345 | pair<_Base_ptr, _Base_ptr> __res |
2346 | = _M_get_insert_hint_equal_pos(__position, _KeyOfValue()(__v)); |
2347 | |
2348 | if (__res.second) |
2349 | return _M_insert_(__res.first, __res.second, |
2350 | _GLIBCXX_FORWARD(_Arg, __v)std::forward<_Arg>(__v), |
2351 | __node_gen); |
2352 | |
2353 | return _M_insert_equal_lower(_GLIBCXX_FORWARD(_Arg, __v)std::forward<_Arg>(__v)); |
2354 | } |
2355 | |
2356 | #if __cplusplus201703L >= 201103L |
2357 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2358 | typename _Compare, typename _Alloc> |
2359 | typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator |
2360 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
2361 | _M_insert_node(_Base_ptr __x, _Base_ptr __p, _Link_type __z) |
2362 | { |
2363 | bool __insert_left = (__x != 0 || __p == _M_end() |
2364 | || _M_impl._M_key_compare(_S_key(__z), |
2365 | _S_key(__p))); |
2366 | |
2367 | _Rb_tree_insert_and_rebalance(__insert_left, __z, __p, |
2368 | this->_M_impl._M_header); |
2369 | ++_M_impl._M_node_count; |
2370 | return iterator(__z); |
2371 | } |
2372 | |
2373 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2374 | typename _Compare, typename _Alloc> |
2375 | typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator |
2376 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
2377 | _M_insert_lower_node(_Base_ptr __p, _Link_type __z) |
2378 | { |
2379 | bool __insert_left = (__p == _M_end() |
2380 | || !_M_impl._M_key_compare(_S_key(__p), |
2381 | _S_key(__z))); |
2382 | |
2383 | _Rb_tree_insert_and_rebalance(__insert_left, __z, __p, |
2384 | this->_M_impl._M_header); |
2385 | ++_M_impl._M_node_count; |
2386 | return iterator(__z); |
2387 | } |
2388 | |
2389 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2390 | typename _Compare, typename _Alloc> |
2391 | typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator |
2392 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
2393 | _M_insert_equal_lower_node(_Link_type __z) |
2394 | { |
2395 | _Link_type __x = _M_begin(); |
2396 | _Base_ptr __y = _M_end(); |
2397 | while (__x != 0) |
2398 | { |
2399 | __y = __x; |
2400 | __x = !_M_impl._M_key_compare(_S_key(__x), _S_key(__z)) ? |
2401 | _S_left(__x) : _S_right(__x); |
2402 | } |
2403 | return _M_insert_lower_node(__y, __z); |
2404 | } |
2405 | |
2406 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2407 | typename _Compare, typename _Alloc> |
2408 | template<typename... _Args> |
2409 | pair<typename _Rb_tree<_Key, _Val, _KeyOfValue, |
2410 | _Compare, _Alloc>::iterator, bool> |
2411 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
2412 | _M_emplace_unique(_Args&&... __args) |
2413 | { |
2414 | _Link_type __z = _M_create_node(std::forward<_Args>(__args)...); |
2415 | |
2416 | __trytry |
2417 | { |
2418 | typedef pair<iterator, bool> _Res; |
2419 | auto __res = _M_get_insert_unique_pos(_S_key(__z)); |
2420 | if (__res.second) |
2421 | return _Res(_M_insert_node(__res.first, __res.second, __z), true); |
2422 | |
2423 | _M_drop_node(__z); |
2424 | return _Res(iterator(__res.first), false); |
2425 | } |
2426 | __catch(...)catch(...) |
2427 | { |
2428 | _M_drop_node(__z); |
2429 | __throw_exception_againthrow; |
2430 | } |
2431 | } |
2432 | |
2433 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2434 | typename _Compare, typename _Alloc> |
2435 | template<typename... _Args> |
2436 | typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator |
2437 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
2438 | _M_emplace_equal(_Args&&... __args) |
2439 | { |
2440 | _Link_type __z = _M_create_node(std::forward<_Args>(__args)...); |
2441 | |
2442 | __trytry |
2443 | { |
2444 | auto __res = _M_get_insert_equal_pos(_S_key(__z)); |
2445 | return _M_insert_node(__res.first, __res.second, __z); |
2446 | } |
2447 | __catch(...)catch(...) |
2448 | { |
2449 | _M_drop_node(__z); |
2450 | __throw_exception_againthrow; |
2451 | } |
2452 | } |
2453 | |
2454 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2455 | typename _Compare, typename _Alloc> |
2456 | template<typename... _Args> |
2457 | typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator |
2458 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
2459 | _M_emplace_hint_unique(const_iterator __pos, _Args&&... __args) |
2460 | { |
2461 | _Link_type __z = _M_create_node(std::forward<_Args>(__args)...); |
2462 | |
2463 | __trytry |
2464 | { |
2465 | auto __res = _M_get_insert_hint_unique_pos(__pos, _S_key(__z)); |
2466 | |
2467 | if (__res.second) |
2468 | return _M_insert_node(__res.first, __res.second, __z); |
2469 | |
2470 | _M_drop_node(__z); |
2471 | return iterator(__res.first); |
2472 | } |
2473 | __catch(...)catch(...) |
2474 | { |
2475 | _M_drop_node(__z); |
2476 | __throw_exception_againthrow; |
2477 | } |
2478 | } |
2479 | |
2480 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2481 | typename _Compare, typename _Alloc> |
2482 | template<typename... _Args> |
2483 | typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator |
2484 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
2485 | _M_emplace_hint_equal(const_iterator __pos, _Args&&... __args) |
2486 | { |
2487 | _Link_type __z = _M_create_node(std::forward<_Args>(__args)...); |
2488 | |
2489 | __trytry |
2490 | { |
2491 | auto __res = _M_get_insert_hint_equal_pos(__pos, _S_key(__z)); |
2492 | |
2493 | if (__res.second) |
2494 | return _M_insert_node(__res.first, __res.second, __z); |
2495 | |
2496 | return _M_insert_equal_lower_node(__z); |
2497 | } |
2498 | __catch(...)catch(...) |
2499 | { |
2500 | _M_drop_node(__z); |
2501 | __throw_exception_againthrow; |
2502 | } |
2503 | } |
2504 | #endif |
2505 | |
2506 | |
2507 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2508 | typename _Compare, typename _Alloc> |
2509 | void |
2510 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
2511 | _M_erase_aux(const_iterator __position) |
2512 | { |
2513 | _Link_type __y = |
2514 | static_cast<_Link_type>(_Rb_tree_rebalance_for_erase |
2515 | (const_cast<_Base_ptr>(__position._M_node), |
2516 | this->_M_impl._M_header)); |
2517 | _M_drop_node(__y); |
2518 | --_M_impl._M_node_count; |
2519 | } |
2520 | |
2521 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2522 | typename _Compare, typename _Alloc> |
2523 | void |
2524 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
2525 | _M_erase_aux(const_iterator __first, const_iterator __last) |
2526 | { |
2527 | if (__first == begin() && __last == end()) |
2528 | clear(); |
2529 | else |
2530 | while (__first != __last) |
2531 | _M_erase_aux(__first++); |
2532 | } |
2533 | |
2534 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2535 | typename _Compare, typename _Alloc> |
2536 | typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type |
2537 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
2538 | erase(const _Key& __x) |
2539 | { |
2540 | pair<iterator, iterator> __p = equal_range(__x); |
2541 | const size_type __old_size = size(); |
2542 | _M_erase_aux(__p.first, __p.second); |
2543 | return __old_size - size(); |
2544 | } |
2545 | |
2546 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2547 | typename _Compare, typename _Alloc> |
2548 | typename _Rb_tree<_Key, _Val, _KeyOfValue, |
2549 | _Compare, _Alloc>::iterator |
2550 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
2551 | find(const _Key& __k) |
2552 | { |
2553 | iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k); |
2554 | return (__j == end() |
2555 | || _M_impl._M_key_compare(__k, |
2556 | _S_key(__j._M_node))) ? end() : __j; |
2557 | } |
2558 | |
2559 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2560 | typename _Compare, typename _Alloc> |
2561 | typename _Rb_tree<_Key, _Val, _KeyOfValue, |
2562 | _Compare, _Alloc>::const_iterator |
2563 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
2564 | find(const _Key& __k) const |
2565 | { |
2566 | const_iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k); |
2567 | return (__j == end() |
2568 | || _M_impl._M_key_compare(__k, |
2569 | _S_key(__j._M_node))) ? end() : __j; |
2570 | } |
2571 | |
2572 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2573 | typename _Compare, typename _Alloc> |
2574 | typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type |
2575 | _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: |
2576 | count(const _Key& __k) const |
2577 | { |
2578 | pair<const_iterator, const_iterator> __p = equal_range(__k); |
2579 | const size_type __n = std::distance(__p.first, __p.second); |
2580 | return __n; |
2581 | } |
2582 | |
2583 | _GLIBCXX_PURE__attribute__ ((__pure__)) unsigned int |
2584 | _Rb_tree_black_count(const _Rb_tree_node_base* __node, |
2585 | const _Rb_tree_node_base* __root) throw (); |
2586 | |
2587 | template<typename _Key, typename _Val, typename _KeyOfValue, |
2588 | typename _Compare, typename _Alloc> |
2589 | bool |
2590 | _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::__rb_verify() const |
2591 | { |
2592 | if (_M_impl._M_node_count == 0 || begin() == end()) |
2593 | return _M_impl._M_node_count == 0 && begin() == end() |
2594 | && this->_M_impl._M_header._M_left == _M_end() |
2595 | && this->_M_impl._M_header._M_right == _M_end(); |
2596 | |
2597 | unsigned int __len = _Rb_tree_black_count(_M_leftmost(), _M_root()); |
2598 | for (const_iterator __it = begin(); __it != end(); ++__it) |
2599 | { |
2600 | _Const_Link_type __x = static_cast<_Const_Link_type>(__it._M_node); |
2601 | _Const_Link_type __L = _S_left(__x); |
2602 | _Const_Link_type __R = _S_right(__x); |
2603 | |
2604 | if (__x->_M_color == _S_red) |
2605 | if ((__L && __L->_M_color == _S_red) |
2606 | || (__R && __R->_M_color == _S_red)) |
2607 | return false; |
2608 | |
2609 | if (__L && _M_impl._M_key_compare(_S_key(__x), _S_key(__L))) |
2610 | return false; |
2611 | if (__R && _M_impl._M_key_compare(_S_key(__R), _S_key(__x))) |
2612 | return false; |
2613 | |
2614 | if (!__L && !__R && _Rb_tree_black_count(__x, _M_root()) != __len) |
2615 | return false; |
2616 | } |
2617 | |
2618 | if (_M_leftmost() != _Rb_tree_node_base::_S_minimum(_M_root())) |
2619 | return false; |
2620 | if (_M_rightmost() != _Rb_tree_node_base::_S_maximum(_M_root())) |
2621 | return false; |
2622 | return true; |
2623 | } |
2624 | |
2625 | #if __cplusplus201703L > 201402L |
2626 | // Allow access to internals of compatible _Rb_tree specializations. |
2627 | template<typename _Key, typename _Val, typename _Sel, typename _Cmp1, |
2628 | typename _Alloc, typename _Cmp2> |
2629 | struct _Rb_tree_merge_helper<_Rb_tree<_Key, _Val, _Sel, _Cmp1, _Alloc>, |
2630 | _Cmp2> |
2631 | { |
2632 | private: |
2633 | friend class _Rb_tree<_Key, _Val, _Sel, _Cmp1, _Alloc>; |
2634 | |
2635 | static auto& |
2636 | _S_get_impl(_Rb_tree<_Key, _Val, _Sel, _Cmp2, _Alloc>& __tree) |
2637 | { return __tree._M_impl; } |
2638 | }; |
2639 | #endif // C++17 |
2640 | |
2641 | _GLIBCXX_END_NAMESPACE_VERSION |
2642 | } // namespace |
2643 | |
2644 | #endif |