[Libreoffice-commits] core.git: starmath/inc starmath/source
Takeshi Abe
tabe at fixedpoint.jp
Tue Dec 22 16:40:28 PST 2015
starmath/inc/cursor.hxx | 5 +++--
starmath/source/cursor.cxx | 36 +++++++++---------------------------
2 files changed, 12 insertions(+), 29 deletions(-)
New commits:
commit 4753d78cf93bad974f062d8cfe75b4b610385b7e
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date: Wed Dec 16 18:02:30 2015 +0900
starmath: Assert that a parent always finds its child
Change-Id: I6cb75e0d62141dba2809aaec62761cedd8c3257a
Reviewed-on: https://gerrit.libreoffice.org/20733
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Kohei Yoshida <libreoffice at kohei.us>
diff --git a/starmath/inc/cursor.hxx b/starmath/inc/cursor.hxx
index 9de6b53..6962cf5 100644
--- a/starmath/inc/cursor.hxx
+++ b/starmath/inc/cursor.hxx
@@ -12,6 +12,7 @@
#include "node.hxx"
#include "caret.hxx"
+#include <cassert>
#include <list>
#include <memory>
@@ -268,8 +269,8 @@ private:
SmNode* pNode = rpNode;
if(rpNode && rpNode->GetParent()){ //Don't remove this, correctness relies on it
int index = rpNode->GetParent()->IndexOfSubNode(rpNode);
- if(index != -1)
- rpNode->GetParent()->SetSubNode(index, nullptr);
+ assert(index >= 0);
+ rpNode->GetParent()->SetSubNode(index, nullptr);
}
rpNode = nullptr;
//Create line from node
diff --git a/starmath/source/cursor.cxx b/starmath/source/cursor.cxx
index 8efa931..355336c 100644
--- a/starmath/source/cursor.cxx
+++ b/starmath/source/cursor.cxx
@@ -12,6 +12,7 @@
#include "view.hxx"
#include "accessibility.hxx"
#include <comphelper/string.hxx>
+#include <cassert>
void SmCursor::Move(OutputDevice* pDev, SmMovementDirection direction, bool bMoveAnchor){
SmCaretPosGraphEntry* NewPos = nullptr;
@@ -176,6 +177,7 @@ void SmCursor::DeletePrev(OutputDevice* pDev){
SmNode* pLine = FindTopMostNodeInLine(mpPosition->CaretPos.pSelectedNode);
SmStructureNode* pLineParent = pLine->GetParent();
int nLineOffset = pLineParent->IndexOfSubNode(pLine);
+ assert(nLineOffset >= 0);
//If we're in front of a node who's parent is a TABLE
if(pLineParent->GetType() == NTABLE && mpPosition->CaretPos.Index == 0 && nLineOffset > 0){
@@ -262,11 +264,7 @@ void SmCursor::Delete(){
SmStructureNode* pLineParent = pLine->GetParent();
//Find line offset in parent
int nLineOffset = pLineParent->IndexOfSubNode(pLine);
- if (nLineOffset == -1)
- {
- SAL_WARN("starmath", "pLine must be a child of its parent!");
- return;
- }
+ assert(nLineOffset >= 0);
//Position after delete
SmCaretPos PosAfterDelete;
@@ -304,12 +302,7 @@ void SmCursor::InsertNodes(SmNodeList* pNewNodes){
//Find line parent and line index in parent
SmStructureNode* pLineParent = pLine->GetParent();
int nParentIndex = pLineParent->IndexOfSubNode(pLine);
- OSL_ENSURE(nParentIndex != -1, "pLine must be a subnode of pLineParent!");
- if (nParentIndex == -1)
- {
- delete pNewNodes;
- return;
- }
+ assert(nParentIndex >= 0);
//Convert line to list
SmNodeList* pLineList = NodeToList(pLine);
@@ -506,7 +499,7 @@ void SmCursor::InsertSubSup(SmSubSup eSubSup) {
//Find Parent and offset in parent
SmStructureNode *pLineParent = pLine->GetParent();
int nParentIndex = pLineParent->IndexOfSubNode(pLine);
- OSL_ENSURE(nParentIndex != -1, "pLine must be a subnode of pLineParent!");
+ assert(nParentIndex >= 0);
//TODO: Consider handling special cases where parent is an SmOperNode,
// Maybe this method should be able to add limits to an SmOperNode...
@@ -677,9 +670,7 @@ void SmCursor::InsertBrackets(SmBracketType eBracketType) {
//Find parent and offset in parent
SmStructureNode *pLineParent = pLine->GetParent();
int nParentIndex = pLineParent->IndexOfSubNode(pLine);
- OSL_ENSURE( nParentIndex != -1, "pLine must be a subnode of pLineParent!");
- if (nParentIndex < 0)
- return;
+ assert(nParentIndex >= 0);
//Convert line to list
SmNodeList *pLineList = NodeToList(pLine);
@@ -814,12 +805,7 @@ bool SmCursor::InsertRow() {
//Find parent and offset in parent
SmStructureNode *pLineParent = pLine->GetParent();
int nParentIndex = pLineParent->IndexOfSubNode(pLine);
-
- if (nParentIndex == -1)
- {
- SAL_WARN("starmath", "pLine must be a subnode of pLineParent!");
- return false;
- }
+ assert(nParentIndex >= 0);
//Discover the context of this command
SmTableNode *pTable = nullptr;
@@ -834,7 +820,7 @@ bool SmCursor::InsertRow() {
//NOTE: This hack might give problems if we stop ignoring SmAlignNode
pTable = static_cast<SmTableNode*>(pLineParent->GetParent());
nTableIndex = pTable->IndexOfSubNode(pLineParent);
- OSL_ENSURE(nTableIndex != -1, "pLineParent must be a child of its parent!");
+ assert(nTableIndex >= 0);
}
if(pLineParent->GetType() == NMATRIX)
pMatrix = static_cast<SmMatrixNode*>(pLineParent);
@@ -938,11 +924,7 @@ void SmCursor::InsertFraction() {
//Find Parent and offset in parent
SmStructureNode *pLineParent = pLine->GetParent();
int nParentIndex = pLineParent->IndexOfSubNode(pLine);
- if (nParentIndex == -1)
- {
- SAL_WARN("starmath", "pLine must be a subnode of pLineParent!");
- return;
- }
+ assert(nParentIndex >= 0);
//We begin modifying the tree here
BeginEdit();
More information about the Libreoffice-commits
mailing list