[poincare] Change name: TreeByReference --> TreeHandle

This commit is contained in:
Émilie Feral
2018-09-14 17:22:36 +02:00
parent d34ee9ceee
commit e0495de6af
19 changed files with 123 additions and 123 deletions

View File

@@ -119,7 +119,7 @@ objs += $(addprefix poincare/src/,\
sum.o\
symbol.o\
tangent.o\
tree_by_reference.o\
tree_handle.o\
tree_node.o\
tree_pool.o\
trigonometry.o\
@@ -128,7 +128,7 @@ objs += $(addprefix poincare/src/,\
)
tests += $(addprefix poincare/test/,\
tree/tree_by_reference.cpp\
tree/tree_handle.cpp\
addition.cpp\
arithmetic.cpp\
binomial_coefficient_layout.cpp\

View File

@@ -6,7 +6,7 @@ extern "C" {
#include <stdint.h>
}
#include <poincare/preferences.h>
#include <poincare/tree_by_reference.h>
#include <poincare/tree_handle.h>
#include <poincare/tree_node.h>
namespace Poincare {
@@ -34,9 +34,9 @@ public:
};
template<typename T>
class Evaluation : public TreeByReference {
class Evaluation : public TreeHandle {
public:
Evaluation() : TreeByReference() {}
Evaluation() : TreeHandle() {}
#if 0
template<class U> U convert() const {
/* This function allows to convert Evaluation to derived Evaluation.
@@ -51,8 +51,8 @@ public:
}
#endif
EvaluationNode<T> * node() const {
assert(!TreeByReference::node()->isGhost());
return static_cast<EvaluationNode<T> *>(TreeByReference::node());
assert(!TreeHandle::node()->isGhost());
return static_cast<EvaluationNode<T> *>(TreeHandle::node());
}
/* Hierarchy */
@@ -64,7 +64,7 @@ public:
std::complex<T> trace() const { return node()->trace(); }
std::complex<T> determinant() const { return node()->determinant(); }
protected:
Evaluation(EvaluationNode<T> * n) : TreeByReference(n) {}
Evaluation(EvaluationNode<T> * n) : TreeHandle(n) {}
};
}

View File

@@ -1,7 +1,7 @@
#ifndef POINCARE_EXPRESSION_REFERENCE_H
#define POINCARE_EXPRESSION_REFERENCE_H
#include <poincare/tree_by_reference.h>
#include <poincare/tree_handle.h>
#include <poincare/preferences.h>
#include <poincare/print_float.h>
#include <poincare/expression_node.h>
@@ -13,7 +13,7 @@ namespace Poincare {
class Context;
class Expression : public TreeByReference {
class Expression : public TreeHandle {
// TODO clean friends
friend class AbsoluteValue;
friend class Addition;
@@ -87,7 +87,7 @@ template<typename T>
public:
static bool isExpression() { return true; }
/* Constructor & Destructor */
Expression() : TreeByReference() {}
Expression() : TreeHandle() {}
Expression clone() const;
static Expression parse(char const * string);
@@ -179,7 +179,7 @@ public:
Coordinate2D nextIntersection(char symbol, double start, double step, double max, Context & context, Preferences::AngleUnit angleUnit, const Expression expression) const;
protected:
Expression(const ExpressionNode * n) : TreeByReference(n) {}
Expression(const ExpressionNode * n) : TreeHandle(n) {}
template<class T> T convert() const {
/* This function allows to convert Expression to derived Expressions.
@@ -200,17 +200,17 @@ protected:
/* Reference */
ExpressionNode * node() const {
assert(TreeByReference::node() == nullptr || !TreeByReference::node()->isGhost());
return static_cast<ExpressionNode *>(TreeByReference::node());
assert(TreeHandle::node() == nullptr || !TreeHandle::node()->isGhost());
return static_cast<ExpressionNode *>(TreeHandle::node());
}
/* Hierarchy */
Expression(int nodeIdentifier) : TreeByReference(nodeIdentifier) {}
Expression(int nodeIdentifier) : TreeHandle(nodeIdentifier) {}
Expression parent() const; // TODO try to inline
void defaultSetChildrenInPlace(Expression other);
void addChildAtIndexInPlace(TreeByReference t, int index, int currentNumberOfChildren) = delete;
void addChildAtIndexInPlace(TreeHandle t, int index, int currentNumberOfChildren) = delete;
void removeChildAtIndexInPlace(int i) = delete;
void removeChildInPlace(TreeByReference t, int childNumberOfChildren) = delete;
void removeChildInPlace(TreeHandle t, int childNumberOfChildren) = delete;
void removeChildrenInPlace(int currentNumberOfChildren) = delete;
/* Properties */

View File

@@ -2,7 +2,7 @@
#define POINCARE_GHOST_REFERENCE_H
#include <poincare/ghost_node.h>
#include <poincare/tree_by_reference.h>
#include <poincare/tree_handle.h>
#include <poincare/tree_pool.h>
namespace Poincare {
@@ -10,9 +10,9 @@ namespace Poincare {
/* GhostReference is not in ghost_node.h because GhostNode is needed in
* tree_pool.h and this created header inclusion problems. */
class GhostReference : public TreeByReference {
class GhostReference : public TreeHandle {
public:
GhostReference() : TreeByReference(TreePool::sharedPool()->createTreeNode<GhostNode>()) {}
GhostReference() : TreeHandle(TreePool::sharedPool()->createTreeNode<GhostNode>()) {}
};
}

View File

@@ -2,25 +2,25 @@
#define POINCARE_LAYOUT_REFERENCE_H
#include <poincare/layout.h>
#include <poincare/tree_by_reference.h>
#include <poincare/tree_handle.h>
namespace Poincare {
class LayoutCursor;
class LayoutReference : public TreeByReference {
class LayoutReference : public TreeHandle {
friend class GridLayoutNode;
friend class HorizontalLayoutNode;
friend class LayoutNode;
friend class LayoutCursor;
friend class VerticalOffsetLayoutNode;
public:
LayoutReference() : TreeByReference() {}
LayoutReference(const LayoutNode * node) : TreeByReference(node) {}
LayoutReference() : TreeHandle() {}
LayoutReference(const LayoutNode * node) : TreeHandle(node) {}
LayoutReference clone() const;
LayoutNode * node() const {
assert(isUninitialized() || !TreeByReference::node()->isGhost());
return static_cast<LayoutNode *>(TreeByReference::node());
assert(isUninitialized() || !TreeHandle::node()->isGhost());
return static_cast<LayoutNode *>(TreeHandle::node());
}
// Rendering

View File

@@ -74,8 +74,8 @@ public:
void setDimensions(int rows, int columns);
int numberOfRows() const { return node()->numberOfRows(); }
int numberOfColumns() const { return node()->numberOfColumns(); }
using TreeByReference::addChildAtIndexInPlace;
void addChildrenAsRowInPlace(TreeByReference t, int i);
using TreeHandle::addChildAtIndexInPlace;
void addChildrenAsRowInPlace(TreeHandle t, int i);
Expression matrixChild(int i, int j) { return childAtIndex(i*numberOfColumns()+j); }
/* Operation on matrix */

View File

@@ -37,10 +37,10 @@ private:
class NAryExpression : public Expression {
public:
NAryExpression(const NAryExpressionNode * n) : Expression(n) {}
using TreeByReference::addChildAtIndexInPlace;
using TreeByReference::removeChildrenInPlace;
using TreeByReference::removeChildAtIndexInPlace;
using TreeByReference::removeChildInPlace;
using TreeHandle::addChildAtIndexInPlace;
using TreeHandle::removeChildrenInPlace;
using TreeHandle::removeChildAtIndexInPlace;
using TreeHandle::removeChildInPlace;
typedef int (*ExpressionOrder)(const ExpressionNode * e1, const ExpressionNode * e2, bool canBeInterrupted);
void sortChildrenInPlace(ExpressionOrder order, bool canBeInterrupted) {
node()->sortChildrenInPlace(order, canBeInterrupted);

View File

@@ -6,35 +6,35 @@
namespace Poincare {
/* TreeByReference constructors that take only one argument and this argument is
* a TreeByReference should be marked explicit. This prevents the code from
/* TreeHandle constructors that take only one argument and this argument is
* a TreeHandle should be marked explicit. This prevents the code from
* compiling with, for instance: Logarithm l = clone() (which would be
* equivalent to Logarithm l = Logarithm(clone())). */
class TreeByReference {
class TreeHandle {
friend class TreeNode;
friend class TreePool;
public:
/* Constructors */
TreeByReference(const TreeByReference & tr) : m_identifier(TreeNode::NoNodeIdentifier) {
TreeHandle(const TreeHandle & tr) : m_identifier(TreeNode::NoNodeIdentifier) {
setIdentifierAndRetain(tr.identifier());
}
TreeByReference(TreeByReference && tr) : m_identifier(tr.m_identifier) {
TreeHandle(TreeHandle && tr) : m_identifier(tr.m_identifier) {
tr.m_identifier = TreeNode::NoNodeIdentifier;
}
~TreeByReference() {
~TreeHandle() {
release(m_identifier);
}
/* Operators */
TreeByReference & operator=(const TreeByReference & tr) {
TreeHandle & operator=(const TreeHandle & tr) {
setTo(tr);
return *this;
}
TreeByReference & operator=(TreeByReference && tr) {
TreeHandle & operator=(TreeHandle && tr) {
release(m_identifier);
m_identifier = tr.m_identifier;
tr.m_identifier = TreeNode::NoNodeIdentifier;
@@ -42,11 +42,11 @@ public:
}
/* Comparison */
inline bool operator==(const TreeByReference& t) { return m_identifier == t.identifier(); }
inline bool operator!=(const TreeByReference& t) { return m_identifier != t.identifier(); }
inline bool operator==(const TreeHandle& t) { return m_identifier == t.identifier(); }
inline bool operator!=(const TreeHandle& t) { return m_identifier != t.identifier(); }
/* Clone */
TreeByReference clone() const;
TreeHandle clone() const;
int identifier() const { return m_identifier; }
TreeNode * node() const;
@@ -58,13 +58,13 @@ public:
bool isUninitialized() const { return m_identifier == TreeNode::NoNodeIdentifier; }
/* Hierarchy */
bool hasChild(TreeByReference t) const;
bool hasSibling(TreeByReference t) const { return node()->hasSibling(t.node()); }
bool hasAncestor(TreeByReference t, bool includeSelf) const { return node()->hasAncestor(t.node(), includeSelf); }
bool hasChild(TreeHandle t) const;
bool hasSibling(TreeHandle t) const { return node()->hasSibling(t.node()); }
bool hasAncestor(TreeHandle t, bool includeSelf) const { return node()->hasAncestor(t.node(), includeSelf); }
int numberOfChildren() const { return node()->numberOfChildren(); }
int indexOfChild(TreeByReference t) const;
TreeByReference parent() const;
TreeByReference childAtIndex(int i) const;
int indexOfChild(TreeHandle t) const;
TreeHandle parent() const;
TreeHandle childAtIndex(int i) const;
void setParentIdentifier(int id) { node()->setParentIdentifier(id); }
void deleteParentIdentifier() { node()->deleteParentIdentifier(); }
void deleteParentIdentifierInChildren() { node()->deleteParentIdentifierInChildren(); }
@@ -74,16 +74,16 @@ public:
/* Hierarchy operations */
// Replace
void replaceWithInPlace(TreeByReference t);
void replaceChildInPlace(TreeByReference oldChild, TreeByReference newChild);
void replaceChildAtIndexInPlace(int oldChildIndex, TreeByReference newChild);
void replaceWithInPlace(TreeHandle t);
void replaceChildInPlace(TreeHandle oldChild, TreeHandle newChild);
void replaceChildAtIndexInPlace(int oldChildIndex, TreeHandle newChild);
void replaceChildAtIndexWithGhostInPlace(int index) {
assert(index >= 0 && index < numberOfChildren());
replaceChildWithGhostInPlace(childAtIndex(index));
}
void replaceChildWithGhostInPlace(TreeByReference t);
void replaceChildWithGhostInPlace(TreeHandle t);
// Merge
void mergeChildrenAtIndexInPlace(TreeByReference t, int i);
void mergeChildrenAtIndexInPlace(TreeHandle t, int i);
// Swap
void swapChildrenInPlace(int i, int j);
@@ -94,17 +94,17 @@ public:
protected:
/* Constructor */
TreeByReference(const TreeNode * node);
TreeByReference(int nodeIndentifier = TreeNode::NoNodeIdentifier) : m_identifier(nodeIndentifier) {}
TreeHandle(const TreeNode * node);
TreeHandle(int nodeIndentifier = TreeNode::NoNodeIdentifier) : m_identifier(nodeIndentifier) {}
void setIdentifierAndRetain(int newId);
void setTo(const TreeByReference & tr);
void setTo(const TreeHandle & tr);
/* Hierarchy operations */
// Add
void addChildAtIndexInPlace(TreeByReference t, int index, int currentNumberOfChildren);
void addChildAtIndexInPlace(TreeHandle t, int index, int currentNumberOfChildren);
// Remove puts a child at the end of the pool
void removeChildAtIndexInPlace(int i);
void removeChildInPlace(TreeByReference t, int childNumberOfChildren);
void removeChildInPlace(TreeHandle t, int childNumberOfChildren);
void removeChildrenInPlace(int currentNumberOfChildren);
int m_identifier;

View File

@@ -13,11 +13,11 @@
namespace Poincare {
class TreeByReference;
class TreeHandle;
class TreePool {
friend class TreeNode;
friend class TreeByReference;
friend class TreeHandle;
friend class ExceptionCheckpoint;
public:
static TreePool * sharedPool() { assert(SharedStaticPool != nullptr); return SharedStaticPool; }

View File

@@ -5,7 +5,7 @@ namespace Poincare {
template<typename T>
Evaluation<T> Evaluation<T>::childAtIndex(int i) const {
TreeByReference c = TreeByReference::childAtIndex(i);
TreeHandle c = TreeHandle::childAtIndex(i);
return static_cast<Evaluation<T> &>(c);
}

View File

@@ -21,7 +21,7 @@ namespace Poincare {
/* Constructor & Destructor */
Expression Expression::clone() const { TreeByReference c = TreeByReference::clone(); return static_cast<Expression&>(c); }
Expression Expression::clone() const { TreeHandle c = TreeHandle::clone(); return static_cast<Expression&>(c); }
Expression Expression::parse(char const * string) {
if (string[0] == 0) {
@@ -65,7 +65,7 @@ bool Expression::shouldStopProcessing() {
/* Hierarchy */
Expression Expression::childAtIndex(int i) const {
TreeByReference c = TreeByReference::childAtIndex(i);
TreeHandle c = TreeHandle::childAtIndex(i);
return static_cast<Expression &>(c);
}
@@ -165,7 +165,7 @@ Expression Expression::defaultShallowReduce(Context & context, Preferences::Angl
}
Expression Expression::parent() const {
TreeByReference p = TreeByReference::parent();
TreeHandle p = TreeHandle::parent();
return static_cast<Expression &>(p);
}

View File

@@ -11,7 +11,7 @@ LayoutReference LayoutReference::clone() const {
if (isUninitialized()) {
return LayoutReference();
}
TreeByReference c = TreeByReference::clone();
TreeHandle c = TreeHandle::clone();
LayoutReference cast = LayoutReference(static_cast<LayoutNode *>(c.node()));
cast.invalidAllSizesPositionsAndBaselines();
return cast;
@@ -29,7 +29,7 @@ LayoutCursor LayoutReference::equivalentCursor(LayoutCursor * cursor) {
}
LayoutReference LayoutReference::childAtIndex(int i) {
TreeByReference c = TreeByReference::childAtIndex(i);
TreeHandle c = TreeHandle::childAtIndex(i);
return static_cast<LayoutReference &>(c);
}

View File

@@ -95,7 +95,7 @@ void Matrix::setDimensions(int rows, int columns) {
setNumberOfColumns(columns);
}
void Matrix::addChildrenAsRowInPlace(TreeByReference t, int i) {
void Matrix::addChildrenAsRowInPlace(TreeHandle t, int i) {
int previousNumberOfColumns = numberOfColumns();
if (previousNumberOfColumns > 0) {
assert(t.numberOfChildren() == numberOfColumns());

View File

@@ -1,4 +1,4 @@
#include <poincare/tree_by_reference.h>
#include <poincare/tree_handle.h>
#include <poincare/ghost_reference.h>
#if POINCARE_TREE_LOG
#include <iostream>
@@ -8,38 +8,38 @@ namespace Poincare {
/* Clone */
TreeByReference TreeByReference::clone() const {
TreeHandle TreeHandle::clone() const {
/* TODO Remove ?
if (isUninitialized()) {
return TreeByReference();
return TreeHandle();
}*/
TreeNode * nodeCopy = TreePool::sharedPool()->deepCopy(node());
nodeCopy->deleteParentIdentifier();
return TreeByReference(nodeCopy);
return TreeHandle(nodeCopy);
}
/* Hierarchy operations */
TreeNode * TreeByReference::node() const { assert(m_identifier != TreeNode::NoNodeIdentifier); return TreePool::sharedPool()->node(m_identifier); }
TreeNode * TreeHandle::node() const { assert(m_identifier != TreeNode::NoNodeIdentifier); return TreePool::sharedPool()->node(m_identifier); }
size_t TreeByReference::size() const { return node()->deepSize(node()->numberOfChildren()); }
size_t TreeHandle::size() const { return node()->deepSize(node()->numberOfChildren()); }
TreeByReference TreeByReference::parent() const { return (isUninitialized() || node()->parent() == nullptr) ? TreeByReference() : TreeByReference(node()->parent()); }
TreeHandle TreeHandle::parent() const { return (isUninitialized() || node()->parent() == nullptr) ? TreeHandle() : TreeHandle(node()->parent()); }
int TreeByReference::indexOfChild(TreeByReference t) const { return node()->indexOfChild(t.node()); }
int TreeHandle::indexOfChild(TreeHandle t) const { return node()->indexOfChild(t.node()); }
bool TreeByReference::hasChild(TreeByReference t) const { return node()->hasChild(t.node()); }
bool TreeHandle::hasChild(TreeHandle t) const { return node()->hasChild(t.node()); }
TreeByReference TreeByReference::childAtIndex(int i) const { return TreeByReference(node()->childAtIndex(i)); }
TreeHandle TreeHandle::childAtIndex(int i) const { return TreeHandle(node()->childAtIndex(i)); }
void TreeByReference::replaceWithInPlace(TreeByReference t) {
void TreeHandle::replaceWithInPlace(TreeHandle t) {
assert(!isUninitialized());
TreeByReference p = parent();
TreeHandle p = parent();
if (!p.isUninitialized()) {
p.replaceChildInPlace(*this, t);
}
}
void TreeByReference::replaceChildInPlace(TreeByReference oldChild, TreeByReference newChild) {
void TreeHandle::replaceChildInPlace(TreeHandle oldChild, TreeHandle newChild) {
assert(!oldChild.isUninitialized());
assert(!newChild.isUninitialized());
assert(hasChild(oldChild));
@@ -65,18 +65,18 @@ void TreeByReference::replaceChildInPlace(TreeByReference oldChild, TreeByRefere
oldChild.deleteParentIdentifier();
}
void TreeByReference::replaceChildAtIndexInPlace(int oldChildIndex, TreeByReference newChild) {
void TreeHandle::replaceChildAtIndexInPlace(int oldChildIndex, TreeHandle newChild) {
assert(oldChildIndex >= 0 && oldChildIndex < numberOfChildren());
TreeByReference oldChild = childAtIndex(oldChildIndex);
TreeHandle oldChild = childAtIndex(oldChildIndex);
replaceChildInPlace(oldChild, newChild);
}
void TreeByReference::replaceChildWithGhostInPlace(TreeByReference t) {
void TreeHandle::replaceChildWithGhostInPlace(TreeHandle t) {
GhostReference ghost;
return replaceChildInPlace(t, ghost);
}
void TreeByReference::mergeChildrenAtIndexInPlace(TreeByReference t, int i) {
void TreeHandle::mergeChildrenAtIndexInPlace(TreeHandle t, int i) {
/* mergeChildrenAtIndexInPlace should only be called with a tree that can
* have any number of children, so there is no need to replace the stolen
* children with ghosts. */
@@ -101,7 +101,7 @@ void TreeByReference::mergeChildrenAtIndexInPlace(TreeByReference t, int i) {
}
}
void TreeByReference::swapChildrenInPlace(int i, int j) {
void TreeHandle::swapChildrenInPlace(int i, int j) {
assert(i >= 0 && i < numberOfChildren());
assert(j >= 0 && j < numberOfChildren());
if (i == j) {
@@ -109,14 +109,14 @@ void TreeByReference::swapChildrenInPlace(int i, int j) {
}
int firstChildIndex = i < j ? i : j;
int secondChildIndex = i > j ? i : j;
TreeByReference firstChild = childAtIndex(firstChildIndex);
TreeByReference secondChild = childAtIndex(secondChildIndex);
TreeHandle firstChild = childAtIndex(firstChildIndex);
TreeHandle secondChild = childAtIndex(secondChildIndex);
TreePool::sharedPool()->move(firstChild.node()->nextSibling(), secondChild.node(), secondChild.numberOfChildren());
TreePool::sharedPool()->move(childAtIndex(secondChildIndex).node()->nextSibling(), firstChild.node(), firstChild.numberOfChildren());
}
#if POINCARE_TREE_LOG
void TreeByReference::log() const {
void TreeHandle::log() const {
node()->log(std::cout);
std::cout << std::endl;
}
@@ -125,7 +125,7 @@ void TreeByReference::log() const {
/* Protected */
// Add
void TreeByReference::addChildAtIndexInPlace(TreeByReference t, int index, int currentNumberOfChildren) {
void TreeHandle::addChildAtIndexInPlace(TreeHandle t, int index, int currentNumberOfChildren) {
assert(!isUninitialized());
assert(!t.isUninitialized());
assert(index >= 0 && index <= currentNumberOfChildren);
@@ -149,14 +149,14 @@ void TreeByReference::addChildAtIndexInPlace(TreeByReference t, int index, int c
// Remove
void TreeByReference::removeChildAtIndexInPlace(int i) {
void TreeHandle::removeChildAtIndexInPlace(int i) {
assert(!isUninitialized());
assert(i >= 0 && i < numberOfChildren());
TreeByReference t = childAtIndex(i);
TreeHandle t = childAtIndex(i);
removeChildInPlace(t, t.numberOfChildren());
}
void TreeByReference::removeChildInPlace(TreeByReference t, int childNumberOfChildren) {
void TreeHandle::removeChildInPlace(TreeHandle t, int childNumberOfChildren) {
assert(!isUninitialized());
TreePool::sharedPool()->move(TreePool::sharedPool()->last(), t.node(), childNumberOfChildren);
t.node()->release(childNumberOfChildren);
@@ -164,7 +164,7 @@ void TreeByReference::removeChildInPlace(TreeByReference t, int childNumberOfChi
node()->decrementNumberOfChildren();
}
void TreeByReference::removeChildrenInPlace(int currentNumberOfChildren) {
void TreeHandle::removeChildrenInPlace(int currentNumberOfChildren) {
assert(!isUninitialized());
deleteParentIdentifierInChildren();
TreePool::sharedPool()->removeChildren(node(), currentNumberOfChildren);
@@ -172,8 +172,8 @@ void TreeByReference::removeChildrenInPlace(int currentNumberOfChildren) {
/* Private */
void TreeByReference::detachFromParent() {
TreeByReference myParent = parent();
void TreeHandle::detachFromParent() {
TreeHandle myParent = parent();
if (!myParent.isUninitialized()) {
int idxInParent = myParent.indexOfChild(*this);
myParent.replaceChildAtIndexWithGhostInPlace(idxInParent);
@@ -182,22 +182,22 @@ void TreeByReference::detachFromParent() {
}
TreeByReference::TreeByReference(const TreeNode * node) : TreeByReference() {
TreeHandle::TreeHandle(const TreeNode * node) : TreeHandle() {
if (node != nullptr) {
setIdentifierAndRetain(node->identifier());
}
}
void TreeByReference::setIdentifierAndRetain(int newId) {
void TreeHandle::setIdentifierAndRetain(int newId) {
m_identifier = newId;
if (!isUninitialized()) {
node()->retain();
}
}
void TreeByReference::setTo(const TreeByReference & tr) {
void TreeHandle::setTo(const TreeHandle & tr) {
/* We cannot use (*this)==tr because tr would need to be casted to
* TreeByReference, which calls setTo and triggers an infinite loop */
* TreeHandle, which calls setTo and triggers an infinite loop */
if (identifier() == tr.identifier()) {
return;
}
@@ -206,7 +206,7 @@ void TreeByReference::setTo(const TreeByReference & tr) {
release(currentId);
}
void TreeByReference::release(int identifier) {
void TreeHandle::release(int identifier) {
if (identifier == TreeNode::NoNodeIdentifier) {
return;
}

View File

@@ -1,6 +1,6 @@
#include <poincare/tree_node.h>
#include <poincare/tree_pool.h>
#include <poincare/tree_by_reference.h>
#include <poincare/tree_handle.h>
#include <stdio.h>
namespace Poincare {

View File

@@ -1,5 +1,5 @@
#include <poincare/tree_pool.h>
#include <poincare/tree_by_reference.h>
#include <poincare/tree_handle.h>
#include <poincare/exception_checkpoint.h>
#include <poincare/test/tree/blob_node.h>
#include <poincare/test/tree/pair_node.h>

View File

@@ -2,7 +2,7 @@
#define POINCARE_TEST_BLOB_NODE_H
#include <poincare/tree_node.h>
#include <poincare/tree_by_reference.h>
#include <poincare/tree_handle.h>
namespace Poincare {
@@ -21,14 +21,14 @@ private:
int m_data;
};
class BlobByReference : public TreeByReference {
class BlobByReference : public TreeHandle {
public:
BlobByReference(int data = 0) : TreeByReference(TreePool::sharedPool()->createTreeNode<BlobNode>()) {
BlobByReference(int data = 0) : TreeHandle(TreePool::sharedPool()->createTreeNode<BlobNode>()) {
node()->setData(data);
}
int data() { return node()->data(); }
private:
BlobNode * node() const { return static_cast<BlobNode *>(TreeByReference::node()); }
BlobNode * node() const { return static_cast<BlobNode *>(TreeHandle::node()); }
};
}

View File

@@ -2,7 +2,7 @@
#define POINCARE_TEST_PAIR_NODE_H
#include <poincare/tree_node.h>
#include <poincare/tree_by_reference.h>
#include <poincare/tree_handle.h>
namespace Poincare {
@@ -17,9 +17,9 @@ public:
#endif
};
class PairByReference : public TreeByReference {
class PairByReference : public TreeHandle {
public:
PairByReference(TreeByReference t1, TreeByReference t2) : TreeByReference(TreePool::sharedPool()->createTreeNode<PairNode>()) {
PairByReference(TreeHandle t1, TreeHandle t2) : TreeHandle(TreePool::sharedPool()->createTreeNode<PairNode>()) {
replaceChildAtIndexInPlace(0, t1);
replaceChildAtIndexInPlace(1, t2);
}

View File

@@ -7,7 +7,7 @@
using namespace Poincare;
QUIZ_CASE(tree_by_reference_are_discared_after_block) {
QUIZ_CASE(tree_handle_are_discared_after_block) {
int initialPoolSize = pool_size();
{
BlobByReference b(0);
@@ -19,53 +19,53 @@ QUIZ_CASE(tree_by_reference_are_discared_after_block) {
static void make_temp_blob() {
BlobByReference b(5);
}
QUIZ_CASE(tree_by_reference_are_discared_after_function_call) {
QUIZ_CASE(tree_handle_are_discared_after_function_call) {
int initialPoolSize = pool_size();
make_temp_blob();
assert_pool_size(initialPoolSize);
}
QUIZ_CASE(tree_by_reference_can_be_copied) {
QUIZ_CASE(tree_handle_can_be_copied) {
int initialPoolSize = pool_size();
{
BlobByReference b(123);
assert_pool_size(initialPoolSize+1);
TreeByReference t = b;
TreeHandle t = b;
assert_pool_size(initialPoolSize+1);
}
assert_pool_size(initialPoolSize);
}
QUIZ_CASE(tree_by_reference_can_be_moved) {
QUIZ_CASE(tree_handle_can_be_moved) {
int initialPoolSize = pool_size();
{
TreeByReference t = BlobByReference(123);
TreeHandle t = BlobByReference(123);
assert_pool_size(initialPoolSize+1);
}
{
TreeByReference t = BlobByReference(123);
TreeHandle t = BlobByReference(123);
t = BlobByReference(456);
assert_pool_size(initialPoolSize+1);
}
assert_pool_size(initialPoolSize);
}
static TreeByReference blob_with_data_3() {
static TreeHandle blob_with_data_3() {
return BlobByReference(3);
}
QUIZ_CASE(tree_by_reference_can_be_returned) {
QUIZ_CASE(tree_handle_can_be_returned) {
int initialPoolSize = pool_size();
TreeByReference b = blob_with_data_3();
TreeHandle b = blob_with_data_3();
assert_pool_size(initialPoolSize+1);
}
QUIZ_CASE(tree_by_reference_memory_failure) {
QUIZ_CASE(tree_handle_memory_failure) {
int initialPoolSize = pool_size();
int memoryFailureHasBeenHandled = false;
Poincare::ExceptionCheckpoint ecp;
if (ExceptionRun(ecp)) {
TreeByReference tree = BlobByReference(1);
TreeHandle tree = BlobByReference(1);
while (true) {
tree = PairByReference(tree, BlobByReference(1));
}
@@ -76,7 +76,7 @@ QUIZ_CASE(tree_by_reference_memory_failure) {
assert_pool_size(initialPoolSize);
}
QUIZ_CASE(tree_by_reference_does_not_copy) {
QUIZ_CASE(tree_handle_does_not_copy) {
int initialPoolSize = pool_size();
BlobByReference b1(1);
BlobByReference b2(2);