/*
 * LinearStringTerminatingSymbolBWT.h
 *
 *  Created on: 15. 2. 2021
 *      Author: Martin Prokopic
 */

#pragma once

#include <string/LinearStringTerminatingSymbolBWT.h>
#include <core/xmlApi.hpp>

#include <string/xml/common/StringFromXmlParserCommon.h>
#include <string/xml/common/StringToXmlComposerCommon.h>

namespace core {

template < typename SymbolType >
struct xmlApi < string::LinearStringTerminatingSymbolBWT < SymbolType > > {
	static string::LinearStringTerminatingSymbolBWT < SymbolType > parse ( ext::deque < sax::Token >::iterator & input );
	static bool first ( const ext::deque < sax::Token >::const_iterator & input );
	static std::string xmlTagName ( );
	static void compose ( ext::deque < sax::Token > & output, const string::LinearStringTerminatingSymbolBWT < SymbolType > & input );
};

template < typename SymbolType >
string::LinearStringTerminatingSymbolBWT < SymbolType > xmlApi < string::LinearStringTerminatingSymbolBWT < SymbolType > >::parse ( ext::deque < sax::Token >::iterator & input ) {
	sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) );
	ext::set<SymbolType> alphabet = string::StringFromXmlParserCommon::parseAlphabet < SymbolType > ( input );
    SymbolType terminatingSymbol = string::StringFromXmlParserCommon::parseTerminatingSymbol< SymbolType > ( input );
	ext::vector<SymbolType> content = string::StringFromXmlParserCommon::parseContent < SymbolType > ( input );
	sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) );
	return string::LinearStringTerminatingSymbolBWT < SymbolType > ( std::move ( alphabet ), std::move ( terminatingSymbol ), std::move ( content ) );
}

template < typename SymbolType >
bool xmlApi < string::LinearStringTerminatingSymbolBWT < SymbolType > >::first ( const ext::deque < sax::Token >::const_iterator & input ) {
	return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) );
}

template < typename SymbolType >
std::string xmlApi < string::LinearStringTerminatingSymbolBWT < SymbolType > >::xmlTagName ( ) {
	return "LinearStringTerminatingSymbolBWT";
}

template < typename SymbolType >
void xmlApi < string::LinearStringTerminatingSymbolBWT < SymbolType > >::compose ( ext::deque < sax::Token > & output, const string::LinearStringTerminatingSymbolBWT < SymbolType > & input ) {
	output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT );
	string::StringToXmlComposerCommon::composeAlphabet ( output, input.getAlphabet ( ) );
    string::StringToXmlComposerCommon::composeTerminatingSymbol( output, input.getTerminatingSymbol( ) );
	string::StringToXmlComposerCommon::composeContent ( output, input.getContent ( ) );
	output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT );
}

} /* namespace core */

