/*
 * MinimalEndSymbol.h
 *
 *  Created on: 13. 02. 2021
 *      Author: Martin Prokopic
 */

#pragma once

#include <object/Object.h>
#include <common/ranked_symbol.hpp>

namespace alphabet {

/**
 * \brief
 * Represents end symbol, which is minimal in order and is used as a terminating symbol of a string.
 */
class MinimalEndSymbol {
public:
	/**
	 * \brief
	 * Creates a new instance of the symbol.
	 */
	explicit MinimalEndSymbol ( );

	/**
	 * 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 MinimalEndSymbol & ) 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 MinimalEndSymbol & ) 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 MinimalEndSymbol & 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 integral 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 non-integral 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 MinimalEndSymbol::instance ( ) {
	return '\0';
}

template < >
inline object::Object MinimalEndSymbol::instance < object::Object > ( ) {
	return object::Object ( MinimalEndSymbol ( ) );
}

template < >
inline std::string MinimalEndSymbol::instance < std::string > ( ) {
	return std::string ( 1, MinimalEndSymbol::instance < char > ( ) );
}

template < >
inline MinimalEndSymbol MinimalEndSymbol::instance < MinimalEndSymbol > ( ) {
	return MinimalEndSymbol ( );
}

template < >
inline common::ranked_symbol < > MinimalEndSymbol::instance < common::ranked_symbol < > > ( ) {
	return common::ranked_symbol < > ( MinimalEndSymbol::instance < DefaultSymbolType > ( ), 0u );
}

} /* namespace alphabet */

