Add class cursor on for all TreeReferences

This commit is contained in:
Léa Saviot
2018-06-26 14:30:04 +02:00
parent 7587b05c8b
commit c60bc61d32
3 changed files with 25 additions and 4 deletions

16
cursor.h Normal file
View File

@@ -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 <typename T>
friend class TreeReference;
private:
Cursor(TreeNode * node) : m_treeReference(node) {}
TreeReference<TreeNode> m_treeReference;
};
#endif

View File

@@ -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 <stdio.h>
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;
}

View File

@@ -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 <typename T>
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();