diff --git a/poincare/include/poincare/absolute_value_layout_node.h b/poincare/include/poincare/absolute_value_layout_node.h index 933fffcd8..301244298 100644 --- a/poincare/include/poincare/absolute_value_layout_node.h +++ b/poincare/include/poincare/absolute_value_layout_node.h @@ -28,7 +28,7 @@ class AbsoluteValueLayoutRef : public LayoutReference { public: AbsoluteValueLayoutRef(TreeNode * n) : LayoutReference(n) {} AbsoluteValueLayoutRef(LayoutRef l) : AbsoluteValueLayoutRef() { - replaceTreeChildAtIndex(0, l); + replaceChildAtIndexInPlace(0, l); } private: AbsoluteValueLayoutRef() : LayoutReference(TreePool::sharedPool()->createTreeNode(), true) {} diff --git a/poincare/include/poincare/binomial_coefficient_layout_node.h b/poincare/include/poincare/binomial_coefficient_layout_node.h index 505512c88..6efcc6c6f 100644 --- a/poincare/include/poincare/binomial_coefficient_layout_node.h +++ b/poincare/include/poincare/binomial_coefficient_layout_node.h @@ -45,8 +45,8 @@ public: BinomialCoefficientLayoutRef(LayoutRef n, LayoutRef k) : BinomialCoefficientLayoutRef() { - replaceTreeChildAtIndex(0, n); - replaceTreeChildAtIndex(1, k); + replaceChildAtIndexInPlace(0, n); + replaceChildAtIndexInPlace(1, k); } BinomialCoefficientLayoutRef(TreeNode * n) : LayoutReference(n) {} private: diff --git a/poincare/include/poincare/ceiling_layout_node.h b/poincare/include/poincare/ceiling_layout_node.h index 5486a6c5f..ed0f4ba48 100644 --- a/poincare/include/poincare/ceiling_layout_node.h +++ b/poincare/include/poincare/ceiling_layout_node.h @@ -26,7 +26,7 @@ class CeilingLayoutRef : public LayoutReference { public: CeilingLayoutRef(TreeNode * n) : LayoutReference(n) {} CeilingLayoutRef(LayoutRef l) : CeilingLayoutRef() { - replaceTreeChildAtIndex(0, l); + replaceChildAtIndexInPlace(0, l); } private: CeilingLayoutRef() : LayoutReference(TreePool::sharedPool()->createTreeNode(), true) {} diff --git a/poincare/include/poincare/condensed_sum_layout_node.h b/poincare/include/poincare/condensed_sum_layout_node.h index be940d1a0..93c6b40fd 100644 --- a/poincare/include/poincare/condensed_sum_layout_node.h +++ b/poincare/include/poincare/condensed_sum_layout_node.h @@ -51,9 +51,9 @@ public: CondensedSumLayoutRef(LayoutRef base, LayoutRef subscript, LayoutRef superscript) : CondensedSumLayoutRef() { - replaceTreeChildAtIndex(0, base); - replaceTreeChildAtIndex(1, subscript); - replaceTreeChildAtIndex(2, superscript); + replaceChildAtIndexInPlace(0, base); + replaceChildAtIndexInPlace(1, subscript); + replaceChildAtIndexInPlace(2, superscript); } CondensedSumLayoutRef(TreeNode * n) : LayoutReference(n) {} diff --git a/poincare/include/poincare/floor_layout_node.h b/poincare/include/poincare/floor_layout_node.h index 324464189..c3cf221f0 100644 --- a/poincare/include/poincare/floor_layout_node.h +++ b/poincare/include/poincare/floor_layout_node.h @@ -27,7 +27,7 @@ class FloorLayoutRef : public LayoutReference { public: FloorLayoutRef(TreeNode * n) : LayoutReference(n) {} FloorLayoutRef(LayoutRef l) : FloorLayoutRef() { - replaceTreeChildAtIndex(0, l); + replaceChildAtIndexInPlace(0, l); } private: FloorLayoutRef() : LayoutReference(TreePool::sharedPool()->createTreeNode(), true) {} diff --git a/poincare/include/poincare/fraction_layout_node.h b/poincare/include/poincare/fraction_layout_node.h index 52b9adff8..8fe8308bf 100644 --- a/poincare/include/poincare/fraction_layout_node.h +++ b/poincare/include/poincare/fraction_layout_node.h @@ -56,8 +56,8 @@ public: FractionLayoutRef(LayoutRef numerator, LayoutRef denominator) : FractionLayoutRef() { - replaceTreeChildAtIndex(0, numerator); - replaceTreeChildAtIndex(1, denominator); + replaceChildAtIndexInPlace(0, numerator); + replaceChildAtIndexInPlace(1, denominator); } FractionLayoutRef(TreeNode * n) : LayoutReference(n) {} private: diff --git a/poincare/include/poincare/integral_layout_node.h b/poincare/include/poincare/integral_layout_node.h index b3bb15485..f3ffd6cdd 100644 --- a/poincare/include/poincare/integral_layout_node.h +++ b/poincare/include/poincare/integral_layout_node.h @@ -58,9 +58,9 @@ public: IntegralLayoutRef(LayoutRef integrand, LayoutRef lowerBound, LayoutRef upperBound) : IntegralLayoutRef() { - replaceTreeChildAtIndex(0, integrand); - replaceTreeChildAtIndex(1, lowerBound); - replaceTreeChildAtIndex(2, upperBound); + replaceChildAtIndexInPlace(0, integrand); + replaceChildAtIndexInPlace(1, lowerBound); + replaceChildAtIndexInPlace(2, upperBound); } IntegralLayoutRef(TreeNode * n) : LayoutReference(n) {} private: diff --git a/poincare/include/poincare/layout_reference.h b/poincare/include/poincare/layout_reference.h index 02edba7f3..ff262d312 100644 --- a/poincare/include/poincare/layout_reference.h +++ b/poincare/include/poincare/layout_reference.h @@ -78,13 +78,13 @@ public: //Add void addSibling(LayoutCursor * cursor, LayoutReference sibling, bool moveCursor); // Replace - //void replaceChildAtIndex(int oldChildIndex, LayoutReference newChild) { TreeReference::replaceTreeChildAtIndex(oldChildIndex, newChild); } + //void replaceChildAtIndex(int oldChildIndex, LayoutReference newChild) { TreeReference::replaceChildAtIndexInPlace(oldChildIndex, newChild); } void replaceChild(LayoutReference oldChild, LayoutReference newChild, LayoutCursor * cursor = nullptr, bool force = false); void replaceChildWithEmpty(LayoutReference oldChild, LayoutCursor * cursor = nullptr); void replaceWith(LayoutReference newChild, LayoutCursor * cursor) { LayoutReference p = parent(); assert(p.isDefined()); - p.replaceChild(*this, newChild, cursor); + p.replaceChildInPlace(*this, newChild, cursor); } void replaceWithJuxtapositionOf(LayoutReference leftChild, LayoutReference rightChild, LayoutCursor * cursor, bool putCursorInTheMiddle = false); // Collapse diff --git a/poincare/include/poincare/nth_root_layout_node.h b/poincare/include/poincare/nth_root_layout_node.h index ad2652260..c6b4145d8 100644 --- a/poincare/include/poincare/nth_root_layout_node.h +++ b/poincare/include/poincare/nth_root_layout_node.h @@ -69,11 +69,11 @@ public: NthRootLayoutRef(TreeNode * n) : LayoutReference(n) {} NthRootLayoutRef(LayoutRef radicand) : NthRootLayoutRef() { - replaceTreeChildAtIndex(radicand, 0, 0); + replaceChildAtIndexInPlace(radicand, 0, 0); } NthRootLayoutRef(LayoutRef radicand, LayoutRef index) : NthRootLayoutRef() { - replaceTreeChildAtIndex(0, radicand); + replaceChildAtIndexInPlace(0, radicand); addChildTreeAtIndex(index, 1, 1); if (!node()->isAllocationFailure()) { static_cast(node())->setNumberOfChildren(2); diff --git a/poincare/include/poincare/opposite.h b/poincare/include/poincare/opposite.h index 82093fd93..e8419c8d2 100644 --- a/poincare/include/poincare/opposite.h +++ b/poincare/include/poincare/opposite.h @@ -43,7 +43,7 @@ private: class OppositeReference : public ExpressionReference { public: OppositeReference(ExpressionReference operand) : ExpressionReference(TreePool::sharedPool()->createTreeNode(), true) { - replaceTreeChildAtIndex(0, operand); + replaceChildAtIndexInPlace(0, operand); } }; diff --git a/poincare/include/poincare/parenthesis.h b/poincare/include/poincare/parenthesis.h index cf9852813..b8467c63e 100644 --- a/poincare/include/poincare/parenthesis.h +++ b/poincare/include/poincare/parenthesis.h @@ -37,7 +37,7 @@ private: class ParenthesisReference : public ExpressionReference { public: ParenthesisReference(ExpressionReference exp) : ExpressionReference(TreePool::sharedPool()->createTreeNode(), true) { - replaceTreeChildAtIndex(0, exp); + replaceChildAtIndexInPlace(0, exp); } }; diff --git a/poincare/include/poincare/product_layout_node.h b/poincare/include/poincare/product_layout_node.h index 32f1babb3..19ca2a356 100644 --- a/poincare/include/poincare/product_layout_node.h +++ b/poincare/include/poincare/product_layout_node.h @@ -27,9 +27,9 @@ public: ProductLayoutRef(LayoutRef argument, LayoutRef lowerB, LayoutRef upperB) : ProductLayoutRef() { - replaceTreeChildAtIndex(0, argument); - replaceTreeChildAtIndex(1, lowerB); - replaceTreeChildAtIndex(2, upperB); + replaceChildAtIndexInPlace(0, argument); + replaceChildAtIndexInPlace(1, lowerB); + replaceChildAtIndexInPlace(2, upperB); } private: ProductLayoutRef() : LayoutReference(TreePool::sharedPool()->createTreeNode(), true) {} diff --git a/poincare/include/poincare/sum_layout_node.h b/poincare/include/poincare/sum_layout_node.h index b1fbd923a..1d2656f4f 100644 --- a/poincare/include/poincare/sum_layout_node.h +++ b/poincare/include/poincare/sum_layout_node.h @@ -20,9 +20,9 @@ public: SumLayoutRef(LayoutRef argument, LayoutRef lowerB, LayoutRef upperB) : SumLayoutRef() { - replaceTreeChildAtIndex(0, argument); - replaceTreeChildAtIndex(1, lowerB); - replaceTreeChildAtIndex(2, upperB); + replaceChildAtIndexInPlace(0, argument); + replaceChildAtIndexInPlace(1, lowerB); + replaceChildAtIndexInPlace(2, upperB); } private: SumLayoutRef() : LayoutReference(TreePool::sharedPool()->createTreeNode(), true) {} diff --git a/poincare/include/poincare/tree_by_reference.h b/poincare/include/poincare/tree_by_reference.h index 5a411efb1..4736434cc 100644 --- a/poincare/include/poincare/tree_by_reference.h +++ b/poincare/include/poincare/tree_by_reference.h @@ -86,19 +86,19 @@ public: /* Hierarchy operations */ // Replace - void replaceWith(TreeByReference t); - void replaceTreeChild(TreeByReference oldChild, TreeByReference newChild); - void replaceTreeChildAtIndex(int oldChildIndex, TreeByReference newChild) { + void replaceWithInPlace(TreeByReference t); + void replaceChildInPlace(TreeByReference oldChild, TreeByReference newChild); + void replaceChildAtIndexInPlace(int oldChildIndex, TreeByReference newChild) { assert(oldChildIndex >= 0 && oldChildIndex < numberOfChildren()); TreeByReference oldChild = treeChildAtIndex(oldChildIndex); - replaceTreeChild(oldChild, newChild); + replaceChildInPlace(oldChild, newChild); } - void replaceWithAllocationFailure(int currentNumberOfChildren); - void replaceChildWithGhost(TreeByReference t); + void replaceWithAllocationFailureInPlace(int currentNumberOfChildren); + void replaceChildWithGhostInPlace(TreeByReference t); // Merge - void mergeTreeChildrenAtIndex(TreeByReference t, int i); + void mergeChildrenAtIndexInPlace(TreeByReference t, int i); // Swap - void swapChildren(int i, int j); + void swapChildrenInPlace(int i, int j); protected: /* Constructor */ @@ -115,12 +115,12 @@ protected: /* Hierarchy operations */ // Add - virtual void addChildTreeAtIndex(TreeByReference t, int index, int currentNumberOfChildren); + virtual void addChildAtIndexInPlace(TreeByReference t, int index, int currentNumberOfChildren); // Remove puts a child at the end of the pool - virtual void removeChildTreeAtIndex(int i); - virtual void removeChildTree(TreeByReference t, int childNumberOfChildren); - virtual void removeChildren(int currentNumberOfChildren); - virtual void removeChildrenAndDestroy(int currentNumberOfChildren); + virtual void removeChildAtIndexInPlace(int i); + virtual void removeChildInPlace(TreeByReference t, int childNumberOfChildren); + virtual void removeChildrenInPlace(int currentNumberOfChildren); + virtual void removeChildrenAndDestroyInPlace(int currentNumberOfChildren); int m_identifier; private: diff --git a/poincare/include/poincare/vertical_offset_layout_node.h b/poincare/include/poincare/vertical_offset_layout_node.h index aabf9eff9..58c02a59b 100644 --- a/poincare/include/poincare/vertical_offset_layout_node.h +++ b/poincare/include/poincare/vertical_offset_layout_node.h @@ -66,7 +66,7 @@ public: if (!(node()->isAllocationFailure())) { static_cast(node())->setType(type); } - replaceTreeChildAtIndex(0,l); + replaceChildAtIndexInPlace(0,l); } private: VerticalOffsetLayoutRef() : LayoutReference(TreePool::sharedPool()->createTreeNode(), true) {} diff --git a/poincare/src/bracket_pair_layout_node.cpp b/poincare/src/bracket_pair_layout_node.cpp index b92589d1f..191434929 100644 --- a/poincare/src/bracket_pair_layout_node.cpp +++ b/poincare/src/bracket_pair_layout_node.cpp @@ -73,7 +73,7 @@ void BracketPairLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * should void BracketPairLayoutNode::deleteBeforeCursor(LayoutCursor * cursor) { if (cursor->isEquivalentTo(LayoutCursor(childLayout(), LayoutCursor::Position::Left))) { // Case: Left of the operand. Delete the layout, keep the operand. - LayoutRef(this).replaceWith(LayoutRef(childLayout()), cursor); + LayoutRef(this).replaceWithInPlace(LayoutRef(childLayout()), cursor); // WARNING: do not call "this" afterwards return; } diff --git a/poincare/src/empty_layout_node.cpp b/poincare/src/empty_layout_node.cpp index 906935d09..c179497f4 100644 --- a/poincare/src/empty_layout_node.cpp +++ b/poincare/src/empty_layout_node.cpp @@ -87,7 +87,7 @@ bool EmptyLayoutNode::willAddSibling(LayoutCursor * cursor, LayoutNode * sibling thisRef.setColor(Color::Yellow); return true; } else { - thisRef.replaceWith(siblingRef, cursor); + thisRef.replaceWithInPlace(siblingRef, cursor); // WARNING: do not call "this" afterwards return false; } diff --git a/poincare/src/fraction_layout_node.cpp b/poincare/src/fraction_layout_node.cpp index 120d1e014..65b54adff 100644 --- a/poincare/src/fraction_layout_node.cpp +++ b/poincare/src/fraction_layout_node.cpp @@ -100,7 +100,7 @@ void FractionLayoutNode::deleteBeforeCursor(LayoutCursor * cursor) { if (numeratorLayout()->isEmpty() && denominatorLayout()->isEmpty()) { /* Case: Numerator and denominator are empty. Move the cursor and replace * the fraction with an empty layout. */ - thisRef.replaceWith(EmptyLayoutRef(), cursor); + thisRef.replaceWithInPlace(EmptyLayoutRef(), cursor); // WARNING: Do no use "this" afterwards return; } diff --git a/poincare/src/horizontal_layout_node.cpp b/poincare/src/horizontal_layout_node.cpp index 05719ba40..c9e63afce 100644 --- a/poincare/src/horizontal_layout_node.cpp +++ b/poincare/src/horizontal_layout_node.cpp @@ -278,7 +278,7 @@ bool HorizontalLayoutNode::willReplaceChild(LayoutNode * oldChild, LayoutNode * * a parent, replace this with the new empty layout. */ LayoutNode * p = parent(); if (p != nullptr) { - thisRef.replaceWith(newChild, cursor); + thisRef.replaceWithInPlace(newChild, cursor); // WARNING: do not call "this" afterwards return false; } @@ -374,7 +374,7 @@ void HorizontalLayoutRef::mergeChildrenAtIndex(HorizontalLayoutRef h, int index, } // Merge the horizontal layout - mergeTreeChildrenAtIndex(h, newIndex); + mergeChildrenAtIndexInPlace(h, newIndex); if (cursor != nullptr) { if (!isAllocationFailure()) { diff --git a/poincare/src/integral_layout_node.cpp b/poincare/src/integral_layout_node.cpp index 6e6f55e1c..3176f80c1 100644 --- a/poincare/src/integral_layout_node.cpp +++ b/poincare/src/integral_layout_node.cpp @@ -132,7 +132,7 @@ void IntegralLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shouldReco void IntegralLayoutNode::deleteBeforeCursor(LayoutCursor * cursor) { if (cursor->isEquivalentTo(LayoutCursor(integrandLayout(), LayoutCursor::Position::Left))) { // Case: Left of the integrand. Delete the layout, keep the integrand. - LayoutRef(this).replaceWith(LayoutRef(integrandLayout()), cursor); + LayoutRef(this).replaceWithInPlace(LayoutRef(integrandLayout()), cursor); // WARNING: Do not use "this" afterwards return; } diff --git a/poincare/src/layout_cursor.cpp b/poincare/src/layout_cursor.cpp index 37f088ee2..afec5bc52 100644 --- a/poincare/src/layout_cursor.cpp +++ b/poincare/src/layout_cursor.cpp @@ -222,7 +222,7 @@ void LayoutCursor::addLayoutAndMoveCursor(LayoutRef l) { void LayoutCursor::clearLayout() { LayoutRef rootLayoutR = m_layoutRef.root(); assert(rootLayoutR.isHorizontal()); - rootLayoutR.removeChildren(); + rootLayoutR.removeChildrenInPlace(); m_layoutRef = rootLayoutR; } diff --git a/poincare/src/layout_reference.cpp b/poincare/src/layout_reference.cpp index 41e9de069..13ef1a772 100644 --- a/poincare/src/layout_reference.cpp +++ b/poincare/src/layout_reference.cpp @@ -26,7 +26,7 @@ void LayoutReference::replaceChild(LayoutRef oldChild, LayoutRef newChild, Layou if (!node()->willReplaceChild(oldChild.node(), newChild.node(), cursor, force)) { return; } - replaceTreeChild(oldChild, newChild); + replaceChildInPlace(oldChild, newChild); if (cursor != nullptr) { if (isAllocationFailure()) { cursor->setLayoutReference(*this); @@ -107,7 +107,7 @@ void LayoutReference::addChildAtIndex(LayoutRef l, int index, int currentNumberO } } - this->addChildTreeAtIndex(l, newIndex, newCurrentNumberOfChildren); + this->addChildAtIndexInPlace(l, newIndex, newCurrentNumberOfChildren); if (cursor != nullptr) { if (this->isAllocationFailure()) { @@ -174,7 +174,7 @@ void LayoutReference::removeChild(LayoutRef l, LayoutCursor * cursor, bool force } assert(hasChild(l)); int index = indexOfChild(l); - removeChildTree(l, numberOfChildren()); + removeChildInPlace(l, numberOfChildren()); if (cursor) { if (index < numberOfChildren()) { LayoutRef newCursorRef = childAtIndex(index); diff --git a/poincare/src/matrix_layout_node.cpp b/poincare/src/matrix_layout_node.cpp index 4ef95ef02..e5de9166d 100644 --- a/poincare/src/matrix_layout_node.cpp +++ b/poincare/src/matrix_layout_node.cpp @@ -296,8 +296,8 @@ void MatrixLayoutRef::setDimensions(int rows, int columns) { setNumberOfColumns(columns); } -void MatrixLayoutRef::addChildTreeAtIndex(TreeReference t, int index, int currentNumberOfChildren) { - ExpressionReference::addChildTreeAtIndex(t, index, currentNumberOfChildren); +void MatrixLayoutRef::addChildAtIndexInPlace(TreeReference t, int index, int currentNumberOfChildren) { + TreeByReference::addChildAtIndexInPlace(t, index, currentNumberOfChildren); if (isAllocationFailure()) { return; } diff --git a/poincare/src/nth_root_layout_node.cpp b/poincare/src/nth_root_layout_node.cpp index 3513fec5a..f974f5268 100644 --- a/poincare/src/nth_root_layout_node.cpp +++ b/poincare/src/nth_root_layout_node.cpp @@ -139,7 +139,7 @@ void NthRootLayoutNode::deleteBeforeCursor(LayoutCursor * cursor) { && cursor->position() == LayoutCursor::Position::Left) { // Case: Left of the radicand. Delete the layout, keep the radicand. - NthRootLayoutRef(this).replaceWith(LayoutRef(radicandLayout()), cursor); + NthRootLayoutRef(this).replaceWithInPlace(LayoutRef(radicandLayout()), cursor); // WARNING: Do not call "this" afterwards return; } diff --git a/poincare/src/sequence_layout_node.cpp b/poincare/src/sequence_layout_node.cpp index 688bcc5fe..e5097ca6b 100644 --- a/poincare/src/sequence_layout_node.cpp +++ b/poincare/src/sequence_layout_node.cpp @@ -119,7 +119,7 @@ void SequenceLayoutNode::moveCursorDown(LayoutCursor * cursor, bool * shouldReco void SequenceLayoutNode::deleteBeforeCursor(LayoutCursor * cursor) { if (cursor->isEquivalentTo(LayoutCursor(argumentLayout(), LayoutCursor::Position::Left))) { // Case: Left of the argument. Delete the layout, keep the argument. - LayoutRef(this).replaceWith(LayoutRef(argumentLayout()), cursor); + LayoutRef(this).replaceWithInPlace(LayoutRef(argumentLayout()), cursor); // WARNING: do not use "this" afterwards return; } diff --git a/poincare/src/tree_by_reference.cpp b/poincare/src/tree_by_reference.cpp index 634031337..e59129e6f 100644 --- a/poincare/src/tree_by_reference.cpp +++ b/poincare/src/tree_by_reference.cpp @@ -30,22 +30,22 @@ TreeByReference TreeByReference::clone() const { /* Hierarchy operations */ -void TreeByReference::replaceWith(TreeByReference t) { +void TreeByReference::replaceWithInPlace(TreeByReference t) { assert(isDefined()); TreeByReference p = parent(); if (p.isDefined()) { - p.replaceTreeChild(*this, t); + p.replaceChildInPlace(*this, t); } } -void TreeByReference::replaceTreeChild(TreeByReference oldChild, TreeByReference newChild) { +void TreeByReference::replaceChildInPlace(TreeByReference oldChild, TreeByReference newChild) { if (oldChild == newChild) { return; } assert(isDefined()); if (newChild.isAllocationFailure()) { - replaceWithAllocationFailure(numberOfChildren()); + replaceWithAllocationFailureInPlace(numberOfChildren()); return; } @@ -62,7 +62,7 @@ void TreeByReference::replaceTreeChild(TreeByReference oldChild, TreeByReference oldChild.node()->release(oldChild.numberOfChildren()); } -void TreeByReference::replaceWithAllocationFailure(int currentNumberOfChildren) { +void TreeByReference::replaceWithAllocationFailureInPlace(int currentNumberOfChildren) { if (isAllocationFailure()) { return; } @@ -74,7 +74,7 @@ void TreeByReference::replaceWithAllocationFailure(int currentNumberOfChildren) TreeNode * staticAllocFailNode = node()->failedAllocationStaticNode(); // Release all children and delete the node in the pool - removeChildrenAndDestroy(currentNumberOfChildren); + removeChildrenAndDestroyInPlace(currentNumberOfChildren); /* WARNING: If we called "p.decrementNumberOfChildren()" here, the number of * children of the parent layout would be: * -> numberOfChildren() for "dynamic trees" that have a m_numberOfChildren @@ -97,7 +97,7 @@ void TreeByReference::replaceWithAllocationFailure(int currentNumberOfChildren) * no longer retaining the node. When we add this node to the parent, it * will retain it and increment the retain count. */ newAllocationFailureNode->setReferenceCounter(currentRetainCount - 1); - p.addChildTreeAtIndex(TreeByReference(newAllocationFailureNode), indexInParentNode, p.numberOfChildren() - 1); + p.addChildAtIndexInPlace(TreeByReference(newAllocationFailureNode), indexInParentNode, p.numberOfChildren() - 1); p.decrementNumberOfChildren(); /* We decrement here the parent's number of children, as we did not do it * before, see WARNING. */ @@ -106,12 +106,12 @@ void TreeByReference::replaceWithAllocationFailure(int currentNumberOfChildren) } } -void TreeByReference::replaceChildWithGhost(TreeByReference t) { +void TreeByReference::replaceChildWithGhostInPlace(TreeByReference t) { GhostReference ghost; - return replaceTreeChild(t, ghost); + return replaceChildInPlace(t, ghost); } -void TreeByReference::mergeTreeChildrenAtIndex(TreeByReference t, int i) { +void TreeByReference::mergeChildrenAtIndexInPlace(TreeByReference t, int i) { assert(i >= 0 && i <= numberOfChildren()); // Steal operands int numberOfNewChildren = t.numberOfChildren(); @@ -123,12 +123,12 @@ void TreeByReference::mergeTreeChildrenAtIndex(TreeByReference t, int i) { t.node()->eraseNumberOfChildren(); // If t is a child, remove it if (node()->hasChild(t.node())) { - removeChildTree(t, 0); + removeChildInPlace(t, 0); } node()->incrementNumberOfChildren(numberOfNewChildren); } -void TreeByReference::swapChildren(int i, int j) { +void TreeByReference::swapChildrenInPlace(int i, int j) { assert(isDefined()); assert(i >= 0 && i < numberOfChildren()); assert(j >= 0 && j < numberOfChildren()); @@ -146,13 +146,13 @@ void TreeByReference::swapChildren(int i, int j) { /* Protected */ // Add -void TreeByReference::addChildTreeAtIndex(TreeByReference t, int index, int currentNumberOfChildren) { +void TreeByReference::addChildAtIndexInPlace(TreeByReference t, int index, int currentNumberOfChildren) { assert(isDefined()); if (node()->isAllocationFailure()) { return; } if (t.isAllocationFailure()) { - replaceWithAllocationFailure(currentNumberOfChildren); + replaceWithAllocationFailureInPlace(currentNumberOfChildren); return; } assert(index >= 0 && index <= currentNumberOfChildren); @@ -170,21 +170,21 @@ void TreeByReference::addChildTreeAtIndex(TreeByReference t, int index, int curr // Remove -void TreeByReference::removeChildTreeAtIndex(int i) { +void TreeByReference::removeChildAtIndexInPlace(int i) { assert(isDefined()); assert(i >= 0 && i < numberOfChildren()); TreeByReference t = treeChildAtIndex(i); - removeChildTree(t, t.numberOfChildren()); + removeChildInPlace(t, t.numberOfChildren()); } -void TreeByReference::removeChildTree(TreeByReference t, int childNumberOfChildren) { +void TreeByReference::removeChildInPlace(TreeByReference t, int childNumberOfChildren) { assert(isDefined()); TreePool::sharedPool()->move(TreePool::sharedPool()->last(), t.node(), childNumberOfChildren); t.node()->release(childNumberOfChildren); node()->decrementNumberOfChildren(); } -void TreeByReference::removeChildren(int currentNumberOfChildren) { +void TreeByReference::removeChildrenInPlace(int currentNumberOfChildren) { assert(isDefined()); for (int i = 0; i < currentNumberOfChildren; i++) { TreeByReference childRef = treeChildAtIndex(0); @@ -194,8 +194,8 @@ void TreeByReference::removeChildren(int currentNumberOfChildren) { node()->eraseNumberOfChildren(); } -void TreeByReference::removeChildrenAndDestroy(int currentNumberOfChildren) { - removeChildren(currentNumberOfChildren); +void TreeByReference::removeChildrenAndDestroyInPlace(int currentNumberOfChildren) { + removeChildrenInPlace(currentNumberOfChildren); TreePool::sharedPool()->discardTreeNode(node()); } @@ -225,7 +225,7 @@ void TreeByReference::buildGhostChildren() { // Add a ghost child GhostReference ghost; if (ghost.isAllocationFailure()) { - replaceWithAllocationFailure(numberOfChildren()); + replaceWithAllocationFailureInPlace(numberOfChildren()); return; } TreePool::sharedPool()->move(node()->next(), ghost.node(), 0); diff --git a/poincare/src/tree_node.cpp b/poincare/src/tree_node.cpp index 82a0bf549..f71987353 100644 --- a/poincare/src/tree_node.cpp +++ b/poincare/src/tree_node.cpp @@ -18,7 +18,7 @@ void TreeNode::release(int currentNumberOfChildren) { } m_referenceCounter--; if (m_referenceCounter == 0) { - TreeByReference(this).removeChildrenAndDestroy(currentNumberOfChildren); + TreeByReference(this).removeChildrenAndDestroyInPlace(currentNumberOfChildren); } } diff --git a/poincare/test/parentheses_layout.cpp b/poincare/test/parentheses_layout.cpp index 7cbeb508e..e8a3849ff 100644 --- a/poincare/test/parentheses_layout.cpp +++ b/poincare/test/parentheses_layout.cpp @@ -15,18 +15,18 @@ QUIZ_CASE(poincare_parenthesis_layout_size) { HorizontalLayout * layout = new HorizontalLayout(); LeftParenthesisLayout leftPar = new LeftParenthesisLayout(); RightParenthesisLayout rightPar = new RightParenthesisLayout(); - layout->addChildTreeAtIndex(leftPar, 0); - layout->addChildTreeAtIndex(new CharLayout('2'), 1); - layout->addChildTreeAtIndex(new CharLayout('+'), 2); - layout->addChildTreeAtIndex(new LeftParenthesisLayout(), 3); - layout->addChildTreeAtIndex(new FractionLayout( + layout->addChildAtIndexInPlace(leftPar, 0); + layout->addChildAtIndexInPlace(new CharLayout('2'), 1); + layout->addChildAtIndexInPlace(new CharLayout('+'), 2); + layout->addChildAtIndexInPlace(new LeftParenthesisLayout(), 3); + layout->addChildAtIndexInPlace(new FractionLayout( new CharLayout('3'), new CharLayout('4')), 4); - layout->addChildTreeAtIndex(new RightParenthesisLayout(), 3); - layout->addChildTreeAtIndex(new CharLayout('6'), 5); - layout->addChildTreeAtIndex(rightPar, 7); - layout->addChildTreeAtIndex(new CharLayout('1'), 8); + layout->addChildAtIndexInPlace(new RightParenthesisLayout(), 3); + layout->addChildAtIndexInPlace(new CharLayout('6'), 5); + layout->addChildAtIndexInPlace(rightPar, 7); + layout->addChildAtIndexInPlace(new CharLayout('1'), 8); assert(leftPar->size().height() == rightPar->size().height()); delete layout; }