Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
ObjectsTrie.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <alib/trie>
9#include <core/xmlApi.hpp>
10
11namespace core {
12
13template < typename T, typename R >
14struct xmlApi < ext::trie < T, R > > {
16 static bool first ( const ext::deque < sax::Token >::const_iterator & input );
17 static std::string xmlTagName ( );
18 static void compose ( ext::deque < sax::Token > & output, const ext::trie < T, R > & input );
19
20private:
22 static void composeChildren ( ext::deque < sax::Token > & out, const ext::map < T, ext::trie < T, R > > & children );
23};
24
25template < typename T, typename R >
28
31
32 T key = core::xmlApi < T >::parse ( input );
33 R value = core::xmlApi < R >::parse ( input );
34 ext::map < T, ext::trie < T, R > > innerChildren = parseChildren ( input );
35
36 children.insert ( std::make_pair ( std::move ( key ), ext::trie < T, R > ( std::move ( value ), std::move ( innerChildren ) ) ) );
37
39 }
40
41 return children;
42}
43
44template < typename T, typename R >
47 R value = core::xmlApi < R >::parse ( input );
48 ext::map < T, ext::trie < T, R > > children = parseChildren ( input );
49
50 ext::trie < T, R > trie ( std::move ( value ), std::move ( children ) );
51
53 return trie;
54}
55
56template < typename T, typename R >
59}
60
61template < typename T, typename R >
62std::string xmlApi < ext::trie < T, R > >::xmlTagName ( ) {
63 return "Trie";
64}
65
66template < typename T, typename R >
67void xmlApi < ext::trie < T, R > >::composeChildren ( ext::deque < sax::Token > & out, const ext::map < T, ext::trie < T, R > > & children ) {
68 for ( const std::pair < const T, ext::trie < T, R > > & child : children ) {
69 out.emplace_back ( "Child", sax::Token::TokenType::START_ELEMENT );
70
71 core::xmlApi < T >::compose ( out, child.first );
72 core::xmlApi < R >::compose ( out, child.second.getData ( ) );
73 composeChildren ( out, child.second.getChildren ( ) );
74
75 out.emplace_back ( "Child", sax::Token::TokenType::END_ELEMENT );
76 }
77}
78
79template < typename T, typename R >
81 output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT );
82 core::xmlApi < R >::compose ( output, input.getData ( ) );
83 composeChildren ( output, input.getChildren ( ) );
84 output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT );
85}
86
87} /* namespace core */
88
Class extending the deque class from the standard library. Original reason is to allow printing of th...
Definition: deque.hpp:44
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
std::pair< iterator, bool > insert(const T &key, const R &value)
Insert variant with explicit key and value parameters.
Definition: map.hpp:118
Class introducing a trie with interface trying to be close to the interface of standard library conta...
Definition: trie.hpp:47
ext::map< Key, trie > & getChildren()
Getter of children of the root node.
Definition: trie.hpp:115
Value & getData()
Getter of the value in the root node.
Definition: trie.hpp:95
static void popToken(ext::deque< Token >::iterator &input, Token::TokenType type, const std::string &data)
Definition: FromXMLParserHelper.cpp:39
static bool isToken(ext::deque< Token >::const_iterator input, Token::TokenType type, const std::string &data)
Definition: FromXMLParserHelper.cpp:29
Definition: normalize.hpp:10
Definition: sigHandler.cpp:20
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
Definition: xmlApi.hpp:27