diff --git a/alib2data/src/rte/formal/FormalRTE.cpp b/alib2data/src/rte/formal/FormalRTE.cpp index 9191a9d81bd0de9badb2c026c841d091f931de49..1b6fa978c282d3c3cc9ba8a7c146b2bbb6d5fe1f 100644 --- a/alib2data/src/rte/formal/FormalRTE.cpp +++ b/alib2data/src/rte/formal/FormalRTE.cpp @@ -39,14 +39,6 @@ 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 ) { - 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 ) ) { - this->rte->attachRTE ( this ); -} - RTEBase * FormalRTE::clone ( ) const { return new FormalRTE ( * this ); } @@ -55,26 +47,6 @@ RTEBase * FormalRTE::plunder ( ) && { return new FormalRTE ( std::move ( * this ) ); } -FormalRTE & FormalRTE::operator =( const FormalRTE & other ) { - if ( this == & other ) - return * this; - - * this = FormalRTE ( other ); - - return * this; -} - -FormalRTE & FormalRTE::operator =( FormalRTE && other ) noexcept { - std::swap ( this->rte, other.rte ); - std::swap ( accessComponent < GeneralAlphabet > ( ).get ( ), other.accessComponent < GeneralAlphabet > ( ).get ( ) ); - std::swap ( accessComponent < ConstantAlphabet > ( ).get ( ), other.accessComponent < ConstantAlphabet > ( ).get ( ) ); - - return * this; -} - -FormalRTE::~FormalRTE ( ) noexcept { -} - const FormalRTEElement & FormalRTE::getRTE ( ) const { return * rte; } @@ -90,8 +62,8 @@ void FormalRTE::setRTE ( const FormalRTEElement & rte ) { void FormalRTE::setRTE ( FormalRTEElement && param ) { this->rte = std::smart_ptr < FormalRTEElement > ( std::move ( param ).plunder ( ) ); - if ( !this->rte->attachRTE ( this ) ) - throw exception::CommonException ( "Input symbols not in the alphabet." ); + if ( !this->rte->checkAlphabet ( getAlphabet ( ), getConstantAlphabet ( ) ) ) + throw exception::CommonException ( "Symbols not matching alphabets." ); } void FormalRTE::operator >>( std::ostream & out ) const { diff --git a/alib2data/src/rte/formal/FormalRTE.h b/alib2data/src/rte/formal/FormalRTE.h index 527c870812473f97d14ef25e4bb9b18fb05226d8..a0904df266a9cf4959f2cb797ebb9c8de8fd911e 100644 --- a/alib2data/src/rte/formal/FormalRTE.h +++ b/alib2data/src/rte/formal/FormalRTE.h @@ -32,16 +32,6 @@ public: explicit FormalRTE ( const FormalRTEElement & rte ); explicit FormalRTE ( FormalRTEElement && rte ); - /** - * Copy constructor. - * @param other RTE to copy - */ - FormalRTE ( const FormalRTE & other ); - FormalRTE ( FormalRTE && other ) noexcept; - FormalRTE & operator =( const FormalRTE & other ); - FormalRTE & operator =( FormalRTE && other ) noexcept; - ~FormalRTE ( ) noexcept; - /** * @copydoc FormalRTEElement::clone() const */ diff --git a/alib2data/src/rte/formal/FormalRTEAlternation.cpp b/alib2data/src/rte/formal/FormalRTEAlternation.cpp index fb76f66909713fc4b8801a2b307a30cb1703ac29..7291653d9efa83325d39077fb94793dd403140b8 100644 --- a/alib2data/src/rte/formal/FormalRTEAlternation.cpp +++ b/alib2data/src/rte/formal/FormalRTEAlternation.cpp @@ -5,58 +5,26 @@ namespace rte { -FormalRTEAlternation::FormalRTEAlternation ( FormalRTEElement && leftElement, FormalRTEElement && rightElement ) : left ( nullptr ), right ( nullptr ) { - setLeftElement ( std::move ( leftElement ) ); - setRightElement ( std::move ( rightElement ) ); +FormalRTEAlternation::FormalRTEAlternation ( FormalRTEElement && left, FormalRTEElement && right ) : BinaryNode < std::smart_ptr < FormalRTEElement >, std::smart_ptr < FormalRTEElement >, FormalRTEAlternation > ( std::smart_ptr < FormalRTEElement > ( std::move ( left ).plunder ( ) ), std::smart_ptr < FormalRTEElement > ( std::move ( right ).plunder ( ) ) ) { } FormalRTEAlternation::FormalRTEAlternation ( const FormalRTEElement & left, const FormalRTEElement & right ) : FormalRTEAlternation ( std::move_copy ( left ), std::move_copy ( right ) ) { } -FormalRTEAlternation::FormalRTEAlternation ( const FormalRTEAlternation & other ) : left ( other.left ), right ( other.right ) { -} - -FormalRTEAlternation::FormalRTEAlternation ( FormalRTEAlternation && other ) noexcept : left ( std::move ( other.left ) ), right ( std::move ( other.right ) ) { - left->attachRTE ( NULL ); - right->attachRTE ( NULL ); -} - -FormalRTEAlternation & FormalRTEAlternation::operator =( const FormalRTEAlternation & other ) { - if ( this == & other ) - return * this; - - * this = FormalRTEAlternation ( other ); - - return * this; -} - -FormalRTEAlternation & FormalRTEAlternation::operator =( FormalRTEAlternation && other ) noexcept { - std::swap ( this->left, other.left ); - std::swap ( this->right, other.right ); - - this->left->attachRTE ( this->parentRTE ); - this->right->attachRTE ( this->parentRTE ); - - return * this; -} - -FormalRTEAlternation::~FormalRTEAlternation ( ) noexcept { -} - const FormalRTEElement & FormalRTEAlternation::getLeftElement ( ) const { - return * left; + return * getLeft ( ); } const FormalRTEElement & FormalRTEAlternation::getRightElement ( ) const { - return * right; + return * getRight ( ); } FormalRTEElement & FormalRTEAlternation::getLeftElement ( ) { - return * left; + return * getLeft ( ); } FormalRTEElement & FormalRTEAlternation::getRightElement ( ) { - return * right; + return * getRight ( ); } void FormalRTEAlternation::setLeftElement ( const FormalRTEElement & element ) { @@ -64,10 +32,7 @@ void FormalRTEAlternation::setLeftElement ( const FormalRTEElement & element ) { } void FormalRTEAlternation::setLeftElement ( FormalRTEElement && element ) { - this->left = std::smart_ptr < FormalRTEElement > ( std::move ( element ).plunder ( ) ); - - if ( this->parentRTE && !left->attachRTE ( this->parentRTE ) ) - throw exception::CommonException ( "Input symbols not in the alphabet." ); + setLeft ( std::smart_ptr < FormalRTEElement > ( std::move ( element ).plunder ( ) ) ); } void FormalRTEAlternation::setRightElement ( const FormalRTEElement & element ) { @@ -75,10 +40,7 @@ void FormalRTEAlternation::setRightElement ( const FormalRTEElement & element ) } void FormalRTEAlternation::setRightElement ( FormalRTEElement && element ) { - this->right = std::smart_ptr < FormalRTEElement > ( std::move ( element ).plunder ( ) ); - - if ( this->parentRTE && !right->attachRTE ( this->parentRTE ) ) - throw exception::CommonException ( "Input symbols not in the alphabet." ); + setRight ( std::smart_ptr < FormalRTEElement > ( std::move ( element ).plunder ( ) ) ); } FormalRTEAlternation * FormalRTEAlternation::clone ( ) const { @@ -90,43 +52,35 @@ FormalRTEAlternation * FormalRTEAlternation::plunder ( ) && { } int FormalRTEAlternation::compare ( const FormalRTEAlternation & other ) const { - int res = left->compare ( * other.left ); + int res = getLeftElement ( ).compare ( other.getLeftElement ( ) ); - if ( res == 0 ) res = right->compare ( * other.right ); + if ( res == 0 ) res = getRightElement ( ).compare ( other.getRightElement ( ) ); return res; } void FormalRTEAlternation::operator >>( std::ostream & out ) const { out << "(FormalRTEAlternation"; - out << " " << * left; - out << " " << * right; + out << " " << getLeftElement ( ); + out << " " << getRightElement ( ); out << ")"; } bool FormalRTEAlternation::testSymbol ( const alphabet::RankedSymbol & symbol ) const { - if ( left->testSymbol ( symbol ) ) return true; + if ( getLeftElement ( ).testSymbol ( symbol ) ) return true; - if ( right->testSymbol ( symbol ) ) return true; + if ( getRightElement ( ).testSymbol ( symbol ) ) return true; return false; } -bool FormalRTEAlternation::attachRTE ( const FormalRTE * regexp ) { - if ( this->parentRTE == regexp ) return true; - - this->parentRTE = regexp; - - if ( !left->attachRTE ( regexp ) ) return false; - - if ( !right->attachRTE ( regexp ) ) return false; - - return true; +void FormalRTEAlternation::computeMinimalAlphabet ( std::set < alphabet::RankedSymbol > & alphabetF, std::set < alphabet::RankedSymbol > & alphabetK ) const { + getLeftElement ( ).computeMinimalAlphabet ( alphabetF, alphabetK ); + getRightElement ( ).computeMinimalAlphabet ( alphabetF, alphabetK ); } -void FormalRTEAlternation::computeMinimalAlphabet ( std::set < alphabet::RankedSymbol > & alphabetF, std::set < alphabet::RankedSymbol > & alphabetK ) const { - left->computeMinimalAlphabet ( alphabetF, alphabetK ); - right->computeMinimalAlphabet ( alphabetF, alphabetK ); +bool FormalRTEAlternation::checkAlphabet ( const std::set < alphabet::RankedSymbol > & alphabetF, const std::set < alphabet::RankedSymbol > & alphabetK ) const { + return getLeftElement ( ).checkAlphabet ( alphabetF, alphabetK ) && getRightElement ( ).checkAlphabet ( alphabetF, alphabetK ); } FormalRTEAlternation::operator std::string ( ) const { diff --git a/alib2data/src/rte/formal/FormalRTEAlternation.h b/alib2data/src/rte/formal/FormalRTEAlternation.h index 3211d5a2bc31ddd3fa487b887a4547ce12ad9533..322510a564d164666601aab522e2ec8142497a37 100644 --- a/alib2data/src/rte/formal/FormalRTEAlternation.h +++ b/alib2data/src/rte/formal/FormalRTEAlternation.h @@ -9,20 +9,7 @@ namespace rte { * Represents alternation operator in the regular expression. Contains list of FormalRTEElement * as operands of the operator. */ -class FormalRTEAlternation : public FormalRTEElement { -protected: - /** - * @copydoc FormalRTEElement::clone() const - */ - - std::smart_ptr < FormalRTEElement > left; - std::smart_ptr < FormalRTEElement > right; - - /** - * @copydoc FormalRTEElement::attachRTE() - */ - virtual bool attachRTE ( const FormalRTE * regexp ); - +class FormalRTEAlternation : public FormalRTEElement, public std::BinaryNode < std::smart_ptr < FormalRTEElement >, std::smart_ptr < FormalRTEElement >, FormalRTEAlternation > { public: void Accept ( void * userData, const FormalRTEElementVisitor & visitor ) const { visitor.Visit ( userData, * this ); @@ -31,13 +18,6 @@ public: explicit FormalRTEAlternation ( FormalRTEElement && left, FormalRTEElement && right ); explicit FormalRTEAlternation ( const FormalRTEElement & left, const FormalRTEElement & right ); - FormalRTEAlternation ( const FormalRTEAlternation & other ); - FormalRTEAlternation ( FormalRTEAlternation && other ) noexcept; - FormalRTEAlternation & operator =( const FormalRTEAlternation & other ); - FormalRTEAlternation & operator =( FormalRTEAlternation && other ) noexcept; - - virtual ~FormalRTEAlternation ( ) noexcept; - /** * @copydoc FormalRTEElement::clone() const */ @@ -58,6 +38,11 @@ public: */ virtual void computeMinimalAlphabet ( std::set < alphabet::RankedSymbol > & alphabetF, std::set < alphabet::RankedSymbol > & alphabetK ) const; + /** + * @copydoc FormalRTEElement::checkAlphabet() + */ + virtual bool checkAlphabet ( const std::set < alphabet::RankedSymbol > & alphabetF, const std::set < alphabet::RankedSymbol > & alphabetK ) const; + /** * @return elements */ diff --git a/alib2data/src/rte/formal/FormalRTEElement.cpp b/alib2data/src/rte/formal/FormalRTEElement.cpp index d36f226153555c9e354377acf165c439489b7af6..1cb3df1ddda232c400aac131012dd474b09dd3c6 100644 --- a/alib2data/src/rte/formal/FormalRTEElement.cpp +++ b/alib2data/src/rte/formal/FormalRTEElement.cpp @@ -9,15 +9,12 @@ namespace rte { -FormalRTEElement::FormalRTEElement ( ) : parentRTE ( NULL ) { -} - std::pair < std::set < alphabet::RankedSymbol >, std::set < alphabet::RankedSymbol > > FormalRTEElement::computeMinimalAlphabets ( ) const { std::set < alphabet::RankedSymbol > alphabetF; std::set < alphabet::RankedSymbol > alphabetK; computeMinimalAlphabet ( alphabetF, alphabetK ); - return std::make_pair ( std::move ( alphabetF), std::move ( alphabetK ) ); + return std::make_pair ( std::move ( alphabetF ), std::move ( alphabetK ) ); } } /* namespace rte */ @@ -36,4 +33,4 @@ void xmlApi < rte::FormalRTEElement >::compose ( std::deque < sax::Token > & out data.Accept ( ( void * ) & output, rte::RTEToXMLComposer::RTE_TO_XML_COMPOSER ); } -} /* namespace alib */ +} /* namespace rte */ diff --git a/alib2data/src/rte/formal/FormalRTEElement.h b/alib2data/src/rte/formal/FormalRTEElement.h index d18298e78d955f4cfcda019bc51f187e4fed3fac..492e0364c60f91dfef5af92929b61c112bcbbf70 100644 --- a/alib2data/src/rte/formal/FormalRTEElement.h +++ b/alib2data/src/rte/formal/FormalRTEElement.h @@ -5,11 +5,10 @@ #include "../common/RTEAlphabet.h" #include <XmlApi.hpp> #include <set> +#include <tree> namespace rte { -class FormalRTE; - class FormalRTEAlternation; class FormalRTEIteration; class FormalRTESubstitution; @@ -30,25 +29,10 @@ public: virtual void Visit ( void *, const FormalRTEEmpty & empty ) const = 0; }; -class FormalRTEElement : public alib::CommonBase < FormalRTEElement > { -protected: - /* - * Parent regexp contanining this instance of RTEElement - */ - const FormalRTE * parentRTE; - - /** - * Attaches the regexp to this instance and all its childs - * @param regexp parent regexp to attach as parent - * @return true if symbols used in regexp element are in the regexp's alphabet - */ - virtual bool attachRTE ( const FormalRTE * regexp ) = 0; - +class FormalRTEElement : public alib::CommonBase < FormalRTEElement >, public std::BaseNode < FormalRTEElement > { public: virtual void Accept ( void * userData, const FormalRTEElementVisitor & visitor ) const = 0; - explicit FormalRTEElement ( ); - /** * Traverses the regexp tree looking if particular Symbol is used in the regexp. * @@ -71,17 +55,12 @@ public: std::pair < std::set < alphabet::RankedSymbol >, std::set < alphabet::RankedSymbol > > computeMinimalAlphabets ( ) const; /** - * Creates copy of the element. - * @return copy of the element + * Traverses the regexp tree and checks whether all symbols in the regexp tree are in the alphabet + * + * @param alphabet + * @return true if symbols in the regexp are in the alphabet, false otherwise */ - - friend class FormalRTE; - - friend class FormalRTEAlternation; - friend class FormalRTEIteration; - friend class FormalRTESubstitution; - friend class FromalRTESymbol; - friend class FormalRTEEmpty; + virtual bool checkAlphabet ( const std::set < alphabet::RankedSymbol > & alphabetF, const std::set < alphabet::RankedSymbol > & alphabetK ) const = 0; }; } /* namespace rte */ diff --git a/alib2data/src/rte/formal/FormalRTEEmpty.cpp b/alib2data/src/rte/formal/FormalRTEEmpty.cpp index a25f3a7eae61382838f8defa805774abf8506934..e064d91432560643c65074599603bdec46438cc4 100644 --- a/alib2data/src/rte/formal/FormalRTEEmpty.cpp +++ b/alib2data/src/rte/formal/FormalRTEEmpty.cpp @@ -6,24 +6,6 @@ FormalRTEEmpty::FormalRTEEmpty ( ) { // so that default constructor is available } -FormalRTEEmpty::FormalRTEEmpty ( const FormalRTEEmpty & ) { - // so that copy constructor is available -} - -FormalRTEEmpty::FormalRTEEmpty ( FormalRTEEmpty && ) noexcept { - this->attachRTE ( NULL ); -} - -FormalRTEEmpty & FormalRTEEmpty::operator =( const FormalRTEEmpty & ) { - // this is actually different than default implementation - return * this; -} - -FormalRTEEmpty & FormalRTEEmpty::operator =( FormalRTEEmpty && ) noexcept { - // this is actually different than default implementation - return * this; -} - FormalRTEEmpty * FormalRTEEmpty::clone ( ) const { return new FormalRTEEmpty ( * this ); } @@ -44,14 +26,11 @@ bool FormalRTEEmpty::testSymbol ( const alphabet::RankedSymbol & ) const { return false; } -bool FormalRTEEmpty::attachRTE ( const FormalRTE * regexp ) { - if ( this->parentRTE == regexp ) return true; - - this->parentRTE = regexp; - return true; +void FormalRTEEmpty::computeMinimalAlphabet ( std::set < alphabet::RankedSymbol > & /*alphabetF*/, std::set < alphabet::RankedSymbol > & /*alphabetK*/ ) const { } -void FormalRTEEmpty::computeMinimalAlphabet ( std::set < alphabet::RankedSymbol > & /*alphabetF*/, std::set < alphabet::RankedSymbol > & /*alphabetK*/ ) const { +bool FormalRTEEmpty::checkAlphabet ( const std::set < alphabet::RankedSymbol > & /* alphabetF */, const std::set < alphabet::RankedSymbol > & /* alphabetK */ ) const { + return true; } FormalRTEEmpty::operator std::string ( ) const { diff --git a/alib2data/src/rte/formal/FormalRTEEmpty.h b/alib2data/src/rte/formal/FormalRTEEmpty.h index b2e0ca04e61c36929b49cca04dc77e096db464be..c296af2c1f720c810563e460a87f09d9368a1563 100644 --- a/alib2data/src/rte/formal/FormalRTEEmpty.h +++ b/alib2data/src/rte/formal/FormalRTEEmpty.h @@ -10,26 +10,12 @@ namespace rte { * Represents empty regular expression in the regular expression. */ class FormalRTEEmpty : public FormalRTEElement { -protected: - /** - * @copydoc FormalRTEElement::clone() const - */ - - /** - * @copydoc FormalRTEElement::attachRTE() - */ - virtual bool attachRTE ( const FormalRTE * regexp ); - public: void Accept ( void * userData, const FormalRTEElementVisitor & visitor ) const { visitor.Visit ( userData, * this ); } explicit FormalRTEEmpty ( ); - FormalRTEEmpty ( const FormalRTEEmpty & other ); - FormalRTEEmpty ( FormalRTEEmpty && other ) noexcept; - FormalRTEEmpty & operator =( const FormalRTEEmpty & other ); - FormalRTEEmpty & operator =( FormalRTEEmpty && other ) noexcept; /** * @copydoc FormalRTEElement::clone() const @@ -51,6 +37,11 @@ public: */ virtual void computeMinimalAlphabet ( std::set < alphabet::RankedSymbol > & alphabetF, std::set < alphabet::RankedSymbol > & alphabetK ) const; + /** + * @copydoc FormalRTEElement::checkAlphabet() + */ + virtual bool checkAlphabet ( const std::set < alphabet::RankedSymbol > & alphabetF, const std::set < alphabet::RankedSymbol > & alphabetK ) const; + virtual int compare ( const FormalRTEElement & other ) const { if ( std::type_index ( typeid ( * this ) ) == std::type_index ( typeid ( other ) ) ) return this->compare ( ( decltype ( * this ) )other ); diff --git a/alib2data/src/rte/formal/FormalRTEIteration.cpp b/alib2data/src/rte/formal/FormalRTEIteration.cpp index ce93805b9868e5407b45605ae735180b8b6eb9a7..8f315423ce2267b3ffbdd80c39a19f6be5467ed5 100644 --- a/alib2data/src/rte/formal/FormalRTEIteration.cpp +++ b/alib2data/src/rte/formal/FormalRTEIteration.cpp @@ -5,50 +5,18 @@ namespace rte { -FormalRTEIteration::FormalRTEIteration ( FormalRTEElement && element, FormalRTESymbolSubst substitutionSymbol ) : element ( nullptr ), substitutionSymbol ( nullptr ) { - setElement ( std::move ( element ) ); - setSubstitutionSymbol ( std::move ( substitutionSymbol ) ); +FormalRTEIteration::FormalRTEIteration ( FormalRTEElement && element, FormalRTESymbolSubst substitutionSymbol ) : std::UnaryNode < std::smart_ptr < FormalRTEElement >, std::smart_ptr < const FormalRTEElement >, FormalRTEIteration > ( std::smart_ptr < FormalRTEElement > ( std::move ( element ).plunder ( ) ) ), substitutionSymbol ( std::smart_ptr < FormalRTESymbolSubst > ( std::move ( substitutionSymbol ).plunder ( ) ) ) { } FormalRTEIteration::FormalRTEIteration ( const FormalRTEElement & element, FormalRTESymbolSubst substitutionSymbol ) : FormalRTEIteration ( std::move_copy ( element ), std::move ( substitutionSymbol ) ) { } -FormalRTEIteration::FormalRTEIteration ( const FormalRTEIteration & other ) : element ( other.element ), substitutionSymbol ( other.substitutionSymbol ) { -} - -FormalRTEIteration::FormalRTEIteration ( FormalRTEIteration && other ) noexcept : element ( std::move ( other.element ) ), substitutionSymbol ( std::move ( other.substitutionSymbol ) ) { - element->attachRTE ( NULL ); - substitutionSymbol->attachRTE ( NULL ); -} - -FormalRTEIteration & FormalRTEIteration::operator =( const FormalRTEIteration & other ) { - if ( this == & other ) - return * this; - - * this = FormalRTEIteration ( other ); - - return * this; -} - -FormalRTEIteration & FormalRTEIteration::operator =( FormalRTEIteration && other ) noexcept { - std::swap ( this->element, other.element ); - std::swap ( this->substitutionSymbol, other.substitutionSymbol ); - std::swap ( this->parentRTE, other.parentRTE ); - - this->attachRTE ( other.parentRTE ); - - return * this; -} - -FormalRTEIteration::~FormalRTEIteration ( ) noexcept { -} - const FormalRTEElement & FormalRTEIteration::getElement ( ) const { - return * element; + return * getChild ( ); } FormalRTEElement & FormalRTEIteration::getElement ( ) { - return * element; + return * getChild ( ); } const FormalRTESymbolSubst & FormalRTEIteration::getSubstitutionSymbol ( ) const { @@ -64,17 +32,11 @@ void FormalRTEIteration::setElement ( const FormalRTEElement & element ) { } void FormalRTEIteration::setElement ( FormalRTEElement && elementParam ) { - element = std::smart_ptr < FormalRTEElement > ( std::move ( elementParam ).plunder ( ) ); - - if ( this->parentRTE && !element->attachRTE ( this->parentRTE ) ) - throw exception::CommonException ( "Input symbols not in the alphabet." ); + setChild ( std::smart_ptr < FormalRTEElement > ( std::move ( elementParam ).plunder ( ) ) ); } void FormalRTEIteration::setSubstitutionSymbol ( FormalRTESymbolSubst symbol ) { substitutionSymbol = std::smart_ptr < FormalRTESymbolSubst > ( std::move ( symbol ).plunder ( ) ); - - if ( this->parentRTE && !substitutionSymbol->attachRTE ( this->parentRTE ) ) - throw exception::CommonException ( "Input symbols not in the alphabet." ); } FormalRTEIteration * FormalRTEIteration::clone ( ) const { @@ -95,26 +57,20 @@ int FormalRTEIteration::compare ( const FormalRTEIteration & other ) const { } void FormalRTEIteration::operator >>( std::ostream & out ) const { - out << "(RTEFormalRTEIteration " << * substitutionSymbol << " " << * element << ")"; + out << "(RTEFormalRTEIteration " << * substitutionSymbol << " " << getElement ( ) << ")"; } bool FormalRTEIteration::testSymbol ( const alphabet::RankedSymbol & symbol ) const { - return element->testSymbol ( symbol ); -} - -bool FormalRTEIteration::attachRTE ( const FormalRTE * regexp ) { - if ( this->parentRTE == regexp ) return true; - - this->parentRTE = regexp; - - if ( !this->element->attachRTE ( regexp ) ) return false; - - return this->parentRTE->getConstantAlphabet ( ).find ( this->substitutionSymbol->getSymbol ( ) ) != this->parentRTE->getConstantAlphabet ( ).end ( ); + return getChild ( )->testSymbol ( symbol ); } void FormalRTEIteration::computeMinimalAlphabet ( std::set < alphabet::RankedSymbol > & alphabetF, std::set < alphabet::RankedSymbol > & alphabetK ) const { alphabetK.insert ( substitutionSymbol->getSymbol ( ) ); - element->computeMinimalAlphabet ( alphabetF, alphabetK ); + getChild ( )->computeMinimalAlphabet ( alphabetF, alphabetK ); +} + +bool FormalRTEIteration::checkAlphabet ( const std::set < alphabet::RankedSymbol > & alphabetF, const std::set < alphabet::RankedSymbol > & alphabetK ) const { + return alphabetK.count ( getSubstitutionSymbol ( ).getSymbol ( ) ) > 0 && getElement ( ).checkAlphabet ( alphabetF, alphabetK ); } FormalRTEIteration::operator std::string ( ) const { diff --git a/alib2data/src/rte/formal/FormalRTEIteration.h b/alib2data/src/rte/formal/FormalRTEIteration.h index e68dde5af35c35d6e39b839294f489aea20dbfae..d77b12ef5ac57e9d62c11021f3fb9c52737ead0c 100644 --- a/alib2data/src/rte/formal/FormalRTEIteration.h +++ b/alib2data/src/rte/formal/FormalRTEIteration.h @@ -17,20 +17,10 @@ class RTEOptimize; * Represents iteration operator in the regular expression. Contains one FormalRTEElement * as operand. */ -class FormalRTEIteration : public FormalRTEElement { +class FormalRTEIteration : public FormalRTEElement, public std::UnaryNode < std::smart_ptr < FormalRTEElement >, std::smart_ptr < const FormalRTEElement >, FormalRTEIteration > { protected: - std::smart_ptr < FormalRTEElement > element; std::smart_ptr < FormalRTESymbolSubst > substitutionSymbol; - /** - * @copydoc FormalRTEElement::clone() const - */ - - /** - * @copydoc FormalRTEElement::attachRTE() - */ - virtual bool attachRTE ( const FormalRTE * regexp ); - public: void Accept ( void * userData, const FormalRTEElementVisitor & visitor ) const { visitor.Visit ( userData, * this ); @@ -39,12 +29,6 @@ public: explicit FormalRTEIteration ( FormalRTEElement &&, FormalRTESymbolSubst ); explicit FormalRTEIteration ( const FormalRTEElement &, FormalRTESymbolSubst ); - FormalRTEIteration ( const FormalRTEIteration & other ); - FormalRTEIteration ( FormalRTEIteration && other ) noexcept; - FormalRTEIteration & operator =( const FormalRTEIteration & other ); - FormalRTEIteration & operator =( FormalRTEIteration && other ) noexcept; - virtual ~FormalRTEIteration ( ) noexcept; - /** * @copydoc FormalRTEElement::clone() const */ @@ -65,6 +49,11 @@ public: */ virtual void computeMinimalAlphabet ( std::set < alphabet::RankedSymbol > & alphabetF, std::set < alphabet::RankedSymbol > & alphabetK ) const; + /** + * @copydoc FormalRTEElement::checkAlphabet() + */ + virtual bool checkAlphabet ( const std::set < alphabet::RankedSymbol > & alphabetF, const std::set < alphabet::RankedSymbol > & alphabetK ) const; + /** * @return element */ diff --git a/alib2data/src/rte/formal/FormalRTESubstitution.cpp b/alib2data/src/rte/formal/FormalRTESubstitution.cpp index 59aa739cbe09011b7f29adbdf72c7429959b0643..5bd0bc7b1f3e5b805f92526935f02685161856ea 100644 --- a/alib2data/src/rte/formal/FormalRTESubstitution.cpp +++ b/alib2data/src/rte/formal/FormalRTESubstitution.cpp @@ -4,53 +4,18 @@ namespace rte { -FormalRTESubstitution::FormalRTESubstitution ( FormalRTEElement && left, FormalRTEElement && right, FormalRTESymbolSubst substitutionSymbol ) : left ( nullptr ), right ( nullptr ), substitutionSymbol ( nullptr ) { - setLeftElement ( std::move ( left ) ); - setRightElement ( std::move ( right ) ); - setSubstitutionSymbol ( std::move ( substitutionSymbol ) ); +FormalRTESubstitution::FormalRTESubstitution ( FormalRTEElement && left, FormalRTEElement && right, FormalRTESymbolSubst substitutionSymbol ) : BinaryNode < std::smart_ptr < FormalRTEElement >, std::smart_ptr < FormalRTEElement >, FormalRTESubstitution > ( std::smart_ptr < FormalRTEElement > ( std::move ( left ).plunder ( ) ), std::smart_ptr < FormalRTEElement > ( std::move ( right ).plunder ( ) ) ), substitutionSymbol ( std::smart_ptr < FormalRTESymbolSubst > ( std::move ( substitutionSymbol ).plunder ( ) ) ) { } FormalRTESubstitution::FormalRTESubstitution ( const FormalRTEElement & left, const FormalRTEElement & right, FormalRTESymbolSubst substitutionSymbol ) : FormalRTESubstitution ( std::move_copy ( left ), std::move_copy ( right ), std::move ( substitutionSymbol ) ) { } -FormalRTESubstitution::FormalRTESubstitution ( const FormalRTESubstitution & other ) : left ( other.left ), right ( other.right ), substitutionSymbol ( other.substitutionSymbol ) { -} - -FormalRTESubstitution::FormalRTESubstitution ( FormalRTESubstitution && other ) noexcept : left ( std::move ( other.left ) ), right ( std::move ( other.right ) ), substitutionSymbol ( std::move ( other.substitutionSymbol ) ) { - left->attachRTE ( NULL ); - right->attachRTE ( NULL ); - substitutionSymbol->attachRTE ( NULL ); -} - -FormalRTESubstitution & FormalRTESubstitution::operator =( const FormalRTESubstitution & other ) { - if ( this == & other ) - return * this; - - * this = FormalRTESubstitution ( other ); - - return * this; -} - -FormalRTESubstitution & FormalRTESubstitution::operator =( FormalRTESubstitution && other ) noexcept { - std::swap ( this->left, other.left ); - std::swap ( this->right, other.right ); - std::swap ( this->substitutionSymbol, other.substitutionSymbol ); - - this->left->attachRTE ( this->parentRTE ); - this->right->attachRTE ( this->parentRTE ); - - return * this; -} - -FormalRTESubstitution::~FormalRTESubstitution ( ) noexcept { -} - const FormalRTEElement & FormalRTESubstitution::getLeftElement ( ) const { - return * left; + return * getLeft ( ); } const FormalRTEElement & FormalRTESubstitution::getRightElement ( ) const { - return * right; + return * getRight ( ); } const FormalRTESymbolSubst & FormalRTESubstitution::getSubstitutionSymbol ( ) const { @@ -58,11 +23,11 @@ const FormalRTESymbolSubst & FormalRTESubstitution::getSubstitutionSymbol ( ) co } FormalRTEElement & FormalRTESubstitution::getLeftElement ( ) { - return * left; + return * getLeft ( ); } FormalRTEElement & FormalRTESubstitution::getRightElement ( ) { - return * right; + return * getRight ( ); } FormalRTESymbolSubst & FormalRTESubstitution::getSubstitutionSymbol ( ) { @@ -74,10 +39,7 @@ void FormalRTESubstitution::setLeftElement ( const FormalRTEElement & element ) } void FormalRTESubstitution::setLeftElement ( FormalRTEElement && element ) { - left = std::smart_ptr < FormalRTEElement > ( std::move ( element ).plunder ( ) ); - - if ( this->parentRTE && !left->attachRTE ( this->parentRTE ) ) - throw exception::CommonException ( "Input symbols not in the alphabet." ); + setLeft ( std::smart_ptr < FormalRTEElement > ( std::move ( element ).plunder ( ) ) ); } void FormalRTESubstitution::setRightElement ( const FormalRTEElement & element ) { @@ -85,17 +47,11 @@ void FormalRTESubstitution::setRightElement ( const FormalRTEElement & element ) } void FormalRTESubstitution::setRightElement ( FormalRTEElement && element ) { - right = std::smart_ptr < FormalRTEElement > ( std::move ( element ).plunder ( ) ); - - if ( this->parentRTE && !right->attachRTE ( this->parentRTE ) ) - throw exception::CommonException ( "Input symbols not in the alphabet." ); + setRight ( std::smart_ptr < FormalRTEElement > ( std::move ( element ).plunder ( ) ) ); } void FormalRTESubstitution::setSubstitutionSymbol ( FormalRTESymbolSubst symbol ) { substitutionSymbol = std::smart_ptr < FormalRTESymbolSubst > ( std::move ( symbol ).plunder ( ) ); - - if ( this->parentRTE && !substitutionSymbol->attachRTE ( this->parentRTE ) ) - throw exception::CommonException ( "Input symbols not in the alphabet." ); } FormalRTESubstitution * FormalRTESubstitution::clone ( ) const { @@ -117,40 +73,30 @@ int FormalRTESubstitution::compare ( const FormalRTESubstitution & other ) const void FormalRTESubstitution::operator >>( std::ostream & out ) const { out << "(FormalRTESubstitution"; - out << " " << * left; + out << " " << getLeftElement ( ); out << " " << * substitutionSymbol; - out << " " << * right; + out << " " << getRightElement ( ); out << ")"; } bool FormalRTESubstitution::testSymbol ( const alphabet::RankedSymbol & symbol ) const { - if ( left->testSymbol ( symbol ) ) return true; + if ( getLeftElement ( ).testSymbol ( symbol ) ) return true; - if ( right->testSymbol ( symbol ) ) return true; + if ( getRightElement ( ).testSymbol ( symbol ) ) return true; if ( substitutionSymbol->getSymbol ( ) == symbol ) return true; return false; } -bool FormalRTESubstitution::attachRTE ( const FormalRTE * regexp ) { - if ( this->parentRTE == regexp ) return true; - - this->parentRTE = regexp; - - if ( this->parentRTE == regexp ) return true; - - if ( !left->attachRTE ( regexp ) ) return false; - - if ( !right->attachRTE ( regexp ) ) return false; - - return this->parentRTE->getConstantAlphabet ( ).find ( this->substitutionSymbol->getSymbol ( ) ) != this->parentRTE->getConstantAlphabet ( ).end ( ); -} - void FormalRTESubstitution::computeMinimalAlphabet ( std::set < alphabet::RankedSymbol > & alphabetF, std::set < alphabet::RankedSymbol > & alphabetK ) const { alphabetK.insert ( substitutionSymbol->getSymbol ( ) ); - left->computeMinimalAlphabet ( alphabetF, alphabetK ); - right->computeMinimalAlphabet ( alphabetF, alphabetK ); + getLeftElement ( ).computeMinimalAlphabet ( alphabetF, alphabetK ); + getRightElement ( ).computeMinimalAlphabet ( alphabetF, alphabetK ); +} + +bool FormalRTESubstitution::checkAlphabet ( const std::set < alphabet::RankedSymbol > & alphabetF, const std::set < alphabet::RankedSymbol > & alphabetK ) const { + return alphabetK.count ( getSubstitutionSymbol ( ).getSymbol ( ) ) > 0 && getLeftElement ( ).checkAlphabet ( alphabetF, alphabetK ) && getRightElement ( ).checkAlphabet ( alphabetF, alphabetK ); } FormalRTESubstitution::operator std::string ( ) const { diff --git a/alib2data/src/rte/formal/FormalRTESubstitution.h b/alib2data/src/rte/formal/FormalRTESubstitution.h index 936df0837322a4d12e7a2627d575bf7a92cbd8fe..c9510c237ea766240a8432d7c9a9daf30c6c4196 100644 --- a/alib2data/src/rte/formal/FormalRTESubstitution.h +++ b/alib2data/src/rte/formal/FormalRTESubstitution.h @@ -11,21 +11,10 @@ namespace rte { * Represents concatenation operator in the regular expression. Contains list of FormalRTEElement * as operands of the operator. */ -class FormalRTESubstitution : public FormalRTEElement { +class FormalRTESubstitution : public FormalRTEElement, public std::BinaryNode < std::smart_ptr < FormalRTEElement >, std::smart_ptr < FormalRTEElement >, FormalRTESubstitution > { protected: - /** - * @copydoc FormalRTEElement::clone() const - */ - - std::smart_ptr < FormalRTEElement > left; - std::smart_ptr < FormalRTEElement > right; std::smart_ptr < FormalRTESymbolSubst > substitutionSymbol; // substite this in left by right - /** - * @copydoc FormalRTEElement::attachRTE() - */ - virtual bool attachRTE ( const FormalRTE * regexp ); - public: void Accept ( void * userData, const FormalRTEElementVisitor & visitor ) const { visitor.Visit ( userData, * this ); @@ -34,12 +23,6 @@ public: explicit FormalRTESubstitution ( FormalRTEElement && left, FormalRTEElement && right, FormalRTESymbolSubst substitutionSymbol ); explicit FormalRTESubstitution ( const FormalRTEElement & left, const FormalRTEElement & right, FormalRTESymbolSubst substitutionSymbol ); - FormalRTESubstitution ( const FormalRTESubstitution & other ); - FormalRTESubstitution ( FormalRTESubstitution && other ) noexcept; - FormalRTESubstitution & operator =( const FormalRTESubstitution & other ); - FormalRTESubstitution & operator =( FormalRTESubstitution && other ) noexcept; - virtual ~FormalRTESubstitution ( ) noexcept; - /** * @copydoc FormalRTEElement::clone() const */ @@ -60,6 +43,11 @@ public: */ virtual void computeMinimalAlphabet ( std::set < alphabet::RankedSymbol > & alphabetF, std::set < alphabet::RankedSymbol > & alphabetK ) const; + /** + * @copydoc FormalRTEElement::checkAlphabet() + */ + virtual bool checkAlphabet ( const std::set < alphabet::RankedSymbol > & alphabetF, const std::set < alphabet::RankedSymbol > & alphabetK ) const; + /** * @return elements */ diff --git a/alib2data/src/rte/formal/FormalRTESymbol.cpp b/alib2data/src/rte/formal/FormalRTESymbol.cpp index 51f6630a627ace9ae5308de06ae690987e87adba..ea8d8940d1a4c1f4346bc4a961d7673456818831 100644 --- a/alib2data/src/rte/formal/FormalRTESymbol.cpp +++ b/alib2data/src/rte/formal/FormalRTESymbol.cpp @@ -10,8 +10,8 @@ namespace rte { FormalRTESymbol::FormalRTESymbol ( alphabet::RankedSymbol symbol ) : symbol ( std::move ( symbol ) ) { } -const alphabet::RankedSymbol & FormalRTESymbol::getSymbol ( ) const { - return this->symbol; +alphabet::RankedSymbol FormalRTESymbol::getSymbol ( ) const { + return symbol; } } /* namespace rte */ diff --git a/alib2data/src/rte/formal/FormalRTESymbol.h b/alib2data/src/rte/formal/FormalRTESymbol.h index 90f06ecda75e1dfd25cc9b5e4af5b35b342d3a20..3aab8a91d746df4b652809b93218079d43481612 100644 --- a/alib2data/src/rte/formal/FormalRTESymbol.h +++ b/alib2data/src/rte/formal/FormalRTESymbol.h @@ -14,7 +14,7 @@ protected: alphabet::RankedSymbol symbol; public: - explicit FormalRTESymbol ( alphabet::RankedSymbol symbol ); + FormalRTESymbol ( alphabet::RankedSymbol symbol ); /** * @copydoc FormalRTEElement::clone() const @@ -26,15 +26,7 @@ public: */ virtual FormalRTESymbol * plunder ( ) && = 0; - /** - * Returns the string representation of RTE Symbol. - */ - const alphabet::RankedSymbol & getSymbol ( ) const; - - /** - * @copydoc FormalRTEElement::attachRTE() - */ - virtual bool attachRTE ( const FormalRTE * regexp ) = 0; + alphabet::RankedSymbol getSymbol ( ) const; }; } /* namespace rte */ diff --git a/alib2data/src/rte/formal/FormalRTESymbolAlphabet.cpp b/alib2data/src/rte/formal/FormalRTESymbolAlphabet.cpp index 9759db6dd42259877750230c7e7e12836837055f..ecd251bbc32f09a10458deeaceca837ec39f2c72 100644 --- a/alib2data/src/rte/formal/FormalRTESymbolAlphabet.cpp +++ b/alib2data/src/rte/formal/FormalRTESymbolAlphabet.cpp @@ -6,32 +6,6 @@ namespace rte { -FormalRTESymbolAlphabet::FormalRTESymbolAlphabet ( const FormalRTESymbolAlphabet & other ) : FormalRTESymbol ( other.symbol ), elements ( std::move ( other.elements ) ) { -} - -FormalRTESymbolAlphabet::FormalRTESymbolAlphabet ( FormalRTESymbolAlphabet && other ) noexcept : FormalRTESymbol ( other.symbol ), elements ( std::move ( other.elements ) ) { - this->attachRTE ( NULL ); -} - -FormalRTESymbolAlphabet & FormalRTESymbolAlphabet::operator =( const FormalRTESymbolAlphabet & other ) { - if ( this == & other ) - return * this; - - * this = FormalRTESymbolAlphabet ( other ); - - return * this; -} - -FormalRTESymbolAlphabet & FormalRTESymbolAlphabet::operator =( FormalRTESymbolAlphabet && other ) noexcept { - std::swap ( this->symbol, other.symbol ); - std::swap ( this->elements, other.elements ); - std::swap ( this->parentRTE, other.parentRTE ); - - this->attachRTE ( other.parentRTE ); - - return * this; -} - FormalRTESymbolAlphabet::FormalRTESymbolAlphabet ( alphabet::RankedSymbol symbol ) : FormalRTESymbol ( symbol ) { } @@ -44,28 +18,29 @@ FormalRTESymbolAlphabet * FormalRTESymbolAlphabet::plunder ( ) && { } const std::vector < std::smart_ptr < const FormalRTESymbol > > & FormalRTESymbolAlphabet::getElements ( ) const { - return reinterpret_cast < const std::vector < std::smart_ptr < const FormalRTESymbol > > & > ( elements ); + return getChildren ( ); } -std::vector < std::smart_ptr < FormalRTESymbol > > & FormalRTESymbolAlphabet::getElements ( ) { - return elements; +const std::vector < std::smart_ptr < FormalRTESymbol > > & FormalRTESymbolAlphabet::getElements ( ) { + return getChildren ( ); } void FormalRTESymbolAlphabet::appendElement ( const FormalRTESymbol & element ) { - if ( primitive::Unsigned ( this->elements.size ( ) ) >= this->symbol.getRank ( ) ) - throw exception::CommonException ( "Ranked node cannot have more children then its rank" ); + return appendElement ( std::move_copy ( element ) ); +} - std::smart_ptr < FormalRTESymbol > elem ( element.clone ( ) ); +void FormalRTESymbolAlphabet::appendElement ( FormalRTESymbol && element ) { + // TODO: Remove this. Pass vector in constructor. Now an Element can have LESS children that is MUST have. - if ( this->parentRTE && !elem->attachRTE ( this->parentRTE ) ) - throw exception::CommonException ( "Input symbols not in the alphabet." ); + if ( primitive::Unsigned ( getChildren ( ).size ( ) ) >= this->symbol.getRank ( ) ) + throw exception::CommonException ( "Ranked node cannot have more children then its rank" ); - this->elements.push_back ( std::move ( elem ) ); + pushBackChild ( std::smart_ptr < FormalRTESymbol > ( std::move ( element ).plunder ( ) ) ); } int FormalRTESymbolAlphabet::compare ( const FormalRTESymbolAlphabet & other ) const { - auto first = std::tie ( symbol, getElements ( ) ); - auto second = std::tie ( other.symbol, other.getElements ( ) ); + auto first = std::tie ( symbol, getChildren ( ) ); + auto second = std::tie ( other.symbol, other.getChildren ( ) ); std::compare < decltype ( first ) > comp; @@ -73,34 +48,26 @@ int FormalRTESymbolAlphabet::compare ( const FormalRTESymbolAlphabet & other ) c } void FormalRTESymbolAlphabet::operator >>( std::ostream & out ) const { - out << "(FormalRTESymbolAlphabet " << " symbol = " << this->symbol << " children = " << this->elements << "})"; + out << "(FormalRTESymbolAlphabet " << " symbol = " << this->symbol << " children = " << this->getChildren ( ) << "})"; } bool FormalRTESymbolAlphabet::testSymbol ( const alphabet::RankedSymbol & symbol ) const { return symbol == this->symbol; } -bool FormalRTESymbolAlphabet::attachRTE ( const FormalRTE * regexp ) { - if ( this->parentRTE == regexp ) return true; - - this->parentRTE = regexp; - - if ( regexp == NULL ) return true; - - for ( const std::smart_ptr < FormalRTESymbol > & element : this->elements ) - if ( !element->attachRTE ( regexp ) ) return false; - - /* must be in F, and must not be in K */ - return this->parentRTE->getAlphabet ( ).find ( this->symbol ) != this->parentRTE->getAlphabet ( ).end ( ) || this->parentRTE->getConstantAlphabet ( ).find ( this->symbol ) == this->parentRTE->getConstantAlphabet ( ).end ( ); -} - void FormalRTESymbolAlphabet::computeMinimalAlphabet ( std::set < alphabet::RankedSymbol > & alphabetF, std::set < alphabet::RankedSymbol > & alphabetK ) const { alphabetF.insert ( this->symbol ); - for ( const auto & child : elements ) + for ( const std::smart_ptr < const FormalRTESymbol > & child : getChildren ( ) ) child->computeMinimalAlphabet ( alphabetF, alphabetK ); } +bool FormalRTESymbolAlphabet::checkAlphabet ( const std::set < alphabet::RankedSymbol > & alphabetF, const std::set < alphabet::RankedSymbol > & alphabetK ) const { + return alphabetF.count ( getSymbol ( ) ) > 0 && std::all_of ( getElements ( ).begin ( ), getElements ( ).end ( ), [&] ( const std::smart_ptr < const FormalRTESymbol > & e ) { + return e->checkAlphabet ( alphabetF, alphabetK ); + } ); +} + FormalRTESymbolAlphabet::operator std::string ( ) const { std::stringstream ss; ss << * this; diff --git a/alib2data/src/rte/formal/FormalRTESymbolAlphabet.h b/alib2data/src/rte/formal/FormalRTESymbolAlphabet.h index 2ce66dca55d0b1947a5ad363f871e066c778fd29..3ebb351a1c04a1e355ee150e42c83305fce699ef 100644 --- a/alib2data/src/rte/formal/FormalRTESymbolAlphabet.h +++ b/alib2data/src/rte/formal/FormalRTESymbolAlphabet.h @@ -9,19 +9,7 @@ namespace rte { /** * Represents symbol in the regular expression. Contains name of the symbol. */ -class FormalRTESymbolAlphabet : public FormalRTESymbol { -protected: - std::vector < std::smart_ptr < FormalRTESymbol > > elements; // can be empty (leaf) - - /** - * @copydoc FormalRTEElement::clone() const - */ - - /** - * @copydoc FormalRTESymbol::attachRTE() - */ - virtual bool attachRTE ( const FormalRTE * regexp ); - +class FormalRTESymbolAlphabet : public FormalRTESymbol, public std::VararyNode < std::smart_ptr < FormalRTESymbol >, std::smart_ptr < const FormalRTESymbol >, FormalRTESymbolAlphabet > { public: void Accept ( void * userData, const FormalRTEElementVisitor & visitor ) const { visitor.Visit ( userData, * this ); @@ -29,11 +17,6 @@ public: explicit FormalRTESymbolAlphabet ( alphabet::RankedSymbol symbol ); - FormalRTESymbolAlphabet ( const FormalRTESymbolAlphabet & other ); - FormalRTESymbolAlphabet ( FormalRTESymbolAlphabet && other ) noexcept; - FormalRTESymbolAlphabet & operator =( const FormalRTESymbolAlphabet & other ); - FormalRTESymbolAlphabet & operator =( FormalRTESymbolAlphabet && other ) noexcept; - /** * @copydoc FormalRTEElement::clone() const */ @@ -54,10 +37,16 @@ public: */ virtual void computeMinimalAlphabet ( std::set < alphabet::RankedSymbol > & alphabetF, std::set < alphabet::RankedSymbol > & alphabetK ) const; + /** + * @copydoc FormalRTEElement::checkAlphabet() + */ + virtual bool checkAlphabet ( const std::set < alphabet::RankedSymbol > & alphabetF, const std::set < alphabet::RankedSymbol > & alphabetK ) const; + const std::vector < std::smart_ptr < const FormalRTESymbol > > & getElements ( ) const; - std::vector < std::smart_ptr < FormalRTESymbol > > & getElements ( ); + const std::vector < std::smart_ptr < FormalRTESymbol > > & getElements ( ); void appendElement ( const FormalRTESymbol & element ); + void appendElement ( FormalRTESymbol && element ); virtual int compare ( const FormalRTESymbolAlphabet & ) const; diff --git a/alib2data/src/rte/formal/FormalRTESymbolSubst.cpp b/alib2data/src/rte/formal/FormalRTESymbolSubst.cpp index 44ee762ce3d237faf41170d9bd658e5b169512f0..57fb4d66d1b2c77530858ba59029fc364d0191c6 100644 --- a/alib2data/src/rte/formal/FormalRTESymbolSubst.cpp +++ b/alib2data/src/rte/formal/FormalRTESymbolSubst.cpp @@ -7,31 +7,6 @@ namespace rte { -FormalRTESymbolSubst::FormalRTESymbolSubst ( const FormalRTESymbolSubst & other ) : FormalRTESymbol ( other.symbol ) { -} - -FormalRTESymbolSubst::FormalRTESymbolSubst ( FormalRTESymbolSubst && other ) noexcept : FormalRTESymbol ( other.symbol ) { - this->attachRTE ( NULL ); -} - -FormalRTESymbolSubst & FormalRTESymbolSubst::operator =( const FormalRTESymbolSubst & other ) { - if ( this == & other ) - return * this; - - * this = FormalRTESymbolSubst ( other ); - - return * this; -} - -FormalRTESymbolSubst & FormalRTESymbolSubst::operator =( FormalRTESymbolSubst && other ) noexcept { - std::swap ( this->symbol, other.symbol ); - std::swap ( this->parentRTE, other.parentRTE ); - - this->attachRTE ( other.parentRTE ); - - return * this; -} - FormalRTESymbolSubst::FormalRTESymbolSubst ( alphabet::RankedSymbol symbol ) : FormalRTESymbol ( symbol ) { } @@ -57,21 +32,14 @@ bool FormalRTESymbolSubst::testSymbol ( const alphabet::RankedSymbol & symbol ) return symbol == this->symbol; } -bool FormalRTESymbolSubst::attachRTE ( const FormalRTE * regexp ) { - if ( this->parentRTE == regexp ) return true; - - this->parentRTE = regexp; - - if ( regexp == NULL ) return true; - - /* must not be in F, and must be in K */ - return this->parentRTE->getAlphabet ( ).find ( this->symbol ) == this->parentRTE->getAlphabet ( ).end ( ) || this->parentRTE->getConstantAlphabet ( ).find ( this->symbol ) != this->parentRTE->getConstantAlphabet ( ).end ( ); -} - void FormalRTESymbolSubst::computeMinimalAlphabet ( std::set < alphabet::RankedSymbol > & /* alphabetF */, std::set < alphabet::RankedSymbol > & alphabetK ) const { alphabetK.insert ( this->symbol ); } +bool FormalRTESymbolSubst::checkAlphabet ( const std::set < alphabet::RankedSymbol > & /* alphabetF */, const std::set < alphabet::RankedSymbol > & alphabetK ) const { + return alphabetK.count ( getSymbol ( ) ) > 0; +} + FormalRTESymbolSubst::operator std::string ( ) const { std::stringstream ss; ss << * this; diff --git a/alib2data/src/rte/formal/FormalRTESymbolSubst.h b/alib2data/src/rte/formal/FormalRTESymbolSubst.h index 6961e19b05bba0ca8d6a07683c954441c006d9a0..acbd2d21b6826fe915065a6a0a4be65bacf93f8b 100644 --- a/alib2data/src/rte/formal/FormalRTESymbolSubst.h +++ b/alib2data/src/rte/formal/FormalRTESymbolSubst.h @@ -9,13 +9,7 @@ namespace rte { /** * Represents constant symbol (element of alphabet K) in the regular expression. Contains name of the symbol. */ -class FormalRTESymbolSubst : public FormalRTESymbol { -protected: - /** - * @copydoc FormalRTESymbol::attachRTE() - */ - virtual bool attachRTE ( const FormalRTE * regexp ); - +class FormalRTESymbolSubst : public FormalRTESymbol, public std::NullaryNode < FormalRTESymbolSubst > { public: void Accept ( void * userData, const FormalRTEElementVisitor & visitor ) const { visitor.Visit ( userData, * this ); @@ -23,11 +17,6 @@ public: explicit FormalRTESymbolSubst ( alphabet::RankedSymbol symbol ); - FormalRTESymbolSubst ( const FormalRTESymbolSubst & other ); - FormalRTESymbolSubst ( FormalRTESymbolSubst && other ) noexcept; - FormalRTESymbolSubst & operator =( const FormalRTESymbolSubst & other ); - FormalRTESymbolSubst & operator =( FormalRTESymbolSubst && other ) noexcept; - /** * @copydoc FormalRTEElement::clone() const */ @@ -48,6 +37,11 @@ public: */ virtual void computeMinimalAlphabet ( std::set < alphabet::RankedSymbol > & alphabetF, std::set < alphabet::RankedSymbol > & alphabetK ) const; + /** + * @copydoc FormalRTEElement::checkAlphabet() + */ + virtual bool checkAlphabet ( const std::set < alphabet::RankedSymbol > & alphabetF, const std::set < alphabet::RankedSymbol > & alphabetK ) const; + virtual int compare ( const FormalRTESymbolSubst & ) const; virtual int compare ( const FormalRTEElement & other ) const {