/*
 * SymbolComparator.h
 *
 *  Created on: 16. 02. 2021
 *      Author: Martin Prokopic
 */

#pragma once

#include <alib/utility>
#include <object/Object.h>
#include <alphabet/MinimalEndSymbol.h>

namespace alphabet {

template < class SymbolType >
class SymbolCompare : public std::less < SymbolType > {};

template < >
class SymbolCompare < object::Object > {
public:
    bool operator ()(const object::Object & a, const object::Object & b) const {
        const auto * aAsMinimalEndSymbol = dynamic_cast < const object::AnyObject < alphabet::MinimalEndSymbol > * >( & a.getData () );
        const auto * bAsMinimalEndSymbol = dynamic_cast < const object::AnyObject < alphabet::MinimalEndSymbol > * >( & b.getData () );

        if(static_cast<bool>(aAsMinimalEndSymbol) == static_cast<bool>(bAsMinimalEndSymbol))
            return a < b;

        return static_cast<bool>(aAsMinimalEndSymbol);
    }
};

} /* namespace alphabet */