Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
TreeToStringComposerCommon.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <ostream>
9#include <alib/vector>
10
11#include <core/stringApi.hpp>
12
13namespace tree {
14
16public:
17 template < class SymbolType >
19 template < class SymbolType >
21 template < class SymbolType >
22 static void compose ( ext::ostream &, const ext::tree < SymbolType > & node );
23 template < class SymbolType >
24 static void compose ( ext::ostream &, const SymbolType & subtreeWildcard, const SymbolType & subtreeGap, const ext::tree < SymbolType > & node );
25};
26
27template < class SymbolType >
29 core::stringApi < SymbolType >::compose ( out, node.getData ( ).getSymbol ( ) );
30
31 out << " " << ext::to_string ( node.getData ( ).getRank ( ) );
32
33 for ( const ext::tree < common::ranked_symbol < SymbolType > > & child : node ) {
34 out << " ";
35 compose ( out, child );
36 }
37}
38
39template < class SymbolType >
41 if ( node.getData ( ) == subtreeWildcard ) {
42 out << "#S";
43 } else {
44 core::stringApi < SymbolType >::compose ( out, node.getData ( ).getSymbol ( ) );
45
46 out << " " << ext::to_string ( node.getData ( ).getRank ( ) );
47
48 for ( const ext::tree < common::ranked_symbol < SymbolType > > & child : node ) {
49 out << " ";
50 compose ( out, subtreeWildcard, child );
51 }
52 }
53}
54
55template < class SymbolType >
58
59 for ( const ext::tree < SymbolType > & child : node ) {
60 out << " ";
61 compose ( out, child );
62 }
63
64 out << " |";
65}
66
67template < class SymbolType >
68void TreeToStringComposerCommon::compose ( ext::ostream & out, const SymbolType & subtreeWildcard, const SymbolType & subtreeGap, const ext::tree < SymbolType > & node ) {
69 if ( node.getData ( ) == subtreeWildcard ) {
70 out << "#S |";
71 } else if ( node.getData ( ) == subtreeWildcard ) {
72 out << "#G |";
73 } else {
75
76 for ( const ext::tree < SymbolType > & child : node ) {
77 out << " ";
78 compose ( out, subtreeWildcard, subtreeGap, child );
79 }
80
81 out << " |";
82 }
83}
84
85} /* namespace tree */
86
Definition: ranked_symbol.hpp:20
Definition: ostream.h:14
Class introducing a tree with interface trying to be close to the interface of standard library conta...
Definition: tree.hpp:52
Definition: TreeToStringComposerCommon.h:15
static void compose(ext::ostream &, const ext::tree< common::ranked_symbol< SymbolType > > &node)
Definition: TreeToStringComposerCommon.h:28
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
std::string to_string(const T &value)
To string method designated for objects that can be casted to string.
Definition: string.hpp:131
Definition: Node.cpp:11
Definition: BackwardOccurrenceTest.h:17
Definition: stringApi.hpp:26