-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathTreeReader.cpp
57 lines (46 loc) · 1.3 KB
/
TreeReader.cpp
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
55
56
57
//-----------------------------------------------------------------------------
/** @file libboardgame_base/TreeReader.cpp
@author Markus Enzenberger
@copyright GNU General Public License version 3 or later */
//-----------------------------------------------------------------------------
#include "TreeReader.h"
namespace libboardgame_base {
//-----------------------------------------------------------------------------
unique_ptr<SgfNode> TreeReader::move_tree()
{
return std::move(m_root);
}
void TreeReader::on_begin_tree(bool is_root)
{
if (! is_root)
m_stack.push(m_current);
}
void TreeReader::on_end_tree(bool is_root)
{
if (! is_root)
{
LIBBOARDGAME_ASSERT(! m_stack.empty());
m_current = m_stack.top();
m_stack.pop();
}
}
void TreeReader::on_begin_node(bool is_root)
{
if (is_root)
{
m_root = make_unique<SgfNode>();
m_current = m_root.get();
}
else
m_current = &m_current->create_new_child();
}
void TreeReader::on_end_node()
{
}
void TreeReader::on_property(const string& identifier,
const vector<string>& values)
{
m_current->set_property(identifier, values);
}
//-----------------------------------------------------------------------------
} // namespace libboardgame_base