diff --git a/alib/src/regexp/Alternation.cpp b/alib/src/regexp/Alternation.cpp index 23e98e68b9f82c2b5403d55307bf6c1e167da1a3..721641b07e4d1de737e4ee9cc4b2bfe50e8bff43 100644 --- a/alib/src/regexp/Alternation.cpp +++ b/alib/src/regexp/Alternation.cpp @@ -9,7 +9,47 @@ namespace regexp { +Alternation::Alternation() { +} + +Alternation::Alternation(const Alternation& other) { + for (auto element : other.first) { + first.push_back(element->clone()); + } + for (auto element : other.second) { + second.push_back(element->clone()); + } +} + +Alternation& Alternation::operator =(const Alternation& other) { + for (auto element : first) { + delete element; + } + first.clear(); + + for (auto element : second) { + delete element; + } + first.clear(); + + for (auto element : other.first) { + first.push_back(element->clone()); + } + for (auto element : other.second) { + second.push_back(element->clone()); + } +} + Alternation::~Alternation() { + for (auto element : first) { + delete element; + } + first.clear(); + + for (auto element : second) { + delete element; + } + first.clear(); } list<RegExpElement*>& Alternation::getFirst() { @@ -20,5 +60,19 @@ list<RegExpElement*>& Alternation::getSecond() { return second; } +RegExpElement* Alternation::clone() { + Alternation* toReturn = new Alternation(); + + for (auto element : first) { + toReturn->getFirst().push_back(element->clone()); + } + + for (auto element : second) { + toReturn->getSecond().push_back(element->clone()); + } + + return toReturn; +} + } /* namespace regexp */ diff --git a/alib/src/regexp/Alternation.h b/alib/src/regexp/Alternation.h index 6e1cdf5ed400d132ad03903691916b078091e574..8ea6abee3f1625bfd965f49cc8a60d2d9b1d6e92 100644 --- a/alib/src/regexp/Alternation.h +++ b/alib/src/regexp/Alternation.h @@ -20,9 +20,15 @@ private: list<RegExpElement*> first; list<RegExpElement*> second; public: + Alternation(); + Alternation(const Alternation& other); + Alternation& operator = (const Alternation& other); ~Alternation(); + list<RegExpElement*>& getFirst(); list<RegExpElement*>& getSecond(); + + RegExpElement* clone(); }; } /* namespace regexp */ diff --git a/alib/src/regexp/Iteration.cpp b/alib/src/regexp/Iteration.cpp index 6e95c17edfa892191821cdaeefe61df382d4453a..f43c577dc5463ec6fc28af48af2db75e0b3615b6 100644 --- a/alib/src/regexp/Iteration.cpp +++ b/alib/src/regexp/Iteration.cpp @@ -8,15 +8,45 @@ #include "Iteration.h" namespace regexp { + +Iteration::Iteration() { +} + +Iteration::Iteration(const Iteration& other) { + for (auto element : other.elements) { + elements.push_back(element->clone()); + } +} + +Iteration& Iteration::operator=(const Iteration& other) { + for (auto element : elements) { + delete element; + } + elements.clear(); + + for (auto element : other.elements) { + elements.push_back(element->clone()); + } +} + regexp::Iteration::~Iteration() { for (auto element : elements) { delete element; } + elements.clear(); } list<RegExpElement*>& regexp::Iteration::getElements() { return elements; } +RegExpElement* Iteration::clone() { + Iteration* toReturn = new Iteration(); + for (auto element : elements) { + toReturn->getElements().push_back(element->clone()); + } + return toReturn; +} + } /* namespace regexp */ diff --git a/alib/src/regexp/Iteration.h b/alib/src/regexp/Iteration.h index 0bec4d49f5bf64a5c85c621115c11613ef1e6307..d07a5dad07c3e69ec41861449c8608698af71cc1 100644 --- a/alib/src/regexp/Iteration.h +++ b/alib/src/regexp/Iteration.h @@ -19,8 +19,12 @@ class Iteration : public RegExpElement { private: list<RegExpElement*> elements; public: + Iteration(); + Iteration(const Iteration& other); + Iteration& operator = (const Iteration& other); ~Iteration(); list<RegExpElement*>& getElements(); + RegExpElement* clone(); }; } /* namespace regexp */ diff --git a/alib/src/regexp/RegExp.cpp b/alib/src/regexp/RegExp.cpp index 0151ffd4f34feb97b6539f597757b9dd78363244..cdcf4ae055fd812b6e8d64f661371e98df781b5a 100644 --- a/alib/src/regexp/RegExp.cpp +++ b/alib/src/regexp/RegExp.cpp @@ -8,14 +8,16 @@ #include "RegExp.h" #include "RegExpPrinter.h" +#include <iostream> + namespace regexp { RegExp::RegExp() { } -RegExp::~RegExp() { - for(auto element : regexp) { - delete element; +RegExp::RegExp(const RegExp& other) { + for (auto element : other.regexp) { + regexp.push_back(element->clone()); } } @@ -23,6 +25,24 @@ RegExp::RegExp(const list<RegExpElement*>& regexp) : regexp(regexp) { } +RegExp& RegExp::operator =(const RegExp& other) { + for (auto element : regexp) { + delete element; + } + regexp.clear(); + + for (auto element : other.regexp) { + regexp.push_back(element->clone()); + } +} + +RegExp::~RegExp() { + for (auto element : regexp) { + delete element; + } + regexp.clear(); +} + list<RegExpElement*>& RegExp::getRegExp() { return regexp; } diff --git a/alib/src/regexp/RegExp.h b/alib/src/regexp/RegExp.h index 35a2f77235662ad77260143c8a8ea51c50fad3b2..94e0c433200dae48351d6469e66f94e9e9c8da47 100644 --- a/alib/src/regexp/RegExp.h +++ b/alib/src/regexp/RegExp.h @@ -23,10 +23,17 @@ private: public: RegExp(); - ~RegExp(); RegExp(const list<RegExpElement*>& regexp) ; + + RegExp(const RegExp& other); + RegExp& operator = (const RegExp& other); + ~RegExp(); + list<RegExpElement*>& getRegExp(); + + + void toXML(ostream& out); }; diff --git a/alib/src/regexp/RegExpElement.cpp b/alib/src/regexp/RegExpElement.cpp index eacf72d353aa19b456bb024459403c0fbf66df0e..d7231b3c07966d117afbd903ef011838569cb75b 100644 --- a/alib/src/regexp/RegExpElement.cpp +++ b/alib/src/regexp/RegExpElement.cpp @@ -9,7 +9,8 @@ namespace regexp { +RegExpElement::~RegExpElement() { +} + } /* namespace regexp */ -regexp::RegExpElement::~RegExpElement() { -} diff --git a/alib/src/regexp/RegExpElement.h b/alib/src/regexp/RegExpElement.h index b2ed1df40673958fad59731a298f0aac20b97bce..225f3ef48a2d19f9f3eddb68d9bc265b39bd6deb 100644 --- a/alib/src/regexp/RegExpElement.h +++ b/alib/src/regexp/RegExpElement.h @@ -15,7 +15,7 @@ using namespace std; class RegExpElement { public: virtual ~RegExpElement(); - + virtual RegExpElement* clone() = 0; }; } /* namespace regexp */ diff --git a/alib/src/regexp/RegExpSymbol.cpp b/alib/src/regexp/RegExpSymbol.cpp index 85c6f159ddab19a7077fc56adf464e58b8b2db24..ed17cfd453c0c63210be297192163b3a76acc97f 100644 --- a/alib/src/regexp/RegExpSymbol.cpp +++ b/alib/src/regexp/RegExpSymbol.cpp @@ -9,12 +9,17 @@ namespace regexp { -} /* namespace regexp */ - -regexp::RegExpSymbol::RegExpSymbol() : +RegExpSymbol::RegExpSymbol() : Symbol("") { } -regexp::RegExpSymbol::RegExpSymbol(const string& symbol) : +RegExpSymbol::RegExpSymbol(const string& symbol) : Symbol(symbol) { } + +RegExpElement* RegExpSymbol::clone() { + return new RegExpSymbol(this->symbol); +} + +} /* namespace regexp */ + diff --git a/alib/src/regexp/RegExpSymbol.h b/alib/src/regexp/RegExpSymbol.h index c2bac3c2519a93b38be13666b116420a1fa8b655..b07319284f31a41862ab24a5d3c522d5b736fce3 100644 --- a/alib/src/regexp/RegExpSymbol.h +++ b/alib/src/regexp/RegExpSymbol.h @@ -21,7 +21,7 @@ class RegExpSymbol: public RegExpElement, public Symbol { public: RegExpSymbol(); RegExpSymbol(const string& symbol); - + RegExpElement* clone(); }; } /* namespace regexp */