File: TreeWriter.cpp

package info (click to toggle)
pentobi 29.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,892 kB
  • sloc: cpp: 25,719; javascript: 875; xml: 40; makefile: 13; sh: 6
file content (52 lines) | stat: -rw-r--r-- 1,359 bytes parent folder | download | duplicates (4)
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
//-----------------------------------------------------------------------------
/** @file libboardgame_base/TreeWriter.cpp
    @author Markus Enzenberger
    @copyright GNU General Public License version 3 or later */
//-----------------------------------------------------------------------------

#include "TreeWriter.h"

namespace libboardgame_base {

//-----------------------------------------------------------------------------

TreeWriter::TreeWriter(ostream& out, const SgfNode& root)
    : m_root(root),
      m_writer(out)
{
}

void TreeWriter::write()
{
    m_writer.begin_tree();
    write_node(m_root);
    m_writer.end_tree();
}

void TreeWriter::write_node(const SgfNode& node)
{
    m_writer.begin_node();
    for (auto& i : node.get_properties())
        write_property(i.id, i.values);
    m_writer.end_node();
    if (! node.has_children())
        return;
    if (node.has_single_child())
        write_node(node.get_child());
    else
        for (auto& i : node.get_children())
        {
            m_writer.begin_tree();
            write_node(i);
            m_writer.end_tree();
        }
}

void TreeWriter::write_property(const string& id, const vector<string>& values)
{
    m_writer.write_property(id, values);
}

//-----------------------------------------------------------------------------

} // namespace libboardgame_base