Kaydet (Commit) ea3e7188 authored tarafından Michael Stahl's avatar Michael Stahl

sw: convert SwNumberTree::IsSane to assert() and simplify

Change-Id: Ib2087a53d2a22f5fdafa5c3d0d058dd0ad8ed643
üst a0dc0d3c
...@@ -346,7 +346,7 @@ public: ...@@ -346,7 +346,7 @@ public:
@retval true the structure of this node is sane @retval true the structure of this node is sane
@retval false else @retval false else
*/ */
bool IsSane(bool bRecursive) const; void IsSane(bool bRecursive) const;
#endif // DBG_UTIL #endif // DBG_UTIL
protected: protected:
...@@ -391,15 +391,12 @@ protected: ...@@ -391,15 +391,12 @@ protected:
virtual void PostRemove() = 0; virtual void PostRemove() = 0;
#ifdef DBG_UTIL #ifdef DBG_UTIL
/** /** Sanity check with loop detection.
Sanity check with loop detection.
@param bRecursive descend to children @param bRecursive descend to children
@param rParents vector for recording path @param rParents vector for recording path
*/
@retval true this node is sane virtual void IsSane
@retval false else */
virtual bool IsSane
(bool bRecursive, std::vector<const SwNumberTreeNode *> rParents) const; (bool bRecursive, std::vector<const SwNumberTreeNode *> rParents) const;
#endif // DBG_UTIL #endif // DBG_UTIL
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <sal/log.hxx> #include <sal/log.hxx>
#include <cassert>
using std::vector; using std::vector;
using std::find; using std::find;
...@@ -385,7 +387,8 @@ void SwNumberTreeNode::MoveGreaterChildren( SwNumberTreeNode& _rCompareNode, ...@@ -385,7 +387,8 @@ void SwNumberTreeNode::MoveGreaterChildren( SwNumberTreeNode& _rCompareNode,
} }
#ifdef DBG_UTIL #ifdef DBG_UTIL
SAL_WARN_IF(!IsSane(false) || !_rDestNode.IsSane(true), "sw.core", "insanity"); IsSane(false);
_rDestNode.IsSane(true);
#endif #endif
} }
...@@ -433,7 +436,8 @@ void SwNumberTreeNode::MoveChildren(SwNumberTreeNode * pDest) ...@@ -433,7 +436,8 @@ void SwNumberTreeNode::MoveChildren(SwNumberTreeNode * pDest)
OSL_ENSURE(mChildren.empty(), "MoveChildren failed!"); OSL_ENSURE(mChildren.empty(), "MoveChildren failed!");
#ifdef DBG_UTIL #ifdef DBG_UTIL
OSL_ENSURE(IsSane(false) && pDest->IsSane(false), "insanity!"); IsSane(false);
pDest->IsSane(false);
#endif #endif
} }
...@@ -585,7 +589,7 @@ void SwNumberTreeNode::AddChild( SwNumberTreeNode * pChild, ...@@ -585,7 +589,7 @@ void SwNumberTreeNode::AddChild( SwNumberTreeNode * pChild,
} }
#ifdef DBG_UTIL #ifdef DBG_UTIL
SAL_WARN_IF(!IsSane(false), "sw.core", "insanity"); IsSane(false);
#endif #endif
} }
...@@ -678,7 +682,7 @@ void SwNumberTreeNode::RemoveMe() ...@@ -678,7 +682,7 @@ void SwNumberTreeNode::RemoveMe()
pSavedParent->ClearObsoletePhantoms(); pSavedParent->ClearObsoletePhantoms();
#ifdef DBG_UTIL #ifdef DBG_UTIL
SAL_WARN_IF(!IsSane(false), "sw.core", "insanity"); IsSane(false);
#endif #endif
} }
} }
...@@ -857,34 +861,22 @@ SwNumberTreeNode::GetChildCount() const ...@@ -857,34 +861,22 @@ SwNumberTreeNode::GetChildCount() const
} }
#ifdef DBG_UTIL #ifdef DBG_UTIL
bool SwNumberTreeNode::IsSane(bool bRecursive) const void SwNumberTreeNode::IsSane(bool bRecursive) const
{ {
vector<const SwNumberTreeNode*> aParents; vector<const SwNumberTreeNode*> aParents;
return IsSane(bRecursive, aParents); return IsSane(bRecursive, aParents);
} }
bool SwNumberTreeNode::IsSane(bool bRecursive, void SwNumberTreeNode::IsSane(bool bRecursive,
vector<const SwNumberTreeNode *> rParents) vector<const SwNumberTreeNode *> rParents)
const const
{ {
bool bResult = true;
tSwNumberTreeChildren::const_iterator aIt; tSwNumberTreeChildren::const_iterator aIt;
if (find(rParents.begin(), rParents.end(), this) != rParents.end()) assert(find(rParents.begin(), rParents.end(), this) == rParents.end());
{
OSL_FAIL(" I'm my own ancestor!");
bResult = false;
}
if (! rParents.empty() && rParents.back() != mpParent) assert(rParents.empty() || rParents.back() == mpParent);
{
OSL_FAIL(" I'm a bastard!");
bResult = false;
}
rParents.push_back(this); rParents.push_back(this);
...@@ -895,49 +887,33 @@ bool SwNumberTreeNode::IsSane(bool bRecursive, ...@@ -895,49 +887,33 @@ bool SwNumberTreeNode::IsSane(bool bRecursive,
{ {
if ((*aIt)->IsPhantom()) if ((*aIt)->IsPhantom())
{ {
if ((*aIt)->HasOnlyPhantoms()) SAL_WARN_IF((*aIt)->HasOnlyPhantoms(), "sw.core",
{ "HasOnlyPhantoms: is this an error?");
bResult = false;
}
if (! bFirst) assert(bFirst && "found phantom not at first position.");
{
OSL_FAIL(" found phantom not at first position.");
bResult = false;
}
} }
if ((*aIt)->mpParent != (SwNumberTreeNode *) this) assert((*aIt)->mpParent == this);
{
OSL_FAIL("found a bastard");
bResult = false;
}
if (mpParent) if (mpParent)
{ {
if (!(*aIt)->IsPhantom() && (*aIt)->LessThan(*this)) assert((*aIt)->IsPhantom() || !(*aIt)->LessThan(*this));
{
OSL_FAIL(" found child less than me");
bResult = false;
}
} }
} }
else else
{ {
OSL_FAIL("found child that is NULL"); assert(!"found child that is NULL");
bResult = false;
} }
if (bRecursive) if (bRecursive)
bResult = (*aIt)->IsSane(bRecursive, rParents) && bResult; {
(*aIt)->IsSane(bRecursive, rParents);
}
bFirst = false;
} }
rParents.pop_back(); rParents.pop_back();
return bResult;
} }
#endif // DBG_UTIL #endif // DBG_UTIL
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment