diff --git a/poincare/include/poincare/addition.h b/poincare/include/poincare/addition.h index a8c3a490c..4caa285ec 100644 --- a/poincare/include/poincare/addition.h +++ b/poincare/include/poincare/addition.h @@ -39,7 +39,7 @@ public: } private: // Layout - bool childNeedsParenthesis(const SerializationHelperInterface * child) const override; + bool childNeedsParenthesis(const TreeNode * child) const override; Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Infix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, name()); diff --git a/poincare/include/poincare/division.h b/poincare/include/poincare/division.h index bf3044a25..3ce1819f3 100644 --- a/poincare/include/poincare/division.h +++ b/poincare/include/poincare/division.h @@ -42,7 +42,7 @@ public: } // Layout - bool childNeedsParenthesis(const SerializationHelperInterface * child) const override; + bool childNeedsParenthesis(const TreeNode * child) const override; Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Infix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "/"); diff --git a/poincare/include/poincare/expression_node.h b/poincare/include/poincare/expression_node.h index 3b558a8b5..c8c90a223 100644 --- a/poincare/include/poincare/expression_node.h +++ b/poincare/include/poincare/expression_node.h @@ -4,7 +4,6 @@ #include #include #include -#include #include #include @@ -13,7 +12,7 @@ namespace Poincare { /* Methods preceded by '*!*' interfere with the expression pool, which can make * 'this' outdated. They should only be called in a wrapper on Expression. */ -class ExpressionNode : public TreeNode, public SerializationHelperInterface { +class ExpressionNode : public TreeNode { friend class AdditionNode; friend class DivisionNode; friend class NAryExpressionNode; @@ -159,10 +158,6 @@ protected: /* Hierarchy */ ExpressionNode * parent() const override { return static_cast(TreeNode::parent()); } Direct children() const { return Direct(this); } - - /* SerializationHelperInterface */ - SerializationHelperInterface * serializableChildAtIndex(int i) const override { return childAtIndex(i); } - int numberOfSerializableChildren() const override { return numberOfChildren(); } }; } diff --git a/poincare/include/poincare/factorial.h b/poincare/include/poincare/factorial.h index 6affcfd0e..0c58aaeea 100644 --- a/poincare/include/poincare/factorial.h +++ b/poincare/include/poincare/factorial.h @@ -23,7 +23,7 @@ public: Type type() const override { return Type::Factorial; } private: // Layout - bool childNeedsParenthesis(const SerializationHelperInterface * child) const override; + bool childNeedsParenthesis(const TreeNode * child) const override; Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplication diff --git a/poincare/include/poincare/fraction_layout.h b/poincare/include/poincare/fraction_layout.h index a0712bf67..5d856b0ce 100644 --- a/poincare/include/poincare/fraction_layout.h +++ b/poincare/include/poincare/fraction_layout.h @@ -43,7 +43,7 @@ public: protected: // SerializationInterface - bool childNeedsParenthesis(const SerializationHelperInterface * child) const override { return true; } + bool childNeedsParenthesis(const TreeNode * child) const override { return true; } // LayoutNode KDSize computeSize() override; KDCoordinate computeBaseline() override; diff --git a/poincare/include/poincare/layout_node.h b/poincare/include/poincare/layout_node.h index 5abdb2057..c474c1c59 100644 --- a/poincare/include/poincare/layout_node.h +++ b/poincare/include/poincare/layout_node.h @@ -2,7 +2,6 @@ #define POINCARE_LAYOUT_NODE_H #include -#include #include #include @@ -11,7 +10,7 @@ namespace Poincare { class LayoutCursor; class Layout; -class LayoutNode : public TreeNode, public SerializationHelperInterface { +class LayoutNode : public TreeNode { friend class Layout; public: enum class VerticalDirection { @@ -39,10 +38,6 @@ public: //TODO: invalid cache when tempering with hierarchy virtual void invalidAllSizesPositionsAndBaselines(); - // SerializationHelperInterface - SerializationHelperInterface * serializableChildAtIndex(int i) const override { return childAtIndex(i); } - int numberOfSerializableChildren() const override { return numberOfChildren(); } - // Tree LayoutNode * parent() const override { return static_cast(TreeNode::parent()); } LayoutNode * childAtIndex(int i) const override { return static_cast(TreeNode::childAtIndex(i)); } diff --git a/poincare/include/poincare/multiplication.h b/poincare/include/poincare/multiplication.h index 5c3df8a48..70641d674 100644 --- a/poincare/include/poincare/multiplication.h +++ b/poincare/include/poincare/multiplication.h @@ -37,7 +37,7 @@ private: Expression setSign(Sign s, Context & context, Preferences::AngleUnit angleUnit) override; // Layout - bool childNeedsParenthesis(const SerializationHelperInterface * child) const override; + bool childNeedsParenthesis(const TreeNode * child) const override; Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Serialize diff --git a/poincare/include/poincare/opposite.h b/poincare/include/poincare/opposite.h index 505856ebc..45c2e4b33 100644 --- a/poincare/include/poincare/opposite.h +++ b/poincare/include/poincare/opposite.h @@ -36,7 +36,7 @@ public: } // Layout - bool childNeedsParenthesis(const SerializationHelperInterface * child) const override; + bool childNeedsParenthesis(const TreeNode * child) const override; Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode = Preferences::PrintFloatMode::Decimal, int numberOfSignificantDigits = 0) const override; diff --git a/poincare/include/poincare/power.h b/poincare/include/poincare/power.h index c139fde92..1ec939210 100644 --- a/poincare/include/poincare/power.h +++ b/poincare/include/poincare/power.h @@ -39,7 +39,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Serialize - bool childNeedsParenthesis(const SerializationHelperInterface * child) const override; + bool childNeedsParenthesis(const TreeNode * child) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return SerializationHelper::Infix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, name()); } diff --git a/poincare/include/poincare/serialization_helper.h b/poincare/include/poincare/serialization_helper.h index b31cc450a..2135d0aea 100644 --- a/poincare/include/poincare/serialization_helper.h +++ b/poincare/include/poincare/serialization_helper.h @@ -1,14 +1,14 @@ #ifndef POINCARE_SERIALIZATION_HELPER_H #define POINCARE_SERIALIZATION_HELPER_H -#include +#include namespace Poincare { namespace SerializationHelper { /* SerializableReference to Text */ int Infix( - const SerializationHelperInterface * interface, + const TreeNode * node, char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, @@ -18,7 +18,7 @@ namespace SerializationHelper { int lastChildIndex = -1); int Prefix( - const SerializationHelperInterface * interface, + const TreeNode * node, char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, diff --git a/poincare/include/poincare/serialization_helper_interface.h b/poincare/include/poincare/serialization_helper_interface.h deleted file mode 100644 index 5ed9fad73..000000000 --- a/poincare/include/poincare/serialization_helper_interface.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef POINCARE_SERIALIZATION_HELPER_INTERFACE_H -#define POINCARE_SERIALIZATION_HELPER_INTERFACE_H - -#include - -namespace Poincare { - -class SerializationHelperInterface { -public: - virtual int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode = Preferences::PrintFloatMode::Decimal, int numberOfSignificantDigits = 0) const = 0; - virtual bool childNeedsParenthesis(const SerializationHelperInterface * child) const { return false; }; - - virtual SerializationHelperInterface * serializableChildAtIndex(int i) const = 0; - virtual int numberOfSerializableChildren() const = 0; -}; - -} - -#endif diff --git a/poincare/include/poincare/subtraction.h b/poincare/include/poincare/subtraction.h index a46734214..44fdfa52b 100644 --- a/poincare/include/poincare/subtraction.h +++ b/poincare/include/poincare/subtraction.h @@ -35,7 +35,7 @@ public: } /* Layout */ - bool childNeedsParenthesis(const SerializationHelperInterface * child) const override; + bool childNeedsParenthesis(const TreeNode * child) const override; Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; diff --git a/poincare/include/poincare/tree_node.h b/poincare/include/poincare/tree_node.h index c4d4a51ee..f915a998e 100644 --- a/poincare/include/poincare/tree_node.h +++ b/poincare/include/poincare/tree_node.h @@ -8,6 +8,7 @@ #if POINCARE_TREE_LOG #include #endif +#include /* What's in a TreeNode, really? * - a vtable pointer @@ -62,6 +63,10 @@ public: // AddChild collateral effect virtual void didAddChildAtIndex(int newNumberOfChildren) {} + // Serialization + virtual int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode = Preferences::PrintFloatMode::Decimal, int numberOfSignificantDigits = 0) const { assert(false); return 0; } + virtual bool childNeedsParenthesis(const TreeNode * child) const { return false; }; + template class Iterator { public: diff --git a/poincare/src/addition.cpp b/poincare/src/addition.cpp index bcfd12efa..a09374e41 100644 --- a/poincare/src/addition.cpp +++ b/poincare/src/addition.cpp @@ -28,7 +28,7 @@ int AdditionNode::getPolynomialCoefficients(char symbolName, Expression coeffici // Private // Layout -bool AdditionNode::childNeedsParenthesis(const SerializationHelperInterface * child) const { +bool AdditionNode::childNeedsParenthesis(const TreeNode * child) const { if ((static_cast(child)->isNumber() && static_cast(child)->sign() == Sign::Negative) || static_cast(child)->type() == Type::Opposite) { return true; } diff --git a/poincare/src/division.cpp b/poincare/src/division.cpp index c904e2f1d..ac6cd7365 100644 --- a/poincare/src/division.cpp +++ b/poincare/src/division.cpp @@ -18,7 +18,7 @@ int DivisionNode::polynomialDegree(char symbolName) const { return childAtIndex(0)->polynomialDegree(symbolName); } -bool DivisionNode::childNeedsParenthesis(const SerializationHelperInterface * child) const { +bool DivisionNode::childNeedsParenthesis(const TreeNode * child) const { if (static_cast(child)->isNumber() && static_cast(child)->sign() == Sign::Negative) { return true; } diff --git a/poincare/src/factorial.cpp b/poincare/src/factorial.cpp index 61a4d3620..f08c192f6 100644 --- a/poincare/src/factorial.cpp +++ b/poincare/src/factorial.cpp @@ -13,7 +13,7 @@ namespace Poincare { // Layout -bool FactorialNode::childNeedsParenthesis(const SerializationHelperInterface * child) const { +bool FactorialNode::childNeedsParenthesis(const TreeNode * child) const { if (static_cast(child)->isNumber() && static_cast(child)->sign() == Sign::Negative) { return true; } diff --git a/poincare/src/multiplication.cpp b/poincare/src/multiplication.cpp index 91ae1b13d..9dcfba203 100644 --- a/poincare/src/multiplication.cpp +++ b/poincare/src/multiplication.cpp @@ -67,7 +67,7 @@ Expression MultiplicationNode::setSign(Sign s, Context & context, Preferences::A return Multiplication(this).setSign(s, context, angleUnit); } -bool MultiplicationNode::childNeedsParenthesis(const SerializationHelperInterface * child) const { +bool MultiplicationNode::childNeedsParenthesis(const TreeNode * child) const { if (static_cast(child)->isNumber() && static_cast(child)->sign() == Sign::Negative) { return true; } diff --git a/poincare/src/opposite.cpp b/poincare/src/opposite.cpp index cefe5abe2..39cc12cfa 100644 --- a/poincare/src/opposite.cpp +++ b/poincare/src/opposite.cpp @@ -29,7 +29,7 @@ ExpressionNode::Sign OppositeNode::sign() const { /* Layout */ -bool OppositeNode::childNeedsParenthesis(const SerializationHelperInterface * child) const { +bool OppositeNode::childNeedsParenthesis(const TreeNode * child) const { if (static_cast(child)->isNumber() && static_cast(child)->sign() == Sign::Negative) { return true; } diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index f783a6520..8e6052257 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -111,7 +111,7 @@ Layout PowerNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int // Serialize -bool PowerNode::childNeedsParenthesis(const SerializationHelperInterface * child) const { +bool PowerNode::childNeedsParenthesis(const TreeNode * child) const { if (static_cast(child)->isNumber() && static_cast(child)->sign() == Sign::Negative) { return true; } diff --git a/poincare/src/serialization_helper.cpp b/poincare/src/serialization_helper.cpp index 954c294a9..3375d3b6f 100644 --- a/poincare/src/serialization_helper.cpp +++ b/poincare/src/serialization_helper.cpp @@ -4,9 +4,9 @@ namespace Poincare { -static void serializeChild(const SerializationHelperInterface * childInterface, const SerializationHelperInterface * interface, char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfDigits, int * numberOfChar) { +static void serializeChild(const TreeNode * childNode, const TreeNode * parentNode, char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfDigits, int * numberOfChar) { // Write the child with parentheses if needed - bool addParentheses = interface->childNeedsParenthesis(childInterface); + bool addParentheses = parentNode->childNeedsParenthesis(childNode); if (addParentheses) { buffer[*numberOfChar] = '('; *numberOfChar = *numberOfChar + 1; @@ -14,7 +14,7 @@ static void serializeChild(const SerializationHelperInterface * childInterface, return; } } - *numberOfChar += childInterface->serialize(buffer + *numberOfChar, bufferSize - *numberOfChar, floatDisplayMode, numberOfDigits); + *numberOfChar += childNode->serialize(buffer + *numberOfChar, bufferSize - *numberOfChar, floatDisplayMode, numberOfDigits); if (*numberOfChar >= bufferSize-1) { return; } @@ -25,7 +25,7 @@ static void serializeChild(const SerializationHelperInterface * childInterface, } int SerializationHelper::Infix( - const SerializationHelperInterface * interface, + const TreeNode * node, char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, @@ -44,13 +44,13 @@ int SerializationHelper::Infix( return 0; } - // Get some information on the interface + // Get some information on the node int numberOfChar = 0; - int numberOfChildren = interface->numberOfSerializableChildren(); + int numberOfChildren = node->numberOfChildren(); assert(numberOfChildren > 0); // Write the first child, with parentheses if needed - serializeChild(interface->serializableChildAtIndex(firstChildIndex), interface, buffer, bufferSize, floatDisplayMode, numberOfDigits, &numberOfChar); + serializeChild(node->childAtIndex(firstChildIndex), node, buffer, bufferSize, floatDisplayMode, numberOfDigits, &numberOfChar); if (numberOfChar >= bufferSize-1) { return bufferSize-1; } @@ -63,7 +63,7 @@ int SerializationHelper::Infix( return bufferSize-1; } // Write the child, with parentheses if needed - serializeChild(interface->serializableChildAtIndex(i), interface, buffer, bufferSize, floatDisplayMode, numberOfDigits, &numberOfChar); + serializeChild(node->childAtIndex(i), node, buffer, bufferSize, floatDisplayMode, numberOfDigits, &numberOfChar); if (numberOfChar >= bufferSize-1) { return bufferSize-1; } @@ -75,7 +75,7 @@ int SerializationHelper::Infix( } int SerializationHelper::Prefix( - const SerializationHelperInterface * interface, + const TreeNode * node, char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, @@ -104,7 +104,7 @@ int SerializationHelper::Prefix( return bufferSize-1; } - int childrenCount = interface->numberOfSerializableChildren(); + int childrenCount = node->numberOfChildren(); if (childrenCount > 0) { if (!writeFirstChild) { assert(childrenCount > 1); @@ -112,7 +112,7 @@ int SerializationHelper::Prefix( int firstChildIndex = writeFirstChild ? 0 : 1; // Write the first child - numberOfChar += interface->serializableChildAtIndex(firstChildIndex)->serialize(buffer+numberOfChar, bufferSize-numberOfChar, floatDisplayMode, numberOfDigits); + numberOfChar += node->childAtIndex(firstChildIndex)->serialize(buffer+numberOfChar, bufferSize-numberOfChar, floatDisplayMode, numberOfDigits); if (numberOfChar >= bufferSize-1) { return bufferSize-1; } @@ -123,7 +123,7 @@ int SerializationHelper::Prefix( if (numberOfChar >= bufferSize-1) { return bufferSize-1; } - numberOfChar += interface->serializableChildAtIndex(i)->serialize(buffer+numberOfChar, bufferSize-numberOfChar, floatDisplayMode, numberOfDigits); + numberOfChar += node->childAtIndex(i)->serialize(buffer+numberOfChar, bufferSize-numberOfChar, floatDisplayMode, numberOfDigits); if (numberOfChar >= bufferSize-1) { return bufferSize-1; } diff --git a/poincare/src/subtraction.cpp b/poincare/src/subtraction.cpp index 4d1d3535a..5a12cac31 100644 --- a/poincare/src/subtraction.cpp +++ b/poincare/src/subtraction.cpp @@ -22,7 +22,7 @@ int SubtractionNode::polynomialDegree(char symbolName) const { // Private -bool SubtractionNode::childNeedsParenthesis(const SerializationHelperInterface * child) const { +bool SubtractionNode::childNeedsParenthesis(const TreeNode * child) const { if (static_cast(child)->isNumber() && static_cast(child)->sign() == Sign::Negative) { return true; }