From 0201989a80add4bafefff646b1f653f3eb58d1c8 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Sun, 4 May 2014 16:27:08 +0200 Subject: [PATCH] mor thorough work with parentRegExp pointer --- alib2/src/regexp/Alternation.cpp | 3 +++ alib2/src/regexp/Concatenation.cpp | 2 ++ alib2/src/regexp/Iteration.cpp | 4 +++- alib2/src/regexp/RegExpEmpty.cpp | 9 +++++++++ alib2/src/regexp/RegExpEmpty.h | 3 +++ alib2/src/regexp/RegExpEpsilon.cpp | 9 +++++++++ alib2/src/regexp/RegExpEpsilon.h | 3 +++ alib2/src/regexp/RegExpSymbol.cpp | 10 ++++++++++ alib2/src/regexp/RegExpSymbol.h | 3 +++ 9 files changed, 45 insertions(+), 1 deletion(-) diff --git a/alib2/src/regexp/Alternation.cpp b/alib2/src/regexp/Alternation.cpp index 305830de34..b7de7ca6d7 100644 --- a/alib2/src/regexp/Alternation.cpp +++ b/alib2/src/regexp/Alternation.cpp @@ -29,6 +29,7 @@ Alternation::Alternation(const Alternation& other) { Alternation::Alternation(Alternation&& other) noexcept : elements(std::move(other.elements)) { other.elements.clear(); + this->attachRegExp(NULL); } Alternation& Alternation::operator=(const Alternation& other) { @@ -132,6 +133,8 @@ bool Alternation::testSymbol( const alphabet::Symbol & symbol ) const { } bool Alternation::attachRegExp(const RegExp * regexp ) { + if(this->parentRegExp == regexp) return true; + this->parentRegExp = regexp; for(const auto& child : this->elements) if(!child->attachRegExp(regexp)) return false; diff --git a/alib2/src/regexp/Concatenation.cpp b/alib2/src/regexp/Concatenation.cpp index 38da1d7e72..4faa19cd58 100644 --- a/alib2/src/regexp/Concatenation.cpp +++ b/alib2/src/regexp/Concatenation.cpp @@ -28,6 +28,7 @@ Concatenation::Concatenation(const Concatenation& other) { Concatenation::Concatenation(Concatenation&& other) noexcept : elements(std::move(other.elements)) { other.elements.clear(); + this->attachRegExp(NULL); } Concatenation& Concatenation::operator=(const Concatenation& other) { @@ -139,6 +140,7 @@ bool Concatenation::testSymbol( const alphabet::Symbol & symbol ) const { } bool Concatenation::attachRegExp(const RegExp * regexp ) { + if(this->parentRegExp == regexp) return true; this->parentRegExp = regexp; for(const auto& child : this->elements) if(!child->attachRegExp(regexp)) return false; diff --git a/alib2/src/regexp/Iteration.cpp b/alib2/src/regexp/Iteration.cpp index 622d606cf8..51c364c6e2 100644 --- a/alib2/src/regexp/Iteration.cpp +++ b/alib2/src/regexp/Iteration.cpp @@ -10,7 +10,7 @@ namespace regexp { -Iteration::Iteration(RegExpElement&& element) : element( NULL ){ +Iteration::Iteration(RegExpElement&& element) : element( NULL ) { this->setElement(std::move(element)); } @@ -25,6 +25,7 @@ Iteration::Iteration(const Iteration& other) : element(other.element->clone()) { Iteration::Iteration(Iteration&& other) noexcept : element(other.element) { other.element = nullptr; + this->attachRegExp(NULL); } Iteration& Iteration::operator=(const Iteration& other) { @@ -108,6 +109,7 @@ bool Iteration::testSymbol( const alphabet::Symbol & symbol ) const { } bool Iteration::attachRegExp(const RegExp * regexp ) { + if(this->parentRegExp == regexp) return true; this->parentRegExp = regexp; return this->element->attachRegExp(regexp); } diff --git a/alib2/src/regexp/RegExpEmpty.cpp b/alib2/src/regexp/RegExpEmpty.cpp index aac9838617..90fbf970ac 100644 --- a/alib2/src/regexp/RegExpEmpty.cpp +++ b/alib2/src/regexp/RegExpEmpty.cpp @@ -8,6 +8,14 @@ #include "RegExpEmpty.h" namespace regexp { + +RegExpEmpty::RegExpEmpty(const RegExpEmpty& other) { + +} + +RegExpEmpty::RegExpEmpty(RegExpEmpty&& other) { + this->attachRegExp(NULL); +} RegExpElement* RegExpEmpty::clone() const { return new RegExpEmpty(*this); @@ -47,6 +55,7 @@ bool RegExpEmpty::testSymbol( const alphabet::Symbol & ) const { } bool RegExpEmpty::attachRegExp(const RegExp * regexp ) { + if(this->parentRegExp == regexp) return true; this->parentRegExp = regexp; return true; } diff --git a/alib2/src/regexp/RegExpEmpty.h b/alib2/src/regexp/RegExpEmpty.h index 52ec086c15..1293b61c38 100644 --- a/alib2/src/regexp/RegExpEmpty.h +++ b/alib2/src/regexp/RegExpEmpty.h @@ -40,6 +40,9 @@ protected: virtual void computeMinimalAlphabet( std::set<alphabet::Symbol>& alphabet ) const; public: + RegExpEmpty(const RegExpEmpty& other); + RegExpEmpty(RegExpEmpty&& other); + virtual bool operator<(const RegExpElement&) const; virtual bool operator==(const RegExpElement&) const; virtual bool operator>(const RegExpElement&) const; diff --git a/alib2/src/regexp/RegExpEpsilon.cpp b/alib2/src/regexp/RegExpEpsilon.cpp index eed1754a8c..0984e2ec81 100644 --- a/alib2/src/regexp/RegExpEpsilon.cpp +++ b/alib2/src/regexp/RegExpEpsilon.cpp @@ -9,6 +9,14 @@ namespace regexp { +RegExpEpsilon::RegExpEpsilon(const RegExpEpsilon& other) { + +} + +RegExpEpsilon::RegExpEpsilon(RegExpEpsilon&& other) { + this->attachRegExp(NULL); +} + RegExpElement* RegExpEpsilon::clone() const { return new RegExpEpsilon(*this); } @@ -47,6 +55,7 @@ bool RegExpEpsilon::testSymbol( const alphabet::Symbol & ) const { } bool RegExpEpsilon::attachRegExp(const RegExp * regexp ) { + if(this->parentRegExp == regexp) return true; this->parentRegExp = regexp; return true; } diff --git a/alib2/src/regexp/RegExpEpsilon.h b/alib2/src/regexp/RegExpEpsilon.h index 585bab24b8..56c2a76cc0 100644 --- a/alib2/src/regexp/RegExpEpsilon.h +++ b/alib2/src/regexp/RegExpEpsilon.h @@ -40,6 +40,9 @@ protected: virtual void computeMinimalAlphabet( std::set<alphabet::Symbol>& alphabet ) const; public: + + RegExpEpsilon(const RegExpEpsilon& other); + RegExpEpsilon(RegExpEpsilon&& other); virtual bool operator<(const RegExpElement&) const; virtual bool operator==(const RegExpElement&) const; diff --git a/alib2/src/regexp/RegExpSymbol.cpp b/alib2/src/regexp/RegExpSymbol.cpp index c26c82b1a8..118340a101 100644 --- a/alib2/src/regexp/RegExpSymbol.cpp +++ b/alib2/src/regexp/RegExpSymbol.cpp @@ -8,6 +8,14 @@ #include "RegExpSymbol.h" namespace regexp { + +RegExpSymbol::RegExpSymbol(const RegExpSymbol& other) : alphabet::Symbol(other.symbol) { + +} + +RegExpSymbol::RegExpSymbol(RegExpSymbol&& other) : alphabet::Symbol(std::move(other.symbol)) { + this->attachRegExp(NULL); +} RegExpSymbol::RegExpSymbol(const std::string& symbol) : alphabet::Symbol(symbol) { @@ -72,7 +80,9 @@ bool RegExpSymbol::testSymbol( const alphabet::Symbol & symbol ) const { } bool RegExpSymbol::attachRegExp(const RegExp * regexp ) { + if(this->parentRegExp == regexp) return true; this->parentRegExp = regexp; + if(regexp == NULL) return true; return this->parentRegExp->getAlphabet().find(*this) != this->parentRegExp->getAlphabet().end(); } diff --git a/alib2/src/regexp/RegExpSymbol.h b/alib2/src/regexp/RegExpSymbol.h index 653e84675a..0fa85b0b19 100644 --- a/alib2/src/regexp/RegExpSymbol.h +++ b/alib2/src/regexp/RegExpSymbol.h @@ -44,6 +44,9 @@ public: RegExpSymbol(const std::string& symbol); RegExpSymbol(std::string&& symbol); + RegExpSymbol(const RegExpSymbol& other); + RegExpSymbol(RegExpSymbol&& other); + bool operator==(const alphabet::Symbol&) const; friend bool operator==(const alphabet::Symbol&, const RegExpSymbol&); -- GitLab