-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree_cursor.cpp
More file actions
54 lines (44 loc) · 1.06 KB
/
Copy pathtree_cursor.cpp
File metadata and controls
54 lines (44 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "ts/tree_cursor.hpp"
namespace ts {
TreeCursor::TreeCursor(Node node, std::shared_ptr<Tree> tree)
: m_tree(tree), m_node(new Node(node)) {}
TreeCursor::TreeCursor(TreeCursor&& other)
: m_tree(other.m_tree), m_node(nullptr), cursor(ts_tree_cursor_copy(&other.cursor)) {
}
TreeCursor::~TreeCursor() {
if (m_node != nullptr) {
delete m_node;
}
ts_tree_cursor_delete(&cursor);
}
Node TreeCursor::node() {
if (!m_node) {
m_node = new Node(ts_tree_cursor_current_node(&cursor), m_tree);
}
return *m_node;
}
const char* TreeCursor::getCurrectFieldName() const {
return ts_tree_cursor_current_field_name(&cursor);
}
bool TreeCursor::gotoParent() {
bool result = ts_tree_cursor_goto_parent(&cursor);
if (result) {
m_node = nullptr;
}
return result;
}
bool TreeCursor::gotoFirstChild() {
bool result = ts_tree_cursor_goto_first_child(&cursor);
if (result) {
m_node = nullptr;
}
return result;
}
bool TreeCursor::gotoNextSibling() {
bool result = ts_tree_cursor_goto_next_sibling(&cursor);
if (result) {
m_node = nullptr;
}
return result;
}
}