Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
UnrankedTree.h
Go to the documentation of this file.
1
6#pragma once
7
12#include <core/rawApi.hpp>
13
14namespace core {
15
16template < class SymbolType >
17struct rawApi < tree::UnrankedTree < SymbolType > > {
18private:
20 static void composeContent ( ext::deque < sax::Token > & out, const ext::tree < SymbolType > & node );
21
22public:
23 static tree::UnrankedTree < SymbolType > parse ( ext::istream & input );
24 static void compose ( ext::ostream & output, const tree::UnrankedTree < SymbolType > & tree );
25};
26
27template < class SymbolType >
32 return tree::UnrankedTree < SymbolType > ( parseContent ( iter ) );
33}
34
35template < class SymbolType >
38 composeContent ( tokens, tree.getContent ( ) );
40}
41
42template < class SymbolType >
47 node.push_back ( parseContent ( input ) );
48 }
50 return node;
53 } else {
54 throw exception::CommonException ( "Invalid token stream" );
55 }
56}
57
58template < class SymbolType >
59void rawApi < tree::UnrankedTree < SymbolType > >::composeContent ( ext::deque < sax::Token > & out, const ext::tree < SymbolType > & node ) {
60 if ( node.getChildren ( ).empty ( ) ) {
61 out.emplace_back ( sax::Token ( ext::to_string ( node.getData ( ) ), sax::Token::TokenType::CHARACTER ) );
62 } else {
63 out.emplace_back ( sax::Token ( ext::to_string ( node.getData ( ) ), sax::Token::TokenType::START_ELEMENT ) );
64
65 for ( const ext::tree < SymbolType > & child : node.getChildren ( ) ) {
66 composeContent ( out, child );
67 }
68
69 out.emplace_back ( sax::Token ( ext::to_string ( node.getData ( ) ), sax::Token::TokenType::END_ELEMENT ) );
70 }
71}
72
73} /* namespace core */
74
Basic exception from which all other exceptions are derived.
Definition: CommonException.h:21
Class extending the deque class from the standard library. Original reason is to allow printing of th...
Definition: deque.hpp:44
auto begin() &
Inherited behavior of begin for non-const instance.
Definition: deque.hpp:100
Definition: istream.h:32
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
static std::string popTokenData(ext::deque< Token >::iterator &input, Token::TokenType type)
Definition: FromXMLParserHelper.cpp:48
static bool isTokenType(ext::deque< Token >::const_iterator input, Token::TokenType type)
Definition: FromXMLParserHelper.cpp:34
static void composeStream(ext::ostream &out, const ext::deque< Token > &in)
Definition: SaxComposeInterface.cpp:49
static void parseStream(ext::istream &in, ext::deque< Token > &out)
Definition: SaxParseInterface.cpp:73
Definition: Token.h:17
Tree represented in its natural representation. The representation is so called unranked,...
Definition: UnrankedTree.h:69
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
Definition: normalize.hpp:10
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: rawApi.hpp:11