22#include <osl/diagnose.h>
33 mbContinueingPreviousSubTree( false ),
52 OSL_FAIL(
"lost children!");
56 OSL_ENSURE(
IsPhantom() ||
mpParent ==
nullptr,
": I'm not supposed to have a parent.");
60 OSL_ENSURE(
mChildren.empty(),
"children left!");
70 OSL_FAIL(
"phantom already present");
78 std::pair<tSwNumberTreeChildren::iterator, bool> aInsert =
83 OSL_FAIL(
"insert of phantom failed!");
106 tSwNumberTreeChildren::iterator aIt =
mChildren.begin();
108 if (!(aIt !=
mChildren.end() && (*aIt)->IsPhantom()))
111 (*aIt)->ClearObsoletePhantoms();
113 if ((*aIt)->mChildren.empty())
128 tSwNumberTreeChildren::const_iterator aValidateIt =
134 OSL_ENSURE((*aValidateIt)->mpParent ==
this,
"wrong parent");
136 tSwNumberTreeChildren::const_iterator aIt =
mItLastValid;
150 nTmpNumber = (*aIt)->mnNumber;
154 (*aIt)->mbContinueingPreviousSubTree =
false;
158 nTmpNumber = (*aIt)->GetStartValue();
159 if ( !(*aIt)->IsCounted() &&
160 ( !(*aIt)->HasCountedChildren() || (*aIt)->IsPhantom() ) )
168 const bool bParentCounted(
IsCounted() &&
171 if ( !(*aIt)->IsRestart() &&
174 tSwNumberTreeChildren::const_iterator aParentChildIt =
182 (*aIt)->mbContinueingPreviousSubTree =
true;
183 nTmpNumber = (*(pPrevNode->
mChildren.rbegin()))->GetNumber();
184 if ( (*aIt)->IsCounted() &&
185 ( !(*aIt)->IsPhantom() ||
186 (*aIt)->HasPhantomCountedParent() ) )
204 (*aIt)->mnNumber = nTmpNumber;
207 while (aIt != aValidateIt)
210 (*aIt)->mbContinueingPreviousSubTree =
false;
215 if ( (*aIt)->IsCounted() )
217 if ((*aIt)->IsRestart())
218 nTmpNumber = (*aIt)->GetStartValue();
223 (*aIt)->mnNumber = nTmpNumber;
231 tSwNumberTreeChildren::const_iterator aIt =
mItLastValid;
252 if ( !(*aIt)->IsCounted() )
257 if ( (*aIt)->IsRestart() )
258 nTmpNumber = (*aIt)->GetStartValue();
265 if ( !(*aIt)->IsCounted() )
269 if ( (*aIt)->IsRestart() )
270 nTmpNumber = (*aIt)->GetStartValue();
276 (*aIt)->mnNumber = nTmpNumber;
279 while (aIt !=
mChildren.end() && *aIt != pNode);
298 bool bValidate)
const
325 tSwNumberTreeChildren::iterator aItUpper(
mChildren.end() );
333 aItUpper =
mChildren.upper_bound(&_rCompareNode);
339 tSwNumberTreeChildren::iterator aIt;
340 for (aIt = aItUpper; aIt !=
mChildren.end(); ++aIt)
341 (*aIt)->mpParent = &_rDestNode;
370 tSwNumberTreeChildren::iterator aItBegin =
mChildren.begin();
397 rpChild->mpParent = pDest;
406 OSL_ENSURE(
mChildren.empty(),
"MoveChildren failed!");
445 OSL_FAIL(
"<SwNumberTreeNode::AddChild(..)> - parameter <nDepth> out of valid range. Serious defect." );
451 OSL_FAIL(
"only orphans allowed.");
457 tSwNumberTreeChildren::iterator aInsertDeepIt =
460 OSL_ENSURE(! (aInsertDeepIt !=
mChildren.end() &&
461 (*aInsertDeepIt)->IsPhantom()),
" unexpected phantom");
470 pNew->
AddChild(pChild, nDepth - 1, rDoc);
475 (*aInsertDeepIt)->AddChild(pChild, nDepth - 1, rDoc);
482 std::pair<tSwNumberTreeChildren::iterator, bool> aResult =
489 tSwNumberTreeChildren::iterator aInsertedIt = aResult.first;
493 tSwNumberTreeChildren::iterator aPredIt = aInsertedIt;
503 while ( pDestNode && pPrevChildNode &&
514 tSwNumberTreeChildren::reverse_iterator aIt =
516 pPrevChildNode = *aIt;
520 pDestNode = *(pDestNode->
mChildren.begin());
540 if ((*aPredIt)->IsValid())
582 OSL_FAIL(
"not applicable to phantoms!");
587 tSwNumberTreeChildren::const_iterator aRemoveIt =
GetIterator(pChild);
595 tSwNumberTreeChildren::const_iterator aItPred =
mChildren.end();
615 (*aItPred)->InvalidateTree();
616 (*aItPred)->NotifyInvalidChildren(rDoc);
623 if (aItPred !=
mChildren.end() && (*aItPred)->IsPhantom())
634 OSL_FAIL(
"RemoveChild: failed!");
649 while (pSavedParent && pSavedParent->
IsPhantom() &&
651 pSavedParent = pSavedParent->
GetParent();
678 vector<SwNumberTree::tSwNumTreeNumber> aResult;
687 bool bResult =
false;
691 if (pChild && pChild->
mpParent ==
this)
693 bResult = ! (*mItLastValid)->LessThan(*pChild);
703 bool bResult =
false;
707 tSwNumberTreeChildren::const_iterator aIt =
mChildren.begin();
709 bResult = (*aIt)->IsPhantom() && (*aIt)->HasOnlyPhantoms();
728 "<SwNumberTreeNode::HasPhantomCountedParent()> - wrong usage of method - it's only for phantoms" );
750 tSwNumberTreeChildren::const_iterator aIt =
mChildren.begin();
752 if ((*aIt)->IsPhantom())
755 return *aIt == pNode;
800 OSL_FAIL(
"<SwNumberTreeNode::SetLevelInListTree(..)> - parameter <nLevel> out of valid range. Serious defect." );
805 "<SwNumberTreeNode::SetLevelInListTree(..)> - can only be called for number tree nodes in a list tree" );
811 OSL_ENSURE( pRootTreeNode,
812 "<SwNumberTreeNode::SetLevelInListTree(..)> - no root tree node found. Serious defect." );
815 pRootTreeNode->
AddChild(
this, nLevel, rDoc);
828SwNumberTreeNode::tSwNumberTreeChildren::size_type
837 vector<const SwNumberTreeNode*> aParents;
839 return IsSane(bRecursive, std::move(aParents));
843 vector<const SwNumberTreeNode *> rParents)
846 assert(
find(rParents.begin(), rParents.end(),
this) == rParents.end());
848 assert(rParents.empty() || rParents.back() ==
mpParent);
850 rParents.push_back(
this);
857 if (rpChild->IsPhantom())
860 "HasOnlyPhantoms: is this an error?");
862 assert(bFirst &&
"found phantom not at first position.");
865 assert(rpChild->mpParent ==
this);
869 assert(rpChild->IsPhantom() || !rpChild->LessThan(*
this));
874 assert(!
"found child that is NULL");
879 rpChild->IsSane(bRecursive, rParents);
889SwNumberTreeNode::tSwNumberTreeChildren::const_iterator
892 tSwNumberTreeChildren::const_iterator aItResult =
895 OSL_ENSURE( aItResult !=
mChildren.end(),
896 "something went wrong getting the iterator for a child");
904 bool bResult =
false;
906 if (pA ==
nullptr && pB !=
nullptr)
908 else if (pA !=
nullptr && pB !=
nullptr)
917 tSwNumberTreeChildren::const_reverse_iterator aIt =
mChildren.rbegin();
932 return this < &rTreeNode;
941 tSwNumberTreeChildren::const_iterator aIt =
968 (
const SwNumberTreeNode::tSwNumberTreeChildren::const_iterator& aItValid,
969 bool bValidating )
const
972 "last-valid iterator");
985 tSwNumberTreeChildren::const_iterator aParentChildIt =
1002 tSwNumberTreeChildren::const_iterator aIt =
mItLastValid;
1011 (*aIt)->InvalidateTree();
1030 rpChild->InvalidateTree();
1037 tSwNumberTreeChildren::const_iterator aIt =
GetIterator(pChild);
1069 rpChild->Notify(rDoc);
1077 tSwNumberTreeChildren::const_iterator aIt =
mItLastValid;
1086 (*aIt)->Notify(rDoc);
1093 tSwNumberTreeChildren::const_iterator aParentChildIt =
1126 tSwNumberTreeChildren::const_iterator aUpperBoundIt =
1128 if ( aUpperBoundIt !=
mChildren.begin() )
1135 if ( pPrecedingNode ==
nullptr &&
GetRoot() )
1143 pPrecedingNode =
this;
1147 return pPrecedingNode;
1152 if ( nListLevel < 0 )
1154 OSL_FAIL(
"<SwNumberTreeNode::NotifyNodesOnListLevel(..)> - invalid list level provided" );
1165 OSL_ENSURE( nDepth >= 0,
1166 "<SwNumberTreeNode::NotifyChildrenOnDepth(..)> - misusage" );
1172 rpChild->NotifyNode();
1176 rpChild->NotifyChildrenOnDepth( nDepth - 1 );
bool SwNumberTreeNodeLessThan(const SwNumberTreeNode *pA, const SwNumberTreeNode *pB)
A tree of numbered nodes.
bool HasPhantomCountedParent() const
bool IsPhantom() const
Return if this node is a phantom.
int GetLevelInListTree() const
Return level of this node.
bool IsFirst() const
Return if this node if the first non-phantom node in the tree.
void ValidateHierarchical(const SwNumberTreeNode *pNode) const
Validates a child using hierarchical numbering.
void NotifyChildrenOnDepth(const int nDepth)
notification of children nodes on certain depth
void Invalidate(SwNumberTreeNode const *pChild)
Invalidates a child.
virtual bool IsNotifiable(const SwDoc &rDoc) const =0
Return if this node is notifiable.
virtual bool HasCountedChildren() const =0
virtual void PostRemove()=0
SwNumberTreeNode * mpParent
he parent node
void ClearObsoletePhantoms()
Removes recursively phantoms that have no children.
void NotifyNodesOnListLevel(const int nListLevel)
notification of all nodes in the list tree on certain list level
bool IsValid() const
Returns if this node is valid.
void Notify(const SwDoc &rDoc)
Notifies this node (NotifyNode) and all descendants.
virtual bool IsContinuous() const =0
Return if this node is counted continuous.
SwNumberTreeNode * GetFirstNonPhantomChild()
HB, OD : return node, if it isn't a phantom, otherwise return first non-phantom descendant.
void SetLastValid(const tSwNumberTreeChildren::const_iterator &aItLastValid, bool bValidating=false) const
Set the last valid child of this node.
void Validate(const SwNumberTreeNode *pNode) const
Validates a child.
virtual bool IsNotificationEnabled(const SwDoc &rDoc) const =0
Return if the notification is not disabled on global conditions.
virtual bool IsCounted() const
Return if this node is counted.
SwNumberTree::tSwNumTreeNumber mnNumber
the number of the node
void InvalidateChildren()
Invalidation of all children.
void GetNumberVector_(SwNumberTree::tNumberVector &rVector, bool bValidate=true) const
Calls GetNumberVector_ on parent and adds number of this node at the end.
SwNumberTreeNode * GetRoot() const
Returns the root node of the tree this node is part of.
tSwNumberTreeChildren::const_iterator mItLastValid
Iterator to the last valid element.
SwNumberTree::tSwNumTreeNumber GetNumber(bool bValidate=true) const
Returns number of this node.
tSwNumberTreeChildren mChildren
the children
tSwNumberTreeChildren::size_type GetChildCount() const
Returns how many children this node has got.
SwNumberTreeNode * CreatePhantom()
Creates a phantom.
virtual bool LessThan(const SwNumberTreeNode &rTreeNode) const
Returns if this node is less than another node.
void InvalidateTree() const
Invalidate this node and all its descendants.
void RemoveChild(SwNumberTreeNode *pChild, const SwDoc &rDoc)
Remove a child.
void SetLevelInListTree(const int nLevel, const SwDoc &rDoc)
set level of this node
void ValidateContinuous(const SwNumberTreeNode *pNode) const
Validates a child using continuous numbering.
void IsSane(bool bRecursive) const
Sanity check.
virtual SwNumberTree::tSwNumTreeNumber GetStartValue() const =0
Return start value.
virtual bool IsCountPhantoms() const =0
Return if phantoms are counted.
const SwNumberTreeNode * GetPrecedingNodeOf(const SwNumberTreeNode &rNode) const
determines the node, which is preceding the node
bool HasOnlyPhantoms() const
Return if all descendants of this node are phantoms.
void MoveGreaterChildren(SwNumberTreeNode &_rCompareNode, SwNumberTreeNode &_rDestNode)
Moves all children of this node that are greater than a given node to the destination node.
virtual void NotifyNode()=0
Notifies the node.
bool IsValid(const SwNumberTreeNode *pChild) const
Returns if a child A this node is valid.
void NotifyInvalidChildren(const SwDoc &rDoc)
Notifies all invalid children of this node.
SwNumberTreeNode * GetPred(bool bSibling=false) const
Returns the greatest descendant of the root that is smaller than this node, aka the predecessor of th...
void ValidateMe()
Validates this node.
void NotifyInvalidSiblings(const SwDoc &rDoc)
Notifies all invalid siblings of this node.
virtual ~SwNumberTreeNode()
SwNumberTree::tNumberVector GetNumberVector() const
Returns level numbers of this node.
bool mbPhantom
true this node is a phantom false this node is NOT a phantom
void RemoveMe(const SwDoc &rDoc)
Remove this child from the tree.
void MoveChildren(SwNumberTreeNode *pDest)
Moves all children to a given destination node.
tSwNumberTreeChildren::const_iterator GetIterator(const SwNumberTreeNode *pChild) const
SwNumberTreeNode * GetParent() const
Returns the parent of this node.
SwNumberTreeNode * GetLastDescendant() const
Returns the last descendant of a node, if it has children.
virtual SwNumberTreeNode * Create() const =0
Creates a new node of the same class.
void InvalidateMe()
Notifies the node.
void AddChild(SwNumberTreeNode *pChild, const int nDepth, const SwDoc &rDoc)
Add a child.
RegionData_Impl * mpParent
#define SAL_WARN_IF(condition, area, stream)
tools::Long tSwNumTreeNumber
std::vector< tSwNumTreeNumber > tNumberVector
OSQLColumns::const_iterator find(const OSQLColumns::const_iterator &first, const OSQLColumns::const_iterator &last, std::u16string_view _rVal, const ::comphelper::UStringMixEqual &_rCase)