Skip to content
Snippets Groups Projects
Commit 0081e596 authored by Jan Trávníček's avatar Jan Trávníček Committed by Jan Trávníček
Browse files

data: add gap symbol

parent c393ac3f
No related branches found
No related tags found
1 merge request!183Z automata
#include "GapSymbol.h"
#include <object/Object.h>
#include <registration/ValuePrinterRegistration.hpp>
namespace alphabet {
GapSymbol::GapSymbol() = default;
std::ostream & operator << ( std::ostream & out, const GapSymbol & ) {
return out << "(GapSymbol)";
}
GapSymbol::operator std::string ( ) const {
return GapSymbol::instance < std::string > ( );
}
} /* namespace alphabet */
namespace {
auto valuePrinter = registration::ValuePrinterRegister < alphabet::GapSymbol > ( );
} /* namespace */
/*
* This file is part of Algorithms library toolkit.
* Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
* Algorithms library toolkit is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Algorithms library toolkit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <alib/compare>
#include <common/ranked_symbol.hpp>
#include <object/Object.h>
namespace alphabet {
/**
* \brief
* Represents a wildcard used as representation of anything here in a string or a tree.
*/
class GapSymbol {
public:
/**
* \brief
* Creates a new instance of the symbol.
*/
explicit GapSymbol ( );
/**
* The three way comparison implementation
*
* \param other the other instance
*
* \returns the ordering between this object and the @p other.
*/
std::strong_ordering operator <=> ( const GapSymbol & ) const {
return std::strong_ordering::equal;
}
/**
* The equality comparison implementation.
*
* \param other the other object to compare with.
*
* \returns true if this and other objects are equal, false othervise
*/
bool operator == ( const GapSymbol & ) const {
return true;
}
/**
* Print this object as raw representation to ostream.
*
* \param os ostream where to print
* \param instance object to print
*
* \returns modified output stream
*/
friend std::ostream & operator << ( std::ostream & out, const GapSymbol & instance );
/**
* Casts this instance to as compact as possible string representation.
*
* \returns string representation of the object
*/
explicit operator std::string ( ) const;
/**
* \brief Factory for the symbol construction of the symbol based on given type.
*/
template < typename Base >
static inline typename std::enable_if < std::is_integral < Base >::value, Base >::type instance ( );
/**
* \brief Factory for the symbol construction of the symbol based on given type.
*/
template < typename Base >
static inline typename std::enable_if < ! std::is_integral < Base >::value, Base >::type instance ( );
};
template < typename Base >
inline typename std::enable_if < std::is_integral < Base >::value, Base >::type GapSymbol::instance ( ) {
return '*';
}
template < >
inline object::Object GapSymbol::instance < object::Object > ( ) {
return object::Object ( GapSymbol ( ) );
}
template < >
inline std::string GapSymbol::instance < std::string > ( ) {
return std::string ( 1, GapSymbol::instance < char > ( ) );
}
template < >
inline GapSymbol GapSymbol::instance < GapSymbol > ( ) {
return GapSymbol ( );
}
// TODO make partially specialised when needed by classes or variables, functions can't be partially specialsed
template < >
inline common::ranked_symbol < > GapSymbol::instance < common::ranked_symbol < > > ( ) {
return common::ranked_symbol < > ( GapSymbol::instance < DefaultSymbolType > ( ), 0u );
}
} /* namespace alphabet */
#include "GapSymbol.h"
#include <object/Object.h>
#include <registration/XmlRegistration.hpp>
namespace core {
alphabet::GapSymbol xmlApi < alphabet::GapSymbol >::parse ( ext::deque < sax::Token >::iterator & input ) {
sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) );
sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) );
return alphabet::GapSymbol ( );
}
bool xmlApi < alphabet::GapSymbol >::first ( const ext::deque < sax::Token >::const_iterator & input ) {
return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) );
}
std::string xmlApi < alphabet::GapSymbol >::xmlTagName ( ) {
return "GapSymbol";
}
void xmlApi < alphabet::GapSymbol >::compose ( ext::deque < sax::Token > & output, const alphabet::GapSymbol & ) {
output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT );
output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT );
}
} /* namespace core */
namespace {
auto xmlWrite = registration::XmlWriterRegister < alphabet::GapSymbol > ( );
auto xmlRead = registration::XmlReaderRegister < alphabet::GapSymbol > ( );
auto xmlGroup = registration::XmlRegisterTypeInGroup < object::Object, alphabet::GapSymbol > ( );
} /* namespace */
#pragma once
#include <alphabet/GapSymbol.h>
#include <core/xmlApi.hpp>
namespace core {
template < >
struct xmlApi < alphabet::GapSymbol > {
static alphabet::GapSymbol 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 alphabet::GapSymbol & data );
};
} /* namespace core */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment