From 4d027e595350b809b97af24eb51c6f3f768b314c Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Mon, 1 Aug 2016 21:27:26 +0200 Subject: [PATCH] update rte to components2 --- alib2data/src/rte/formal/FormalRTE.cpp | 47 ++------------------------ alib2data/src/rte/formal/FormalRTE.h | 43 +++++++++++++++++++++-- 2 files changed, 44 insertions(+), 46 deletions(-) diff --git a/alib2data/src/rte/formal/FormalRTE.cpp b/alib2data/src/rte/formal/FormalRTE.cpp index dcbe114412..15a944696a 100644 --- a/alib2data/src/rte/formal/FormalRTE.cpp +++ b/alib2data/src/rte/formal/FormalRTE.cpp @@ -1,5 +1,4 @@ #include "FormalRTE.h" -#include <exception/CommonException.h> #include "FormalRTEEmpty.h" #include "FormalRTESymbol.h" @@ -19,7 +18,7 @@ namespace rte { -FormalRTE::FormalRTE ( std::set < alphabet::RankedSymbol > alphabetF, std::set < alphabet::RankedSymbol > alphabetK, FormalRTEElement && rte ) : std::Components < FormalRTE, alphabet::RankedSymbol, std::tuple < GeneralAlphabet, ConstantAlphabet >, std::tuple < > > ( std::make_tuple ( std::move ( alphabetF ), std::move ( alphabetK ) ), std::tuple < > ( ) ), rte ( NULL ) { +FormalRTE::FormalRTE ( std::set < alphabet::RankedSymbol > alphabetF, std::set < alphabet::RankedSymbol > alphabetK, FormalRTEElement && rte ) : std::Components2 < FormalRTE, alphabet::RankedSymbol, std::tuple < GeneralAlphabet, ConstantAlphabet >, std::tuple < > > ( std::make_tuple ( std::move ( alphabetF ), std::move ( alphabetK ) ), std::tuple < > ( ) ), rte ( NULL ) { setRTE ( std::move ( rte ) ); } @@ -51,11 +50,11 @@ FormalRTE::FormalRTE ( const FormalRTEElement & rte ) : FormalRTE ( rte.computeM FormalRTE::FormalRTE ( FormalRTEElement && rte ) : FormalRTE ( rte.computeMinimalAlphabets ( ), rte ) { } -FormalRTE::FormalRTE ( const FormalRTE & other ) : std::Components < FormalRTE, alphabet::RankedSymbol, std::tuple < GeneralAlphabet, ConstantAlphabet >, std::tuple < > > ( std::make_tuple ( other.getAlphabet ( ), other.getConstantAlphabet ( ) ), std::tuple < > ( ) ), rte ( other.rte ) { +FormalRTE::FormalRTE ( const FormalRTE & other ) : std::Components2 < FormalRTE, alphabet::RankedSymbol, std::tuple < GeneralAlphabet, ConstantAlphabet >, std::tuple < > > ( std::make_tuple ( other.getAlphabet ( ), other.getConstantAlphabet ( ) ), std::tuple < > ( ) ), rte ( other.rte ) { this->rte->attachRTE ( this ); } -FormalRTE::FormalRTE ( FormalRTE && other ) noexcept : std::Components < FormalRTE, alphabet::RankedSymbol, std::tuple < GeneralAlphabet, ConstantAlphabet >, std::tuple < > > ( std::make_tuple ( std::move ( other.accessComponent < GeneralAlphabet > ( ).get ( ) ), std::move ( other.accessComponent < ConstantAlphabet > ( ).get ( ) ) ), std::tuple < > ( ) ), rte ( std::move ( other.rte ) ) { +FormalRTE::FormalRTE ( FormalRTE && other ) noexcept : std::Components2 < FormalRTE, alphabet::RankedSymbol, std::tuple < GeneralAlphabet, ConstantAlphabet >, std::tuple < > > ( std::make_tuple ( std::move ( other.accessComponent < GeneralAlphabet > ( ).get ( ) ), std::move ( other.accessComponent < ConstantAlphabet > ( ).get ( ) ) ), std::tuple < > ( ) ), rte ( std::move ( other.rte ) ) { this->rte->attachRTE ( this ); } @@ -145,46 +144,6 @@ void FormalRTE::compose ( std::deque < sax::Token > & out ) const { } /* namespace rte */ -namespace std { - -template < > -bool rte::FormalRTE::Component < rte::FormalRTE, alphabet::RankedSymbol, rte::GeneralAlphabet >::used ( const alphabet::RankedSymbol & symbol ) const { - return static_cast < const rte::FormalRTE * > ( this )->getRTE ( ).testSymbol ( symbol ); -} - -template < > -bool rte::FormalRTE::Component < rte::FormalRTE, alphabet::RankedSymbol, rte::GeneralAlphabet >::available ( const alphabet::RankedSymbol & ) const { - return true; -} - -template < > -void rte::FormalRTE::Component < rte::FormalRTE, alphabet::RankedSymbol, rte::GeneralAlphabet >::valid ( const alphabet::RankedSymbol & symbol ) const { - const rte::FormalRTE * rte = static_cast < const rte::FormalRTE * > ( this ); - - if ( rte->accessComponent < rte::ConstantAlphabet > ( ).get ( ).count ( symbol ) ) - throw ::exception::CommonException ( "Symbol " + ( std::string ) symbol + "cannot be in general alphabet since it is already in constant alphabet" ); -} - -template < > -bool rte::FormalRTE::Component < rte::FormalRTE, alphabet::RankedSymbol, rte::ConstantAlphabet >::used ( const alphabet::RankedSymbol & symbol ) const { - return static_cast < const rte::FormalRTE * > ( this )->getRTE ( ).testSymbol ( symbol ); -} - -template < > -bool rte::FormalRTE::Component < rte::FormalRTE, alphabet::RankedSymbol, rte::ConstantAlphabet >::available ( const alphabet::RankedSymbol & ) const { - return true; -} - -template < > -void rte::FormalRTE::Component < rte::FormalRTE, alphabet::RankedSymbol, rte::ConstantAlphabet >::valid ( const alphabet::RankedSymbol & symbol ) const { - const rte::FormalRTE * rte = static_cast < const rte::FormalRTE * > ( this ); - - if ( rte->accessComponent < rte::GeneralAlphabet > ( ).get ( ).count ( symbol ) ) - throw ::exception::CommonException ( "Symbol " + ( std::string ) symbol + "cannot be in constant alphabet since it is already in general alphabet" ); -} - -} /* namespace std */ - namespace alib { auto formalRTEParserRegister = xmlApi < rte::RTE >::ParserRegister < rte::FormalRTE > ( ); diff --git a/alib2data/src/rte/formal/FormalRTE.h b/alib2data/src/rte/formal/FormalRTE.h index 5e4ae0ad86..a2fbdeeb26 100644 --- a/alib2data/src/rte/formal/FormalRTE.h +++ b/alib2data/src/rte/formal/FormalRTE.h @@ -3,9 +3,10 @@ #include <string> #include <set> +#include <exception/CommonException.h> #include "FormalRTEElement.h" #include "../RTEBase.h" -#include <core/components.hpp> +#include <core/components2.hpp> namespace rte { @@ -19,7 +20,7 @@ class ConstantAlphabet; * Represents regular tree expression parsed from the XML. Regular tree expression is stored * as a tree of RTEElement elements. */ -class FormalRTE : public RTEBase, public std::Components < FormalRTE, alphabet::RankedSymbol, std::tuple < GeneralAlphabet, ConstantAlphabet >, std::tuple < > > { +class FormalRTE : public RTEBase, public std::Components2 < FormalRTE, alphabet::RankedSymbol, std::tuple < GeneralAlphabet, ConstantAlphabet >, std::tuple < > > { protected: std::smart_ptr < FormalRTEElement > rte; @@ -146,4 +147,42 @@ public: } /* namespace rte */ +namespace std { + +template < > +class ComponentConstraint2< rte::FormalRTE, alphabet::RankedSymbol, rte::GeneralAlphabet > { +public: + static bool used ( const rte::FormalRTE & rte, const alphabet::RankedSymbol & symbol ) { + return rte.getRTE ( ).testSymbol ( symbol ); + } + + static bool available ( const rte::FormalRTE &, const alphabet::RankedSymbol & ) { + return true; + } + + static void valid ( const rte::FormalRTE & rte, const alphabet::RankedSymbol & symbol ) { + if ( rte.accessComponent < rte::ConstantAlphabet > ( ).get ( ).count ( symbol ) ) + throw ::exception::CommonException ( "Symbol " + ( std::string ) symbol + "cannot be in general alphabet since it is already in constant alphabet" ); + } +}; + +template < > +class ComponentConstraint2< rte::FormalRTE, alphabet::RankedSymbol, rte::ConstantAlphabet > { +public: + static bool used ( const rte::FormalRTE & rte, const alphabet::RankedSymbol & symbol ) { + return rte.getRTE ( ).testSymbol ( symbol ); + } + + static bool available ( const rte::FormalRTE &, const alphabet::RankedSymbol & ) { + return true; + } + + static void valid ( const rte::FormalRTE & rte, const alphabet::RankedSymbol & symbol ) { + if ( rte.accessComponent < rte::GeneralAlphabet > ( ).get ( ).count ( symbol ) ) + throw ::exception::CommonException ( "Symbol " + ( std::string ) symbol + "cannot be in constant alphabet since it is already in general alphabet" ); + } +}; + +} /* namespace std */ + #endif /* FORMAL_RTE_H_ */ -- GitLab