22 #include <osl/diagnose.h>
34 mbContinueingPreviousSubTree( false ),
54 OSL_FAIL(
"lost children!");
58 OSL_ENSURE(
IsPhantom() ||
mpParent ==
nullptr,
": I'm not supposed to have a parent.");
62 OSL_ENSURE(
mChildren.empty(),
"children left!");
72 OSL_FAIL(
"phantom already present");
80 std::pair<tSwNumberTreeChildren::iterator, bool> aInsert =
85 OSL_FAIL(
"insert of phantom failed!");
108 tSwNumberTreeChildren::iterator aIt =
mChildren.begin();
110 if (!(aIt !=
mChildren.end() && (*aIt)->IsPhantom()))
113 (*aIt)->ClearObsoletePhantoms();
115 if ((*aIt)->mChildren.empty())
130 tSwNumberTreeChildren::const_iterator aValidateIt =
136 OSL_ENSURE((*aValidateIt)->mpParent ==
this,
"wrong parent");
138 tSwNumberTreeChildren::const_iterator aIt =
mItLastValid;
152 nTmpNumber = (*aIt)->mnNumber;
156 (*aIt)->mbContinueingPreviousSubTree =
false;
160 nTmpNumber = (*aIt)->GetStartValue();
161 if ( !(*aIt)->IsCounted() &&
162 ( !(*aIt)->HasCountedChildren() || (*aIt)->IsPhantom() ) )
170 const bool bParentCounted(
IsCounted() &&
173 if ( !(*aIt)->IsRestart() &&
176 tSwNumberTreeChildren::const_iterator aParentChildIt =
184 (*aIt)->mbContinueingPreviousSubTree =
true;
185 nTmpNumber = (*(pPrevNode->
mChildren.rbegin()))->GetNumber();
186 if ( (*aIt)->IsCounted() &&
187 ( !(*aIt)->IsPhantom() ||
188 (*aIt)->HasPhantomCountedParent() ) )
206 (*aIt)->mnNumber = nTmpNumber;
209 while (aIt != aValidateIt)
212 (*aIt)->mbContinueingPreviousSubTree =
false;
217 if ( (*aIt)->IsCounted() )
219 if ((*aIt)->IsRestart())
220 nTmpNumber = (*aIt)->GetStartValue();
225 (*aIt)->mnNumber = nTmpNumber;
228 SetLastValid(aIt,
true);
233 tSwNumberTreeChildren::const_iterator aIt =
mItLastValid;
254 if ( !(*aIt)->IsCounted() )
259 if ( (*aIt)->IsRestart() )
260 nTmpNumber = (*aIt)->GetStartValue();
267 if ( !(*aIt)->IsCounted() )
271 if ( (*aIt)->IsRestart() )
272 nTmpNumber = (*aIt)->GetStartValue();
278 (*aIt)->mnNumber = nTmpNumber;
281 while (aIt !=
mChildren.end() && *aIt != pNode);
300 bool bValidate)
const
327 tSwNumberTreeChildren::iterator aItUpper(
mChildren.end() );
335 aItUpper =
mChildren.upper_bound(&_rCompareNode);
341 tSwNumberTreeChildren::iterator aIt;
342 for (aIt = aItUpper; aIt !=
mChildren.end(); ++aIt)
343 (*aIt)->mpParent = &_rDestNode;
372 tSwNumberTreeChildren::iterator aItBegin =
mChildren.begin();
399 rpChild->mpParent = pDest;
401 pDest->
mChildren.insert(mChildren.begin(), mChildren.end());
408 OSL_ENSURE(
mChildren.empty(),
"MoveChildren failed!");
446 OSL_FAIL(
"<SwNumberTreeNode::AddChild(..)> - parameter <nDepth> out of valid range. Serious defect." );
452 OSL_FAIL(
"only orphans allowed.");
458 tSwNumberTreeChildren::iterator aInsertDeepIt =
461 OSL_ENSURE(! (aInsertDeepIt !=
mChildren.end() &&
462 (*aInsertDeepIt)->IsPhantom()),
" unexpected phantom");
476 (*aInsertDeepIt)->AddChild(pChild, nDepth - 1);
483 std::pair<tSwNumberTreeChildren::iterator, bool> aResult =
490 tSwNumberTreeChildren::iterator aInsertedIt = aResult.first;
494 tSwNumberTreeChildren::iterator aPredIt = aInsertedIt;
504 while ( pDestNode && pPrevChildNode &&
515 tSwNumberTreeChildren::reverse_iterator aIt =
517 pPrevChildNode = *aIt;
521 pDestNode = *(pDestNode->
mChildren.begin());
541 if ((*aPredIt)->IsValid())
583 OSL_FAIL(
"not applicable to phantoms!");
588 tSwNumberTreeChildren::const_iterator aRemoveIt =
GetIterator(pChild);
596 tSwNumberTreeChildren::const_iterator aItPred =
mChildren.end();
616 (*aItPred)->InvalidateTree();
617 (*aItPred)->NotifyInvalidChildren();
624 if (aItPred !=
mChildren.end() && (*aItPred)->IsPhantom())
635 OSL_FAIL(
"RemoveChild: failed!");
650 while (pSavedParent && pSavedParent->
IsPhantom() &&
652 pSavedParent = pSavedParent->
GetParent();
679 vector<SwNumberTree::tSwNumTreeNumber> aResult;
688 bool bResult =
false;
692 if (pChild && pChild->
mpParent ==
this)
694 bResult = ! (*mItLastValid)->LessThan(*pChild);
704 bool bResult =
false;
708 tSwNumberTreeChildren::const_iterator aIt =
mChildren.begin();
710 bResult = (*aIt)->IsPhantom() && (*aIt)->HasOnlyPhantoms();
729 "<SwNumberTreeNode::HasPhantomCountedParent()> - wrong usage of method - it's only for phantoms" );
751 tSwNumberTreeChildren::const_iterator aIt =
mChildren.begin();
753 if ((*aIt)->IsPhantom())
756 return *aIt == pNode;
801 OSL_FAIL(
"<SwNumberTreeNode::SetLevelInListTree(..)> - parameter <nLevel> out of valid range. Serious defect." );
806 "<SwNumberTreeNode::SetLevelInListTree(..)> - can only be called for number tree nodes in a list tree" );
812 OSL_ENSURE( pRootTreeNode,
813 "<SwNumberTreeNode::SetLevelInListTree(..)> - no root tree node found. Serious defect." );
816 pRootTreeNode->
AddChild(
this, nLevel );
829 SwNumberTreeNode::tSwNumberTreeChildren::size_type
838 vector<const SwNumberTreeNode*> aParents;
840 return IsSane(bRecursive, aParents);
844 vector<const SwNumberTreeNode *> rParents)
847 assert(
find(rParents.begin(), rParents.end(),
this) == rParents.end());
851 rParents.push_back(
this);
858 if (rpChild->IsPhantom())
861 "HasOnlyPhantoms: is this an error?");
863 assert(bFirst &&
"found phantom not at first position.");
866 assert(rpChild->mpParent ==
this);
870 assert(rpChild->IsPhantom() || !rpChild->LessThan(*
this));
875 assert(!
"found child that is NULL");
880 rpChild->IsSane(bRecursive, rParents);
890 SwNumberTreeNode::tSwNumberTreeChildren::const_iterator
893 tSwNumberTreeChildren::const_iterator aItResult =
894 mChildren.find(const_cast<SwNumberTreeNode *>(pChild));
896 OSL_ENSURE( aItResult !=
mChildren.end(),
897 "something went wrong getting the iterator for a child");
905 bool bResult =
false;
907 if (pA ==
nullptr && pB !=
nullptr)
909 else if (pA !=
nullptr && pB !=
nullptr)
918 tSwNumberTreeChildren::const_reverse_iterator aIt =
mChildren.rbegin();
933 return this < &rTreeNode;
942 tSwNumberTreeChildren::const_iterator aIt =
969 (
const SwNumberTreeNode::tSwNumberTreeChildren::const_iterator& aItValid,
970 bool bValidating )
const
972 OSL_ENSURE( (aItValid == mChildren.end() || GetIterator(*aItValid) != mChildren.end()),
973 "last-valid iterator");
977 aItValid == mChildren.end() ||
978 (mItLastValid != mChildren.end() &&
979 (*aItValid)->LessThan(**mItLastValid))
982 mItLastValid = aItValid;
986 tSwNumberTreeChildren::const_iterator aParentChildIt =
987 GetParent()->GetIterator(
this );
989 if ( aParentChildIt != GetParent()->mChildren.end() )
1003 tSwNumberTreeChildren::const_iterator aIt = mItLastValid;
1005 if (aIt != mChildren.end())
1008 aIt = mChildren.begin();
1010 while (aIt != mChildren.end())
1012 (*aIt)->InvalidateTree();
1031 rpChild->InvalidateTree();
1038 tSwNumberTreeChildren::const_iterator aIt =
GetIterator(pChild);
1078 tSwNumberTreeChildren::const_iterator aIt =
mItLastValid;
1094 tSwNumberTreeChildren::const_iterator aParentChildIt =
1127 tSwNumberTreeChildren::const_iterator aUpperBoundIt =
1128 mChildren.upper_bound( const_cast<SwNumberTreeNode*>(&rNode) );
1129 if ( aUpperBoundIt !=
mChildren.begin() )
1136 if ( pPrecedingNode ==
nullptr &&
GetRoot() )
1144 pPrecedingNode =
this;
1148 return pPrecedingNode;
1153 if ( nListLevel < 0 )
1155 OSL_FAIL(
"<SwNumberTreeNode::NotifyNodesOnListLevel(..)> - invalid list level provided" );
1166 OSL_ENSURE( nDepth >= 0,
1167 "<SwNumberTreeNode::NotifyChildrenOnDepth(..)> - misusage" );
1173 rpChild->NotifyNode();
1177 rpChild->NotifyChildrenOnDepth( nDepth - 1 );
bool HasPhantomCountedParent() const
virtual void NotifyNode()=0
Notifies the node.
void AddChild(SwNumberTreeNode *pChild, const int nDepth)
Add a child.
bool IsValid() const
Returns if this node is valid.
SwNumberTreeNode * GetLastDescendant() const
Returns the last descendant of a node, if it has children.
bool IsFirst() const
Return if this node if the first non-phantom node in the tree.
virtual bool LessThan(const SwNumberTreeNode &rTreeNode) const
Returns if this node is less than another node.
A tree of numbered nodes.
const SwNumberTreeNode * GetPrecedingNodeOf(const SwNumberTreeNode &rNode) const
determines the node, which is preceding the node
virtual SwNumberTree::tSwNumTreeNumber GetStartValue() const =0
Return start value.
void SetLevelInListTree(const int nLevel)
set level 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...
SwNumberTreeNode * GetParent() const
Returns the parent of this node.
void RemoveChild(SwNumberTreeNode *pChild)
Remove a child.
void ClearObsoletePhantoms()
Removes recursively phantoms that have no children.
virtual bool HasCountedChildren() const =0
bool SwNumberTreeNodeLessThan(const SwNumberTreeNode *pA, const SwNumberTreeNode *pB)
void Validate(const SwNumberTreeNode *pNode) const
Validates a child.
SwNumberTree::tNumberVector GetNumberVector() const
Returns level numbers of this node.
void GetNumberVector_(SwNumberTree::tNumberVector &rVector, bool bValidate=true) const
Calls GetNumberVector_ on parent and adds number of this node at the end.
int GetLevelInListTree() const
Return level of this node.
OSQLColumns::const_iterator find(const OSQLColumns::const_iterator &first, const OSQLColumns::const_iterator &last, std::u16string_view _rVal, const ::comphelper::UStringMixEqual &_rCase)
SwNumberTreeNode * GetRoot() const
Returns the root node of the tree this node is part of.
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
tSwNumberTreeChildren::const_iterator GetIterator(const SwNumberTreeNode *pChild) const
tSwNumberTreeChildren mChildren
the children
void InvalidateMe()
Notifies the node.
void NotifyInvalidChildren()
Notifies all invalid children of this node.
void MoveChildren(SwNumberTreeNode *pDest)
Moves all children to a given destination node.
bool mbPhantom
true this node is a phantom false this node is NOT a phantom
bool IsPhantom() const
Return if this node is a phantom.
tools::Long tSwNumTreeNumber
void SetLastValid(const tSwNumberTreeChildren::const_iterator &aItLastValid, bool bValidating=false) const
Set the last valid child of this node.
void ValidateHierarchical(const SwNumberTreeNode *pNode) const
Validates a child using hierarchical numbering.
void Invalidate(SwNumberTreeNode const *pChild)
Invalidates a child.
void RemoveMe()
Remove this child from the tree.
SwNumberTreeNode * CreatePhantom()
Creates a phantom.
virtual bool IsContinuous() const =0
Return if this node is counted continuous.
SwNumberTreeNode * mpParent
he parent node
bool IsValid(const SwNumberTreeNode *pChild) const
Returns if a child A this node is valid.
tSwNumberTreeChildren::const_iterator mItLastValid
Iterator to the last valid element.
SwNumberTree::tSwNumTreeNumber GetNumber(bool bValidate=true) const
Returns number of this node.
virtual ~SwNumberTreeNode()
void ValidateMe()
Validates this node.
SwNumberTreeNode * GetFirstNonPhantomChild()
HB, OD : return node, if it isn't a phantom, otherwise return first non-phantom descendant.
void IsSane(bool bRecursive) const
Sanity check.
std::vector< tSwNumTreeNumber > tNumberVector
RegionData_Impl * mpParent
virtual bool IsCountPhantoms() const =0
Return if phantoms are counted.
void ValidateContinuous(const SwNumberTreeNode *pNode) const
Validates a child using continuous numbering.
void InvalidateChildren()
Invalidation of all children.
void MoveGreaterChildren(SwNumberTreeNode &_rCompareNode, SwNumberTreeNode &_rDestNode)
Moves all children of this node that are greater than a given node to the destination node...
#define SAL_WARN_IF(condition, area, stream)
bool HasOnlyPhantoms() const
Return if all descendants of this node are phantoms.
tSwNumberTreeChildren::size_type GetChildCount() const
Returns how many children this node has got.
void Notify()
Notifies this node (NotifyNode) and all descendants.
virtual SwNumberTreeNode * Create() const =0
Creates a new node of the same class.
void NotifyChildrenOnDepth(const int nDepth)
notification of children nodes on certain depth
virtual void PostRemove()=0
void NotifyInvalidSiblings()
Notifies all invalid siblings of this node.
SwNumberTree::tSwNumTreeNumber mnNumber
the number of the node
void InvalidateTree() const
Invalidate this node and all its descendants.
virtual bool IsCounted() const
Return if this node is counted.
virtual bool IsNotificationEnabled() const =0
Return if the notification is not disabled on global conditions.
void NotifyNodesOnListLevel(const int nListLevel)
notification of all nodes in the list tree on certain list level
virtual bool IsNotifiable() const =0
Return if this node is notifiable.