diff --git a/alib2data/src/alphabet/BarSymbol.h b/alib2data/src/alphabet/BarSymbol.h index 4a1e9ce10e2eb48ad4e93d1aad2561e49ac88041..6da7fc0f60d3e04905b2f6246e2d5d044b23e138 100644 --- a/alib2data/src/alphabet/BarSymbol.h +++ b/alib2data/src/alphabet/BarSymbol.h @@ -24,7 +24,7 @@ #ifndef BAR_SYMBOL_H_ #define BAR_SYMBOL_H_ -#include "SymbolBase.h" +#include <alib/compare> #include <object/Object.h> #include <common/ranked_symbol.hpp> @@ -34,7 +34,7 @@ namespace alphabet { * \brief * Represents bar symbol used in tree linearization. */ -class BarSymbol : public SymbolBase { +class BarSymbol : public ext::CompareOperators < BarSymbol > { public: /** * \brief @@ -42,15 +42,6 @@ public: */ explicit BarSymbol ( ); - /** - * @copydoc base::CommonBase < SymbolBase >::compare ( const SymbolBase & ) const - */ - virtual int compare ( const SymbolBase & other ) const override { - if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return this->compare ( ( decltype ( * this ) )other ); - - return ext::type_index ( typeid ( * this ) ) - ext::type_index ( typeid ( other ) ); - } - /** * The actual compare method * diff --git a/alib2data/src/alphabet/BlankSymbol.h b/alib2data/src/alphabet/BlankSymbol.h index 656274e3334db78b2e34110cb2dba4ef8f4e9a52..6399009ebf0c2e13504919ad85bc7ce00770720d 100644 --- a/alib2data/src/alphabet/BlankSymbol.h +++ b/alib2data/src/alphabet/BlankSymbol.h @@ -24,7 +24,7 @@ #ifndef BLANK_SYMBOL_H_ #define BLANK_SYMBOL_H_ -#include "SymbolBase.h" +#include <alib/compare> #include <object/Object.h> #include <common/ranked_symbol.hpp> @@ -34,7 +34,7 @@ namespace alphabet { * \brief * Represents blank symbol used in the turing machine. */ -class BlankSymbol : public SymbolBase { +class BlankSymbol : public ext::CompareOperators < BlankSymbol > { public: /** * \brief @@ -42,15 +42,6 @@ public: */ explicit BlankSymbol ( ); - /** - * @copydoc base::CommonBase < SymbolBase >::compare ( const SymbolBase & ) const - */ - virtual int compare ( const SymbolBase & other ) const override { - if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return this->compare ( ( decltype ( * this ) )other ); - - return ext::type_index ( typeid ( * this ) ) - ext::type_index ( typeid ( other ) ); - } - /** * The actual compare method * diff --git a/alib2data/src/alphabet/BottomOfTheStackSymbol.h b/alib2data/src/alphabet/BottomOfTheStackSymbol.h index fa6a13ac5c1340b0447b76de92be692186dd8b25..21ea81bb972e6b9b14b9b172de652ea6b2f3bc34 100644 --- a/alib2data/src/alphabet/BottomOfTheStackSymbol.h +++ b/alib2data/src/alphabet/BottomOfTheStackSymbol.h @@ -24,7 +24,7 @@ #ifndef BOTTOM_OF_THE_STACK_SYMBOL_H_ #define BOTTOM_OF_THE_STACK_SYMBOL_H_ -#include "SymbolBase.h" +#include <alib/compare> #include <object/Object.h> #include <common/ranked_symbol.hpp> @@ -34,7 +34,7 @@ namespace alphabet { * \brief * Represents bottom of the stack symbol used in the visibly pushdown automata. */ -class BottomOfTheStackSymbol : public SymbolBase { +class BottomOfTheStackSymbol : public ext::CompareOperators < BottomOfTheStackSymbol > { public: /** * \brief @@ -42,15 +42,6 @@ public: */ explicit BottomOfTheStackSymbol ( ); - /** - * @copydoc base::CommonBase < SymbolBase >::compare ( const SymbolBase & ) const - */ - virtual int compare ( const SymbolBase & other ) const override { - if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return this->compare ( ( decltype ( * this ) )other ); - - return ext::type_index ( typeid ( * this ) ) - ext::type_index ( typeid ( other ) ); - } - /** * The actual compare method * diff --git a/alib2data/src/alphabet/EndSymbol.h b/alib2data/src/alphabet/EndSymbol.h index 464b14d9bfe98a44e4b31c014e06201a6b6beb25..b0ab079c93bc0873a301525bb63b22749e34a881 100644 --- a/alib2data/src/alphabet/EndSymbol.h +++ b/alib2data/src/alphabet/EndSymbol.h @@ -24,7 +24,7 @@ #ifndef END_SYMBOL_H_ #define END_SYMBOL_H_ -#include "SymbolBase.h" +#include <alib/compare> #include <object/Object.h> #include <common/ranked_symbol.hpp> @@ -34,7 +34,7 @@ namespace alphabet { * \brief * Represents end symbol used as termation symbol of a string. */ -class EndSymbol : public SymbolBase { +class EndSymbol : public ext::CompareOperators < EndSymbol > { public: /** * \brief @@ -42,15 +42,6 @@ public: */ explicit EndSymbol ( ); - /** - * @copydoc base::CommonBase < SymbolBase >::compare ( const SymbolBase & ) const - */ - virtual int compare ( const SymbolBase & other ) const override { - if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return this->compare ( ( decltype ( * this ) )other ); - - return ext::type_index ( typeid ( * this ) ) - ext::type_index ( typeid ( other ) ); - } - /** * The actual compare method * diff --git a/alib2data/src/alphabet/InitialSymbol.h b/alib2data/src/alphabet/InitialSymbol.h index f11f6069fef9c79c601cebf6a042fc2533ba2d23..7c5c74691d14af6fd3bf0c3c3fcbd6db7c0a03d2 100644 --- a/alib2data/src/alphabet/InitialSymbol.h +++ b/alib2data/src/alphabet/InitialSymbol.h @@ -24,7 +24,7 @@ #ifndef INITIAL_SYMBOL_LABEL_H_ #define INITIAL_SYMBOL_LABEL_H_ -#include "SymbolBase.h" +#include <alib/compare> #include <object/Object.h> #include <common/ranked_symbol.hpp> @@ -34,7 +34,7 @@ namespace alphabet { * \brief * Represents initial symbol used as an initial symbol of a grammar. */ -class InitialSymbol : public SymbolBase { +class InitialSymbol : public ext::CompareOperators < InitialSymbol > { public: /** * \brief @@ -42,15 +42,6 @@ public: */ explicit InitialSymbol ( ); - /** - * @copydoc base::CommonBase < SymbolBase >::compare ( const SymbolBase & ) const - */ - virtual int compare ( const SymbolBase & other ) const override{ - if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return this->compare ( ( decltype ( * this ) )other ); - - return ext::type_index ( typeid ( * this ) ) - ext::type_index ( typeid ( other ) ); - } - /** * The actual compare method * diff --git a/alib2data/src/alphabet/NonlinearVariableSymbol.h b/alib2data/src/alphabet/NonlinearVariableSymbol.h index 4522c8965e278d89d96aa2e1c0a84256d1319fd1..1670e719856f34f1783440f07a24202e1ee5cb17 100644 --- a/alib2data/src/alphabet/NonlinearVariableSymbol.h +++ b/alib2data/src/alphabet/NonlinearVariableSymbol.h @@ -24,7 +24,7 @@ #ifndef NONLINEAR_VARIABLE_SYMBOL_H_ #define NONLINEAR_VARIABLE_SYMBOL_H_ -#include "SymbolBase.h" +#include <alib/compare> #include <core/normalize.hpp> #include <alphabet/common/SymbolNormalize.h> @@ -35,7 +35,7 @@ namespace alphabet { * Represents the nonlinear variable symbol used in a nonlinear tree pattern. */ template < class SymbolType = DefaultSymbolType > -class NonlinearVariableSymbol : public SymbolBase { +class NonlinearVariableSymbol : public ext::CompareOperators < NonlinearVariableSymbol < SymbolType > > { /** * \brief the symbol of the nonlinear variable. */ @@ -62,15 +62,6 @@ public: */ SymbolType && getSymbol ( ) &&; - /** - * @copydoc base::CommonBase < SymbolBase >::compare ( const SymbolBase & ) const - */ - virtual int compare ( const SymbolBase & other ) const override { - if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return this->compare ( ( decltype ( * this ) )other ); - - return ext::type_index ( typeid ( * this ) ) - ext::type_index ( typeid ( other ) ); - } - /** * The actual compare method * diff --git a/alib2data/src/alphabet/StartSymbol.h b/alib2data/src/alphabet/StartSymbol.h index fcc0f744a5dfda2ea7372da8d178a6c137b89fde..0de4fdbd4cfaf0ef1e246c237a0dcf07de65fad4 100644 --- a/alib2data/src/alphabet/StartSymbol.h +++ b/alib2data/src/alphabet/StartSymbol.h @@ -24,7 +24,7 @@ #ifndef START_SYMBOL_H_ #define START_SYMBOL_H_ -#include "SymbolBase.h" +#include <alib/compare> #include <object/Object.h> #include <common/ranked_symbol.hpp> @@ -34,7 +34,7 @@ namespace alphabet { * \brief * Represents start symbol used as initializing symbol of a string. */ -class StartSymbol : public SymbolBase { +class StartSymbol : public ext::CompareOperators < StartSymbol > { public: /** * \brief @@ -42,15 +42,6 @@ public: */ explicit StartSymbol ( ); - /** - * @copydoc base::CommonBase < SymbolBase >::compare ( const SymbolBase & ) const - */ - virtual int compare ( const SymbolBase & other ) const override { - if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return this->compare ( ( decltype ( * this ) )other ); - - return ext::type_index ( typeid ( * this ) ) - ext::type_index ( typeid ( other ) ); - } - /** * The actual compare method * diff --git a/alib2data/src/alphabet/SymbolBase.h b/alib2data/src/alphabet/SymbolBase.h deleted file mode 100644 index 73531bf7e140b4a23e1a6343409c6d165e1b9f1d..0000000000000000000000000000000000000000 --- a/alib2data/src/alphabet/SymbolBase.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SymbolBase.h - * - * 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/>. - * - * Created on: Mar 26, 2013 - * Author: Jan Travnicek - */ - -#ifndef SYMBOL_BASE_H_ -#define SYMBOL_BASE_H_ - -#include <alib/compare> - -namespace alphabet { - -/** - * \brief Represents base for a concrete symbol type. - */ -class SymbolBase : public ext::CompareOperators < SymbolBase > { -public: - virtual ~SymbolBase ( ) noexcept { - } - - /** - * \brief Comparison helper method evaluating allowing possibly deeper comparison of this with other class of the same type. - * - * \details If the other class is of different type the relative order is computer by means of type_index. - * - * \param other the other class to compare with - * - * \returns result of actual comparison if type of this class and other class is the same, result of difference of type indexes othervise. - */ - virtual int compare ( const SymbolBase & other ) const = 0; -}; - -} /* namespace alphabet */ - -#endif /* SYMBOL_BASE_H_ */ diff --git a/alib2data/src/alphabet/VariablesBarSymbol.h b/alib2data/src/alphabet/VariablesBarSymbol.h index ae68937536f27672ac342003b851f243ca62da59..801a82916987da35949070c8d1a1de400b39683e 100644 --- a/alib2data/src/alphabet/VariablesBarSymbol.h +++ b/alib2data/src/alphabet/VariablesBarSymbol.h @@ -24,7 +24,7 @@ #ifndef VARIABLES_BAR_SYMBOL_H_ #define VARIABLES_BAR_SYMBOL_H_ -#include "SymbolBase.h" +#include <alib/compare> #include <common/ranked_symbol.hpp> #include <object/Object.h> @@ -34,7 +34,7 @@ namespace alphabet { * \brief * Represents variables bar symbol used in tree linearization. */ -class VariablesBarSymbol : public SymbolBase { +class VariablesBarSymbol : public ext::CompareOperators < VariablesBarSymbol > { public: /** * \brief @@ -42,15 +42,6 @@ public: */ explicit VariablesBarSymbol ( ); - /** - * @copydoc base::CommonBase < SymbolBase >::compare ( const SymbolBase & ) const - */ - virtual int compare ( const SymbolBase & other ) const override { - if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return this->compare ( ( decltype ( * this ) )other ); - - return ext::type_index ( typeid ( * this ) ) - ext::type_index ( typeid ( other ) ); - } - /** * The actual compare method * diff --git a/alib2data/src/alphabet/WildcardSymbol.h b/alib2data/src/alphabet/WildcardSymbol.h index 37b61c540d0ba716597f34aa3081eba52e61e51f..f674b455fdac77a063eaa118f7b91da713b0c699 100644 --- a/alib2data/src/alphabet/WildcardSymbol.h +++ b/alib2data/src/alphabet/WildcardSymbol.h @@ -24,7 +24,7 @@ #ifndef SUBTREE_WILDCARD_SYMBOL_H_ #define SUBTREE_WILDCARD_SYMBOL_H_ -#include "SymbolBase.h" +#include <alib/compare> #include <common/ranked_symbol.hpp> #include <object/Object.h> @@ -34,7 +34,7 @@ namespace alphabet { * \brief * Represents a wildcard used as representation of anything here in a string or a tree. */ -class WildcardSymbol : public SymbolBase { +class WildcardSymbol : public ext::CompareOperators < WildcardSymbol > { public: /** * \brief @@ -42,15 +42,6 @@ public: */ explicit WildcardSymbol ( ); - /** - * @copydoc base::CommonBase < SymbolBase >::compare ( const SymbolBase & ) const - */ - virtual int compare ( const SymbolBase & other ) const override { - if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return this->compare ( ( decltype ( * this ) )other ); - - return ext::type_index ( typeid ( * this ) ) - ext::type_index ( typeid ( other ) ); - } - /** * The actual compare method * diff --git a/alib2data/test-src/alphabet/SymbolTest.cpp b/alib2data/test-src/alphabet/SymbolTest.cpp index 0ece732e728366630302a9a3d50a2f02f2924aff..13d1e7ead195b9c77c3c295e75772311c4aa55d3 100644 --- a/alib2data/test-src/alphabet/SymbolTest.cpp +++ b/alib2data/test-src/alphabet/SymbolTest.cpp @@ -23,20 +23,10 @@ void SymbolTest::tearDown ( ) { } void SymbolTest::testOrder ( ) { - alphabet::BlankSymbol bs; - alphabet::StartSymbol ss; - alphabet::EndSymbol es; - common::ranked_symbol < > rs1 ( DefaultSymbolType ( alphabet::BarSymbol { } ), DefaultRankType ( 0 ) ); common::ranked_symbol < > rs2 ( DefaultSymbolType ( alphabet::BarSymbol { } ), DefaultRankType ( 0 ) ); - CPPUNIT_EXCLUSIVE_OR ( bs < ss, ss < bs ); - CPPUNIT_EXCLUSIVE_OR ( bs < es, es < bs ); - CPPUNIT_ASSERT ( rs1 == rs2 ); - - // CPPUNIT_ASSERT(es < ls); //End symbol typically denoted by '$' is lexicographically smaller than any other symbol - // CPPUNIT_ASSERT(ls < ss); //Start symbol typically denoted by '^' is lexicographically bigger than any other symbol } namespace alphabet {