diff --git a/adeterminize/makefile b/adeterminize/makefile index ae6e677504304d95f4d12e4797185a659bdfd6f4..973abf7a9db7dba571c0606356a4695017fb10c7 100644 --- a/adeterminize/makefile +++ b/adeterminize/makefile @@ -1,7 +1,7 @@ CC=g++ EXECUTABLE=adeterminize -CCFLAGS= -std=c++11 -O2 -c -Wall -I../alib/src -I/usr/include/libxml2/ -LDFLAGS= -L../alib/lib -lxml2 -lalib -Wl,-rpath,. +CCFLAGS= -std=c++11 -O2 -c -Wall -I../alib2/src -I/usr/include/libxml2/ +LDFLAGS= -L../alib/lib2 -lxml2 -lalib2 -Wl,-rpath,. SOURCES=$(shell find src/ -name *cpp) OBJECTS=$(patsubst src/%.cpp, obj/%.o, $(SOURCES)) diff --git a/alib2/src/regexp/Alternation.cpp b/alib2/src/regexp/Alternation.cpp index 9b3bd1e8214ff28a5b3c2e179f8a9ce975290d27..8745b14392a5194ddb65bcb8efa0695c3843044e 100644 --- a/alib2/src/regexp/Alternation.cpp +++ b/alib2/src/regexp/Alternation.cpp @@ -33,7 +33,7 @@ Alternation& Alternation::operator=(const Alternation& other) { return *this; } -Alternation& Alternation::operator=(Alternation&& other) { +Alternation& Alternation::operator=(Alternation&& other) noexcept { std::swap(this->elements, other.elements); return *this; diff --git a/alib2/src/regexp/Alternation.h b/alib2/src/regexp/Alternation.h index 098e601f8461092a9dbd5967c1cc048db5507964..fbddb2b93c24d72511c3fa014d62276a9a70a814 100644 --- a/alib2/src/regexp/Alternation.h +++ b/alib2/src/regexp/Alternation.h @@ -25,7 +25,7 @@ public: Alternation(const Alternation& other); Alternation(Alternation&& other) noexcept; Alternation& operator =(const Alternation& other); - Alternation& operator =(Alternation&& other); + Alternation& operator =(Alternation&& other) noexcept; ~Alternation() noexcept; /** diff --git a/alib2/src/regexp/Concatenation.cpp b/alib2/src/regexp/Concatenation.cpp index a7f4138b284be6950c403a39c2c1d2a1a1d9c875..dcc3aa767e8566cd3fe9dd899f404a586ba25b73 100644 --- a/alib2/src/regexp/Concatenation.cpp +++ b/alib2/src/regexp/Concatenation.cpp @@ -18,24 +18,27 @@ Concatenation::Concatenation(const Concatenation& other) { } } -Concatenation& Concatenation::operator =(const Concatenation& other) { +Concatenation::Concatenation(Concatenation&& other) noexcept : elements(std::move(other.elements)) { + other.elements.clear(); +} + +Concatenation& Concatenation::operator=(const Concatenation& other) { if(this == &other) { return *this; } - for (auto element : elements) { - delete element; - } - elements.clear(); - - for (const auto& element : other.elements) { - elements.push_back(element->clone()); - } + *this = Concatenation(other); + + return *this; +} +Concatenation& Concatenation::operator=(Concatenation&& other) noexcept { + std::swap(this->elements, other.elements); + return *this; } -Concatenation::~Concatenation() { +Concatenation::~Concatenation() noexcept { for (auto element : elements) { delete element; } diff --git a/alib2/src/regexp/Concatenation.h b/alib2/src/regexp/Concatenation.h index 3d52b41ef85bf6f49e1322e08391957eb148a8c2..be52c02b352b0d8df0b7b636bc2b05d89899d784 100644 --- a/alib2/src/regexp/Concatenation.h +++ b/alib2/src/regexp/Concatenation.h @@ -23,8 +23,10 @@ private: public: Concatenation(); Concatenation(const Concatenation& other); + Concatenation(Concatenation&& other) noexcept; Concatenation& operator =(const Concatenation& other); - ~Concatenation(); + Concatenation& operator =(Concatenation&& other) noexcept; + ~Concatenation() noexcept; /** * @return list of operands diff --git a/alib2/src/regexp/Iteration.cpp b/alib2/src/regexp/Iteration.cpp index 436b3eaca33d03d6d47b9471ca4f4556b5f437ba..12bfdeea90844b8f707cbd520bb76ea5752d80ee 100644 --- a/alib2/src/regexp/Iteration.cpp +++ b/alib2/src/regexp/Iteration.cpp @@ -23,25 +23,27 @@ Iteration::Iteration(const Iteration& other) { } +Iteration::Iteration(Iteration&& other) noexcept : element(other.element) { + other.element = NULL; +} + Iteration& Iteration::operator=(const Iteration& other) { if (this == &other) { return *this; } - if (element != NULL) { - delete element; - } + *this = Iteration(other); - if (other.element != NULL) { - element = other.element->clone(); - } else { - element = NULL; - } + return *this; +} + +Iteration& Iteration::operator=(Iteration&& other) noexcept { + std::swap(this->element, other.element); return *this; } -regexp::Iteration::~Iteration() { +regexp::Iteration::~Iteration() noexcept { if (element != NULL) { delete element; } diff --git a/alib2/src/regexp/Iteration.h b/alib2/src/regexp/Iteration.h index 09617598a836fb07b8975cb101ec7479c73ccfd8..90d270a3a934d3db0d665e1978b0132a26c484f0 100644 --- a/alib2/src/regexp/Iteration.h +++ b/alib2/src/regexp/Iteration.h @@ -23,8 +23,10 @@ private: public: Iteration(); Iteration(const Iteration& other); + Iteration(Iteration&& other) noexcept; Iteration& operator =(const Iteration& other); - ~Iteration(); + Iteration& operator =(Iteration&& other) noexcept; + ~Iteration() noexcept; /** * @return element to iterate diff --git a/alib2/src/regexp/RegExp.cpp b/alib2/src/regexp/RegExp.cpp index cfa2967a7726d91fdcb24f0920ceb667edf97657..6c190100db4bdfd98d866c6d7c0db038cc1b0b4e 100644 --- a/alib2/src/regexp/RegExp.cpp +++ b/alib2/src/regexp/RegExp.cpp @@ -6,55 +6,50 @@ */ #include "RegExp.h" +#include "../AlibException.h" #include <iostream> namespace regexp { RegExp::RegExp() { - regExp = NULL; + this->regExp = new RegExpEmpty(); } -RegExp::RegExp(const RegExp& other) { - if (other.regExp != NULL) { - regExp = other.regExp->clone(); - } else { - regExp = NULL; +RegExp::RegExp(const RegExpElement* regExp) { + if (regExp == NULL) { + throw alib::AlibException(); } + + this->regExp = regExp->clone(); } -RegExp::RegExp(const RegExpElement* regExp) { - if (regExp != NULL) { - this->regExp = regExp->clone(); - } else { - this->regExp = NULL; - } +RegExp::RegExp(const RegExp& other) : regExp(other.regExp->clone()) { + } -RegExp& RegExp::operator =(const RegExp& other) { +RegExp::RegExp(RegExp&& other) noexcept : regExp(other.regExp) { + other.regExp = NULL; +} + +RegExp& RegExp::operator=(const RegExp& other) { if (this == &other) { return *this; } - if (regExp != NULL) { - delete regExp; - } - - if (other.regExp != NULL) { - regExp = other.regExp->clone(); - } else { - regExp = NULL; - } + *this = RegExp(other); return *this; } -RegExp::~RegExp() { - if (regExp != NULL) { - delete regExp; - } +RegExp& RegExp::operator=(RegExp&& other) noexcept { + std::swap(this->regExp, other.regExp); - regExp = NULL; + return *this; +} + +RegExp::~RegExp() noexcept { + delete regExp; } RegExpElement* RegExp::getRegExp() { @@ -72,8 +67,7 @@ void RegExp::setRegExp(RegExpElement* regExp) { std::set<alphabet::Symbol> RegExp::getAlphabet() const { std::set<alphabet::Symbol> alphabet; - if(regExp) - regExp->getAlphabet( alphabet ); + regExp->getAlphabet( alphabet ); return alphabet; } @@ -83,14 +77,11 @@ bool RegExp::isEmpty() const { } bool RegExp::containsEmptyString() const { - if(regExp) - return regExp->containsEmptyString(); - - return false; + return regExp->containsEmptyString(); } -std::ostream& operator <<(std::ostream& out, const RegExp& regexp) { - out << "(RegExp " << *(regexp.regExp) << ")"; +std::ostream& operator <<(std::ostream& out, const RegExp& regExp) { + out << "(RegExp " << *(regExp.regExp) << ")"; return out; } diff --git a/alib2/src/regexp/RegExp.h b/alib2/src/regexp/RegExp.h index eac9004daf64ded3fc7316000e79bdf77d3f33df..7bb157b3f48372799c10879743b403b16a0feb90 100644 --- a/alib2/src/regexp/RegExp.h +++ b/alib2/src/regexp/RegExp.h @@ -34,8 +34,10 @@ public: * @param other RegExp to copy */ RegExp(const RegExp& other); + RegExp(RegExp&& other) noexcept; RegExp& operator =(const RegExp& other); - ~RegExp(); + RegExp& operator =(RegExp&& other) noexcept; + ~RegExp() noexcept; /** * @return Root node of the regular expression tree diff --git a/alib2/src/regexp/RegExpElement.cpp b/alib2/src/regexp/RegExpElement.cpp index dd880a8d0d261f56a8e0e2cfd6daaef1055078f3..91065141e6ce99123547ba18a82e5539021775b4 100644 --- a/alib2/src/regexp/RegExpElement.cpp +++ b/alib2/src/regexp/RegExpElement.cpp @@ -9,7 +9,7 @@ namespace regexp { -RegExpElement::~RegExpElement() { +RegExpElement::~RegExpElement() noexcept { } diff --git a/alib2/src/regexp/RegExpElement.h b/alib2/src/regexp/RegExpElement.h index 12db32db1b7f3dc2d06f2f183ec64917a8ef8c44..046a0294c1bd2f981074861b111dd6b116eb37cd 100644 --- a/alib2/src/regexp/RegExpElement.h +++ b/alib2/src/regexp/RegExpElement.h @@ -26,7 +26,7 @@ class RegExpEpsilon; */ class RegExpElement : virtual public std::elementBase<std::visitor<Alternation, Concatenation, Iteration, RegExpSymbol, RegExpEmpty, RegExpEpsilon> > { public: - virtual ~RegExpElement(); + virtual ~RegExpElement() noexcept; /** * Creates copy of the element. diff --git a/alib2/src/regexp/RegExpEmpty.cpp b/alib2/src/regexp/RegExpEmpty.cpp index 9c37ac53e795472b0ecfb4f884126b9e6c8dc9e3..b80ae39dad9e72f1f784dd44ad2a166007a27650 100644 --- a/alib2/src/regexp/RegExpEmpty.cpp +++ b/alib2/src/regexp/RegExpEmpty.cpp @@ -13,7 +13,7 @@ RegExpEmpty::RegExpEmpty() { } RegExpElement* RegExpEmpty::clone() const { - return new RegExpEmpty(); + return new RegExpEmpty(*this); } bool RegExpEmpty::operator<(const RegExpElement& other) const { diff --git a/alib2/src/regexp/RegExpEpsilon.cpp b/alib2/src/regexp/RegExpEpsilon.cpp index 0ed91e5d050f22cb114dab87f095a26718c57e79..364af6e7bfdeb3481448aa3c75dd821113efc7a2 100644 --- a/alib2/src/regexp/RegExpEpsilon.cpp +++ b/alib2/src/regexp/RegExpEpsilon.cpp @@ -13,7 +13,7 @@ RegExpEpsilon::RegExpEpsilon() { } RegExpElement* RegExpEpsilon::clone() const { - return new RegExpEpsilon(); + return new RegExpEpsilon(*this); } bool RegExpEpsilon::operator<(const RegExpElement& other) const { diff --git a/alib2/src/regexp/RegExpSymbol.cpp b/alib2/src/regexp/RegExpSymbol.cpp index bcc30faf6fef848b71e346ee13991d8d92fd9fba..91fa6be5c5e1d2d2bc92cbfbaa1f83b90abba66d 100644 --- a/alib2/src/regexp/RegExpSymbol.cpp +++ b/alib2/src/regexp/RegExpSymbol.cpp @@ -9,16 +9,16 @@ namespace regexp { -RegExpSymbol::RegExpSymbol() : - symbol("") { -} - RegExpSymbol::RegExpSymbol(const std::string& symbol) : symbol(symbol) { } +RegExpSymbol::RegExpSymbol(std::string&& symbol) : + symbol(move(symbol)) { +} + RegExpElement* RegExpSymbol::clone() const { - return new RegExpSymbol(this->symbol); + return new RegExpSymbol(*this); } bool RegExpSymbol::operator<(const RegExpElement& other) const { diff --git a/alib2/src/regexp/RegExpSymbol.h b/alib2/src/regexp/RegExpSymbol.h index 8296bce29f595b67341ad9301e4c8de37424c80c..11faa21d97bfdf48194f6ee8cc5b31ccf639ce64 100644 --- a/alib2/src/regexp/RegExpSymbol.h +++ b/alib2/src/regexp/RegExpSymbol.h @@ -20,8 +20,8 @@ namespace regexp { class RegExpSymbol : public RegExpElement, public std::element<RegExpSymbol, RegExpElement::visitor_type> { std::string symbol; public: - RegExpSymbol(); RegExpSymbol(const std::string& symbol); + RegExpSymbol(std::string&& symbol); /** * @copydoc RegExpElement::clone() const