From c60bc61d32a550fb54fbd8cfa23e595fc6d48b0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Tue, 26 Jun 2018 14:30:04 +0200 Subject: [PATCH] Add class cursor on for all TreeReferences --- cursor.h | 16 ++++++++++++++++ test.cpp | 8 ++++---- tree_reference.h | 5 +++++ 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 cursor.h diff --git a/cursor.h b/cursor.h new file mode 100644 index 000000000..a66aeafa0 --- /dev/null +++ b/cursor.h @@ -0,0 +1,16 @@ +#ifndef CURSOR_H +#define CURSOR_H + +#include "char_layout_node.h" +#include "tree_node.h" +#include "tree_reference.h" + +class Cursor { + template + friend class TreeReference; +private: + Cursor(TreeNode * node) : m_treeReference(node) {} + TreeReference m_treeReference; +}; + +#endif diff --git a/test.cpp b/test.cpp index 6586020bd..96a79bb7a 100644 --- a/test.cpp +++ b/test.cpp @@ -1,7 +1,7 @@ #include "float_node.h" #include "char_layout_node.h" #include "addition_node.h" -#include "layout_cursor.h" +#include "cursor.h" #include Addition buildAddition() { @@ -24,13 +24,13 @@ int main() { printf("\nCHAR LAYOUT\n"); CharLayout aChar('a'); TreePool::sharedPool()->log(); - LayoutCursor cursor(aChar.pointer()); - TreePool::sharedPool()->log(); + Cursor cursor = aChar.cursor(); +/* TreePool::sharedPool()->log(); cursor.log(); bool recompute = false; cursor.moveLeft(&recompute); cursor.log(); cursor.moveRight(&recompute); - cursor.log(); + cursor.log();*/ return 0; } diff --git a/tree_reference.h b/tree_reference.h index 59efeab89..7ef1bb5b0 100644 --- a/tree_reference.h +++ b/tree_reference.h @@ -7,8 +7,11 @@ static inline int min(int i, int j) { return i < j ? i : j; } static inline int max(int i, int j) { return i > j ? i : j; } +class Cursor; + template class TreeReference { + friend class Cursor; public: TreeReference(const TreeReference & tr) { int trNodeIdentifier = tr.identifier(); @@ -38,6 +41,8 @@ public: int identifier() const { return m_identifier; } + Cursor cursor(); + // Hierarchy int numberOfChildren() const { return node()->numberOfChildren();