From 6357164d36e60f2da72b22cebaa216ed0aa3e512 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Tue, 20 May 2014 11:18:51 +0200
Subject: [PATCH] Wrapper of AutomatonBase*, cleanup

---
 alib2/makefile                                |  4 +-
 alib2/src/automaton/Automaton.cpp             | 58 ++++++++++-------
 alib2/src/automaton/Automaton.h               | 48 ++++++--------
 alib2/src/automaton/AutomatonBase.cpp         | 62 ++++++++++++++++++
 alib2/src/automaton/AutomatonBase.h           | 63 +++++++++++++++++++
 .../src/automaton/AutomatonFromXMLParser.cpp  | 10 +--
 alib2/src/automaton/AutomatonFromXMLParser.h  |  3 +-
 .../src/automaton/AutomatonToXMLComposer.cpp  | 10 +++
 alib2/src/automaton/AutomatonToXMLComposer.h  |  6 +-
 alib2/src/automaton/FSM/CompactNFA.cpp        | 10 ++-
 alib2/src/automaton/FSM/CompactNFA.h          | 10 ++-
 alib2/src/automaton/FSM/DFA.cpp               | 10 ++-
 alib2/src/automaton/FSM/DFA.h                 | 10 ++-
 alib2/src/automaton/FSM/EpsilonNFA.cpp        | 10 ++-
 alib2/src/automaton/FSM/EpsilonNFA.h          | 10 ++-
 alib2/src/automaton/FSM/ExtendedNFA.cpp       | 10 ++-
 alib2/src/automaton/FSM/ExtendedNFA.h         | 10 ++-
 alib2/src/automaton/FSM/NFA.cpp               | 10 ++-
 alib2/src/automaton/FSM/NFA.h                 | 10 ++-
 alib2/src/automaton/PDA/PDA.cpp               | 10 ++-
 alib2/src/automaton/PDA/PDA.h                 | 10 ++-
 alib2/src/automaton/TM/OneTapeDTM.cpp         | 10 ++-
 alib2/src/automaton/TM/OneTapeDTM.h           | 10 ++-
 alib2/src/automaton/UnknownAutomaton.cpp      | 10 ++-
 alib2/src/automaton/UnknownAutomaton.h        | 10 ++-
 alib2/src/automaton/common/States.cpp         |  4 --
 alib2/src/automaton/common/States.h           |  7 ---
 alib2/src/factory/AutomatonConvertor.cpp      |  8 +--
 alib2/src/factory/AutomatonConvertor.h        |  3 +-
 alib2/src/factory/AutomatonFactory.cpp        | 34 +++++++---
 alib2/src/factory/AutomatonFactory.h          | 38 +++++++++--
 alib2/src/regexp/RegExpElement.cpp            | 12 ++--
 alib2/src/regexp/RegExpEmpty.cpp              | 10 +--
 alib2/src/regexp/RegExpEpsilon.cpp            | 10 +--
 alib2/src/regexp/RegExpToStringComposer.cpp   |  4 +-
 alib2/src/regexp/RegExpToXMLComposer.cpp      |  4 +-
 alib2/src/std/variant.hpp                     | 12 ++--
 alib2/src/string/Epsilon.cpp                  |  6 +-
 alib2/test-src/automaton/AutomatonTest.cpp    |  4 +-
 39 files changed, 426 insertions(+), 154 deletions(-)
 create mode 100644 alib2/src/automaton/AutomatonBase.cpp
 create mode 100644 alib2/src/automaton/AutomatonBase.h

diff --git a/alib2/makefile b/alib2/makefile
index 4ddb917b0c..cc0515fe3e 100644
--- a/alib2/makefile
+++ b/alib2/makefile
@@ -1,9 +1,9 @@
 CC=g++
 LIBRARY=libalib2.so 
 TESTBIN=alib2test
-CCFLAGS= -std=c++11 -O2 -g -c -Wall -pedantic -fPIC -I/usr/include/libxml2/ 
+CCFLAGS= -std=c++11 -O2 -g -c -Wall -pedantic -Wextra -fPIC -I/usr/include/libxml2/ 
 LDFLAGS= -shared -lxml2
-TEST_CCFLAGS= -std=c++11 -O2 -g -c -Wall -pedantic -I../alib2/src -I/usr/include/libxml2/ 
+TEST_CCFLAGS= -std=c++11 -O2 -g -c -Wall -pedantic -Wextra -I../alib2/src -I/usr/include/libxml2/ 
 TEST_LDFLAGS= -L../alib2/lib -lxml2 -lalib2 -lcppunit -Wl,-rpath,.
 
 SOURCES=$(shell find src/ -name *cpp)
diff --git a/alib2/src/automaton/Automaton.cpp b/alib2/src/automaton/Automaton.cpp
index cf7fe0bf13..4e762c39a7 100644
--- a/alib2/src/automaton/Automaton.cpp
+++ b/alib2/src/automaton/Automaton.cpp
@@ -9,52 +9,68 @@
 
 namespace automaton {
 
-Automaton::~Automaton() {
+Automaton::Automaton(const AutomatonBase& automaton) : automaton(automaton.clone()) {
 
 }
 
-bool Automaton::operator!=(const Automaton& other) const {
-	return !(*this == other);
+Automaton::Automaton(AutomatonBase&& automaton) : automaton(std::move(automaton).plunder()) {
+
+}
+
+Automaton::Automaton(const Automaton& other) : automaton(other.getAutomaton().clone()) {
+
 }
 
-bool Automaton::operator==(const UnknownAutomaton& other) const {
-	return false;
+Automaton::Automaton(Automaton&& other) noexcept : automaton(std::move(other.getAutomaton()).plunder()) {
+	other.automaton = NULL;
 }
 
-bool Automaton::operator==(const DFA& other) const {
-	return false;
+Automaton& Automaton::operator=(const Automaton& other) {
+	if(this == &other) return *this;
+
+	delete automaton;
+	automaton = other.getAutomaton().clone();
+
+	return *this;
 }
 
-bool Automaton::operator==(const NFA& other) const {
-	return false;
+Automaton& Automaton::operator=(Automaton&& other) noexcept {
+	std::swap(this->automaton, other.automaton);
+	return *this;
 }
 
-bool Automaton::operator==(const EpsilonNFA& other) const{
-	return false;
+Automaton::~Automaton() {
+	delete automaton;
 }
 
-bool Automaton::operator==(const CompactNFA& other) const{
-	return false;
+const AutomatonBase& Automaton::getAutomaton() const {
+	return *automaton;
 }
 
-bool Automaton::operator==(const ExtendedNFA& other) const {
-	return false;
+AutomatonBase& Automaton::getAutomaton() {
+	return *automaton;
 }
 
-bool Automaton::operator==(const PDA& other) const {
-	return false;
+void Automaton::setAutomaton(const AutomatonBase& automaton) {
+	delete this->automaton;
+	this->automaton = automaton.clone();
 }
 
-bool Automaton::operator==(const OneTapeDTM& other) const {
-	return false;
+void Automaton::setAutomaton(AutomatonBase&& automaton) {
+	delete this->automaton;
+	this->automaton = std::move(automaton).plunder();
+}
+
+bool Automaton::operator!=(const Automaton& other) const {
+	return !(*this == other);
 }
 
 bool Automaton::operator==(const Automaton& other) const {
-	return false;
+	return this->getAutomaton() == other.getAutomaton();
 }
 
 std::ostream& operator<<(std::ostream& os, const Automaton& automaton) {
-	automaton >> os;
+	os << automaton.getAutomaton();
 	return os;
 }
 
diff --git a/alib2/src/automaton/Automaton.h b/alib2/src/automaton/Automaton.h
index 13a1acf614..cdcfd09db4 100644
--- a/alib2/src/automaton/Automaton.h
+++ b/alib2/src/automaton/Automaton.h
@@ -9,48 +9,36 @@
 #define AUTOMATON_H_
 
 #include "../std/visitor.hpp"
+#include "AutomatonBase.h"
 
 namespace automaton {
 
-class UnknownAutomaton;
-class DFA;
-class NFA;
-class EpsilonNFA;
-class CompactNFA;
-class ExtendedNFA;
-class PDA;
-class OneTapeDTM;
-
 /**
- * Abstract base class for all automata.
+ * Wrapper around automata.
  */
-class Automaton : virtual public std::elementBase<std::visitor<UnknownAutomaton, DFA, NFA, EpsilonNFA, CompactNFA, ExtendedNFA, PDA, OneTapeDTM> > {
+class Automaton : public std::element<Automaton, std::visitor<Automaton> > {
+protected:
+	AutomatonBase* automaton;
 public:
+	explicit Automaton(const AutomatonBase& automaton);
+	explicit Automaton(AutomatonBase&& automaton);
+	Automaton(const Automaton& other);
+	Automaton(Automaton&&) noexcept;
+	Automaton& operator=(const Automaton& other);
+	Automaton& operator=(Automaton&& other) noexcept;
 	virtual ~Automaton() noexcept;
-	
-	virtual bool operator!=(const Automaton& other) const;
-
-	virtual bool operator==(const UnknownAutomaton& other) const;
-
-	virtual bool operator==(const DFA& other) const;
-
-	virtual bool operator==(const NFA& other) const;
 
-	virtual bool operator==(const EpsilonNFA& other) const;
+	const AutomatonBase& getAutomaton() const;
+	AutomatonBase& getAutomaton();
 
-	virtual bool operator==(const CompactNFA& other) const;
-
-	virtual bool operator==(const ExtendedNFA& other) const;
-
-	virtual bool operator==(const PDA& other) const;
-
-	virtual bool operator==(const OneTapeDTM& other) const;
+	void setAutomaton(const AutomatonBase& automaton);
+	void setAutomaton(AutomatonBase&& automaton);
+	
+	bool operator!=(const Automaton& other) const;
 
-	virtual bool operator==(const Automaton& other) const = 0;
+	bool operator==(const Automaton& other) const;
 
 	friend std::ostream& operator<<(std::ostream& os, const Automaton& automaton);
-
-	virtual void operator>>(std::ostream&) const = 0;
 };
 
 } /* namespace automaton */
diff --git a/alib2/src/automaton/AutomatonBase.cpp b/alib2/src/automaton/AutomatonBase.cpp
new file mode 100644
index 0000000000..0c73ea6fbb
--- /dev/null
+++ b/alib2/src/automaton/AutomatonBase.cpp
@@ -0,0 +1,62 @@
+/*
+ * AutomatonBase.cpp
+ *
+ *  Created on: Apr 16, 2013
+ *      Author: Jan Travnicek
+ */
+
+#include "AutomatonBase.h"
+
+namespace automaton {
+
+AutomatonBase::~AutomatonBase() {
+
+}
+
+bool AutomatonBase::operator!=(const AutomatonBase& other) const {
+	return !(*this == other);
+}
+
+bool AutomatonBase::operator==(const UnknownAutomaton&) const {
+	return false;
+}
+
+bool AutomatonBase::operator==(const DFA&) const {
+	return false;
+}
+
+bool AutomatonBase::operator==(const NFA&) const {
+	return false;
+}
+
+bool AutomatonBase::operator==(const EpsilonNFA&) const{
+	return false;
+}
+
+bool AutomatonBase::operator==(const CompactNFA&) const{
+	return false;
+}
+
+bool AutomatonBase::operator==(const ExtendedNFA&) const {
+	return false;
+}
+
+bool AutomatonBase::operator==(const PDA&) const {
+	return false;
+}
+
+bool AutomatonBase::operator==(const OneTapeDTM&) const {
+	return false;
+}
+
+bool AutomatonBase::operator==(const AutomatonBase&) const {
+	return false;
+}
+
+std::ostream& operator<<(std::ostream& os, const AutomatonBase& automaton) {
+	automaton >> os;
+	return os;
+}
+
+} /* namespace automaton */
+
diff --git a/alib2/src/automaton/AutomatonBase.h b/alib2/src/automaton/AutomatonBase.h
new file mode 100644
index 0000000000..aac5328d60
--- /dev/null
+++ b/alib2/src/automaton/AutomatonBase.h
@@ -0,0 +1,63 @@
+/*
+ * AutomatonBase.h
+ *
+ *  Created on: Apr 10, 2013
+ *      Author: Jan Travnicek
+ */
+
+#ifndef AUTOMATON_BASE_H_
+#define AUTOMATON_BASE_H_
+
+#include "../std/visitor.hpp"
+
+namespace automaton {
+
+class UnknownAutomaton;
+class DFA;
+class NFA;
+class EpsilonNFA;
+class CompactNFA;
+class ExtendedNFA;
+class PDA;
+class OneTapeDTM;
+
+/**
+ * Abstract base class for all automata.
+ */
+class AutomatonBase : virtual public std::elementBase<std::visitor<UnknownAutomaton, DFA, NFA, EpsilonNFA, CompactNFA, ExtendedNFA, PDA, OneTapeDTM> > {
+public:
+	virtual AutomatonBase* clone() const = 0;
+
+	virtual AutomatonBase* plunder() && = 0;
+
+	virtual ~AutomatonBase() noexcept;
+
+	virtual bool operator!=(const AutomatonBase& other) const;
+
+	virtual bool operator==(const UnknownAutomaton& other) const;
+
+	virtual bool operator==(const DFA& other) const;
+
+	virtual bool operator==(const NFA& other) const;
+
+	virtual bool operator==(const EpsilonNFA& other) const;
+
+	virtual bool operator==(const CompactNFA& other) const;
+
+	virtual bool operator==(const ExtendedNFA& other) const;
+
+	virtual bool operator==(const PDA& other) const;
+
+	virtual bool operator==(const OneTapeDTM& other) const;
+
+	virtual bool operator==(const AutomatonBase& other) const = 0;
+
+	friend std::ostream& operator<<(std::ostream& os, const AutomatonBase& automaton);
+
+	virtual void operator>>(std::ostream&) const = 0;
+};
+
+} /* namespace automaton */
+
+#endif /* AUTOMATON_BASE_H_ */
+
diff --git a/alib2/src/automaton/AutomatonFromXMLParser.cpp b/alib2/src/automaton/AutomatonFromXMLParser.cpp
index ea9be89cb3..9e5330d769 100644
--- a/alib2/src/automaton/AutomatonFromXMLParser.cpp
+++ b/alib2/src/automaton/AutomatonFromXMLParser.cpp
@@ -12,15 +12,15 @@
 
 namespace automaton {
 
-Automaton* AutomatonFromXMLParser::parse(std::list<sax::Token> &input) {
+Automaton AutomatonFromXMLParser::parse(std::list<sax::Token> &input) {
 	if(isToken(input, sax::Token::START_ELEMENT, "automaton"))
-		return new UnknownAutomaton(parseUnknownAutomaton(input));
+		return Automaton(parseUnknownAutomaton(input));
 	else if(isToken(input, sax::Token::START_ELEMENT, "EpsilonNFA"))
-		return new EpsilonNFA(parseEpsilonNFA(input));
+		return Automaton(parseEpsilonNFA(input));
 	else if(isToken(input, sax::Token::START_ELEMENT, "NFA"))
-		return new NFA(parseNFA(input));
+		return Automaton(parseNFA(input));
 	else if(isToken(input, sax::Token::START_ELEMENT, "DFA"))
-		return new DFA(parseDFA(input));
+		return Automaton(parseDFA(input));
 	else
 		throw sax::ParserException(sax::Token("EpsilonNFA / NFA / DFA", sax::Token::START_ELEMENT), input.front());
 }
diff --git a/alib2/src/automaton/AutomatonFromXMLParser.h b/alib2/src/automaton/AutomatonFromXMLParser.h
index 98f6c94212..6487a9b2e6 100644
--- a/alib2/src/automaton/AutomatonFromXMLParser.h
+++ b/alib2/src/automaton/AutomatonFromXMLParser.h
@@ -9,6 +9,7 @@
 #define AUTOMATON_FROM_XML_PARSER_H_
 
 #include "../sax/FromXMLParser.h"
+#include "Automaton.h"
 #include "UnknownAutomaton.h"
 #include "FSM/EpsilonNFA.h"
 #include "FSM/NFA.h"
@@ -67,7 +68,7 @@ public:
 	 * @return UnknownAutomaton
 	 * @throws ParserException when an error occurs
 	 */
-	Automaton* parse(std::list<sax::Token> &input);
+	Automaton parse(std::list<sax::Token> &input);
 
 	UnknownAutomaton parseUnknownAutomaton(std::list<sax::Token>& input);
 	EpsilonNFA parseEpsilonNFA(std::list<sax::Token>& input);
diff --git a/alib2/src/automaton/AutomatonToXMLComposer.cpp b/alib2/src/automaton/AutomatonToXMLComposer.cpp
index be77fd416e..37ce44074c 100644
--- a/alib2/src/automaton/AutomatonToXMLComposer.cpp
+++ b/alib2/src/automaton/AutomatonToXMLComposer.cpp
@@ -159,6 +159,12 @@ void AutomatonToXMLComposer::printSymbol(std::list<sax::Token>& out, const alpha
 	out.push_back(sax::Token(tagName, sax::Token::END_ELEMENT));
 }
 
+std::list<sax::Token> AutomatonToXMLComposer::compose(const AutomatonBase& automaton) {
+	std::list<sax::Token> out;
+	automaton.Accept((void*) &out, *this);
+	return out;
+}
+
 std::list<sax::Token> AutomatonToXMLComposer::compose(const UnknownAutomaton& automaton) {
 	std::list<sax::Token> out;
 	out.push_back(sax::Token("automaton", sax::Token::START_ELEMENT));
@@ -263,6 +269,10 @@ std::list<sax::Token> AutomatonToXMLComposer::compose(const Automaton& automaton
 	return out;
 }
 
+void AutomatonToXMLComposer::Visit(void* data, const Automaton& automaton) {
+	*((std::list<sax::Token>*) data) = this->compose(automaton);
+}
+
 void AutomatonToXMLComposer::Visit(void* data, const UnknownAutomaton& automaton) {
 	*((std::list<sax::Token>*) data) = this->compose(automaton);
 }
diff --git a/alib2/src/automaton/AutomatonToXMLComposer.h b/alib2/src/automaton/AutomatonToXMLComposer.h
index 3daa380ce1..06e3430bdd 100644
--- a/alib2/src/automaton/AutomatonToXMLComposer.h
+++ b/alib2/src/automaton/AutomatonToXMLComposer.h
@@ -10,6 +10,7 @@
 
 #include <string>
 #include <list>
+#include "Automaton.h"
 #include "UnknownAutomaton.h"
 #include "FSM/EpsilonNFA.h"
 #include "FSM/NFA.h"
@@ -21,7 +22,8 @@ namespace automaton {
 /**
  * This class contains methods to print XML representation of automata to the output stream.
  */
-class AutomatonToXMLComposer : public Automaton::visitor_type {
+class AutomatonToXMLComposer : public Automaton::visitor_type, public AutomatonBase::visitor_type {
+	void Visit(void*, const Automaton& automaton);
 	void Visit(void*, const UnknownAutomaton& automaton);
 	void Visit(void*, const EpsilonNFA& automaton);
 	void Visit(void*, const NFA& automaton);
@@ -53,6 +55,8 @@ public:
 	 * @param automaton automaton to print
 	 * @return list of xml tokens representing the automaton
 	 */
+	std::list<sax::Token> compose(const AutomatonBase& automaton);
+
 	std::list<sax::Token> compose(const Automaton& automaton);
 	
 	std::list<sax::Token> compose(const UnknownAutomaton& automaton);
diff --git a/alib2/src/automaton/FSM/CompactNFA.cpp b/alib2/src/automaton/FSM/CompactNFA.cpp
index e8f8585b90..a325de3834 100644
--- a/alib2/src/automaton/FSM/CompactNFA.cpp
+++ b/alib2/src/automaton/FSM/CompactNFA.cpp
@@ -13,6 +13,14 @@
 
 namespace automaton {
 
+AutomatonBase* CompactNFA::clone() const {
+	return new CompactNFA(*this);
+}
+
+AutomatonBase* CompactNFA::plunder() && {
+	return new CompactNFA(std::move(*this));
+}
+
 bool CompactNFA::removeState(const State& state) {
 	if (initialStates.find(state) != initialStates.end()) {
 		throw AutomatonException("State \"" + state.getName() + "\" is initial state.");
@@ -97,7 +105,7 @@ std::map<std::pair<State, string::String>, std::set<State>> CompactNFA::getTrans
 	return transitionsToState;
 }
 
-bool CompactNFA::operator==(const Automaton& other) const {
+bool CompactNFA::operator==(const AutomatonBase& other) const {
 	return other == *this;
 }
 
diff --git a/alib2/src/automaton/FSM/CompactNFA.h b/alib2/src/automaton/FSM/CompactNFA.h
index 0779c6783e..6e6b498a24 100644
--- a/alib2/src/automaton/FSM/CompactNFA.h
+++ b/alib2/src/automaton/FSM/CompactNFA.h
@@ -9,7 +9,7 @@
 #define COMPACT_DFA_H_
 
 #include <map>
-#include "../Automaton.h"
+#include "../AutomatonBase.h"
 #include "../common/MultiInitialStates.h"
 #include "../common/InputAlphabet.h"
 #include "../../string/String.h"
@@ -20,11 +20,15 @@ namespace automaton {
  * Represents Finite Automaton.
  * Can store nondeterministic finite automaton without epsilon transitions.
  */
-class CompactNFA : public Automaton, public std::element<CompactNFA, Automaton::visitor_type>, public MultiInitialStates, public InputAlphabet {
+class CompactNFA : public AutomatonBase, public std::element<CompactNFA, AutomatonBase::visitor_type>, public MultiInitialStates, public InputAlphabet {
 protected:
 	std::map<std::pair<State, string::String>, std::set<State> > transitions;
 public:
 	
+	virtual AutomatonBase* clone() const;
+	
+	virtual AutomatonBase* plunder() &&;
+
 	/**
 	 * @copydoc Automaton::removeState(const State&)
 	 */
@@ -66,7 +70,7 @@ public:
 	 */
 	std::map<std::pair<State, string::String>, std::set<State>> getTransitionsToState(const State& from) const;
 
-	virtual bool operator==(const Automaton& other) const;
+	virtual bool operator==(const AutomatonBase& other) const;
 
 	virtual bool operator==(const CompactNFA& other) const;
 
diff --git a/alib2/src/automaton/FSM/DFA.cpp b/alib2/src/automaton/FSM/DFA.cpp
index 5b86e94dd5..68e4e84305 100644
--- a/alib2/src/automaton/FSM/DFA.cpp
+++ b/alib2/src/automaton/FSM/DFA.cpp
@@ -17,6 +17,14 @@ DFA::DFA(const State& initialState) : SingleInitialState(initialState) {
 
 }
 
+AutomatonBase* DFA::clone() const {
+	return new DFA(*this);
+}
+
+AutomatonBase* DFA::plunder() && {
+	return new DFA(std::move(*this));
+}
+
 bool DFA::removeState(const State& state) {
 	if (initialState == state) {
 		throw AutomatonException("State \"" + state.getName() + "\" is initial state.");
@@ -123,7 +131,7 @@ bool DFA::isTotal() const {
 	return transitions.size() == inputAlphabet.size() * states.size();
 }
 
-bool DFA::operator==(const Automaton& other) const {
+bool DFA::operator==(const AutomatonBase& other) const {
 	return other == *this;
 }
 
diff --git a/alib2/src/automaton/FSM/DFA.h b/alib2/src/automaton/FSM/DFA.h
index db697e2827..59952216a0 100644
--- a/alib2/src/automaton/FSM/DFA.h
+++ b/alib2/src/automaton/FSM/DFA.h
@@ -9,7 +9,7 @@
 #define DFA_H_
 
 #include <map>
-#include "../Automaton.h"
+#include "../AutomatonBase.h"
 #include "../common/SingleInitialState.h"
 #include "../common/InputAlphabet.h"
 #include "../../alphabet/Symbol.h"
@@ -20,12 +20,16 @@ namespace automaton {
  * Represents Finite Automaton.
  * Can store nondeterministic finite automaton without epsilon transitions.
  */
-class DFA : public Automaton, public std::element<DFA, Automaton::visitor_type>, public SingleInitialState, public InputAlphabet {
+class DFA : public AutomatonBase, public std::element<DFA, AutomatonBase::visitor_type>, public SingleInitialState, public InputAlphabet {
 protected:
 	std::map<std::pair<State, alphabet::Symbol>, State> transitions;
 public:
 	DFA(const State& initialState);
 
+	virtual AutomatonBase* clone() const;
+	
+	virtual AutomatonBase* plunder() &&;
+
 	/**
 	 * @copydoc Automaton::removeState(const State&)
 	 */
@@ -76,7 +80,7 @@ public:
 	 */
 	bool isTotal() const;
 	
-	virtual bool operator==(const Automaton& other) const;
+	virtual bool operator==(const AutomatonBase& other) const;
 
 	virtual bool operator==(const DFA& other) const;
 	
diff --git a/alib2/src/automaton/FSM/EpsilonNFA.cpp b/alib2/src/automaton/FSM/EpsilonNFA.cpp
index 45567fab50..59795c35c6 100644
--- a/alib2/src/automaton/FSM/EpsilonNFA.cpp
+++ b/alib2/src/automaton/FSM/EpsilonNFA.cpp
@@ -12,6 +12,14 @@
 
 namespace automaton {
 
+AutomatonBase* EpsilonNFA::clone() const {
+	return new EpsilonNFA(*this);
+}
+
+AutomatonBase* EpsilonNFA::plunder() && {
+	return new EpsilonNFA(std::move(*this));
+}
+
 bool EpsilonNFA::removeState(const State& state) {
 	if (initialStates.find(state) != initialStates.end()) {
 		throw AutomatonException("State \"" + state.getName() + "\" is initial state.");
@@ -228,7 +236,7 @@ bool EpsilonNFA::isTotal() const {
 	return isDeterministic() && transitions.size() == inputAlphabet.size() * states.size();
 }
 
-bool EpsilonNFA::operator==(const Automaton& other) const {
+bool EpsilonNFA::operator==(const AutomatonBase& other) const {
 	return other == *this;
 }
 
diff --git a/alib2/src/automaton/FSM/EpsilonNFA.h b/alib2/src/automaton/FSM/EpsilonNFA.h
index ef9d78e2a9..09398a52d9 100644
--- a/alib2/src/automaton/FSM/EpsilonNFA.h
+++ b/alib2/src/automaton/FSM/EpsilonNFA.h
@@ -10,7 +10,7 @@
 
 #include <map>
 #include "../../std/variant.hpp"
-#include "../Automaton.h"
+#include "../AutomatonBase.h"
 #include "../common/MultiInitialStates.h"
 #include "../common/InputAlphabet.h"
 #include "../../alphabet/Symbol.h"
@@ -22,10 +22,14 @@ namespace automaton {
  * Represents Finite Automaton.
  * Can store nondeterministic finite automaton with epsilon transitions.
  */
-class EpsilonNFA : public Automaton, public std::element<EpsilonNFA, Automaton::visitor_type>, public MultiInitialStates, public InputAlphabet {
+class EpsilonNFA : public AutomatonBase, public std::element<EpsilonNFA, AutomatonBase::visitor_type>, public MultiInitialStates, public InputAlphabet {
 protected:
 	std::map<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> > transitions;
 public:
+	virtual AutomatonBase* clone() const;
+	
+	virtual AutomatonBase* plunder() &&;
+
 	/**
 	 * @copydoc Automaton::removeState(const State&)
 	 */
@@ -147,7 +151,7 @@ public:
 	 */
 	bool isTotal() const;
 
-	virtual bool operator==(const Automaton& other) const;
+	virtual bool operator==(const AutomatonBase& other) const;
 
 	virtual bool operator==(const EpsilonNFA& other) const;
 
diff --git a/alib2/src/automaton/FSM/ExtendedNFA.cpp b/alib2/src/automaton/FSM/ExtendedNFA.cpp
index 66fecb5ad6..2cf6504ae8 100644
--- a/alib2/src/automaton/FSM/ExtendedNFA.cpp
+++ b/alib2/src/automaton/FSM/ExtendedNFA.cpp
@@ -13,6 +13,14 @@
 
 namespace automaton {
 
+AutomatonBase* ExtendedNFA::clone() const {
+	return new ExtendedNFA(*this);
+}
+
+AutomatonBase* ExtendedNFA::plunder() && {
+	return new ExtendedNFA(std::move(*this));
+}
+
 bool ExtendedNFA::removeState(const State& state) {
 	if (initialStates.find(state) != initialStates.end()) {
 		throw AutomatonException("State \"" + state.getName() + "\" is initial state.");
@@ -97,7 +105,7 @@ std::map<std::pair<State, regexp::RegExp>, std::set<State> > ExtendedNFA::getTra
 	return transitionsToState;
 }
 
-bool ExtendedNFA::operator==(const Automaton& other) const {
+bool ExtendedNFA::operator==(const AutomatonBase& other) const {
 	return other == *this;
 }
 
diff --git a/alib2/src/automaton/FSM/ExtendedNFA.h b/alib2/src/automaton/FSM/ExtendedNFA.h
index 2e36838be7..dfcb73fd9b 100644
--- a/alib2/src/automaton/FSM/ExtendedNFA.h
+++ b/alib2/src/automaton/FSM/ExtendedNFA.h
@@ -9,7 +9,7 @@
 #define EXTENDED_NFA_H_
 
 #include <map>
-#include "../Automaton.h"
+#include "../AutomatonBase.h"
 #include "../common/MultiInitialStates.h"
 #include "../common/InputAlphabet.h"
 #include "../../regexp/RegExp.h"
@@ -20,10 +20,14 @@ namespace automaton {
  * Represents Finite Automaton.
  * Can store nondeterministic finite automaton without epsilon transitions.
  */
-class ExtendedNFA : public Automaton, public std::element<ExtendedNFA, Automaton::visitor_type>, public MultiInitialStates, public InputAlphabet {
+class ExtendedNFA : public AutomatonBase, public std::element<ExtendedNFA, AutomatonBase::visitor_type>, public MultiInitialStates, public InputAlphabet {
 protected:
 	std::map<std::pair<State, regexp::RegExp>, std::set<State> > transitions;
 public:
+	virtual AutomatonBase* clone() const;
+	
+	virtual AutomatonBase* plunder() &&;
+
 	/**
 	 * @copydoc Automaton::removeState(const State&)
 	 */
@@ -65,7 +69,7 @@ public:
 	 */
 	std::map<std::pair<State, regexp::RegExp>, std::set<State> > getTransitionsToState(const State& from) const;
 
-	virtual bool operator==(const Automaton& other) const;
+	virtual bool operator==(const AutomatonBase& other) const;
 
 	virtual bool operator==(const ExtendedNFA& other) const;
 
diff --git a/alib2/src/automaton/FSM/NFA.cpp b/alib2/src/automaton/FSM/NFA.cpp
index e588e515cb..38e4ef9d50 100644
--- a/alib2/src/automaton/FSM/NFA.cpp
+++ b/alib2/src/automaton/FSM/NFA.cpp
@@ -11,6 +11,14 @@
 
 namespace automaton {
 
+AutomatonBase* NFA::clone() const {
+	return new NFA(*this);
+}
+
+AutomatonBase* NFA::plunder() && {
+	return new NFA(std::move(*this));
+}
+
 bool NFA::removeState(const State& state) {
 	if (initialStates.find(state) != initialStates.end()) {
 		throw AutomatonException("State \"" + state.getName() + "\" is initial state.");
@@ -112,7 +120,7 @@ bool NFA::isTotal() const {
 	return isDeterministic() && transitions.size() == inputAlphabet.size() * states.size();
 }
 
-bool NFA::operator==(const Automaton& other) const {
+bool NFA::operator==(const AutomatonBase& other) const {
 	return other == *this;
 }
 
diff --git a/alib2/src/automaton/FSM/NFA.h b/alib2/src/automaton/FSM/NFA.h
index 6fb134f24a..11a0acb2e1 100644
--- a/alib2/src/automaton/FSM/NFA.h
+++ b/alib2/src/automaton/FSM/NFA.h
@@ -10,7 +10,7 @@
 
 #include <map>
 #include "../../std/map.hpp"
-#include "../Automaton.h"
+#include "../AutomatonBase.h"
 #include "../common/MultiInitialStates.h"
 #include "../common/InputAlphabet.h"
 #include "../../alphabet/Symbol.h"
@@ -21,10 +21,14 @@ namespace automaton {
  * Represents Finite Automaton.
  * Can store nondeterministic finite automaton without epsilon transitions.
  */
-class NFA : public Automaton, public std::element<NFA, Automaton::visitor_type>, public MultiInitialStates, public InputAlphabet {
+class NFA : public AutomatonBase, public std::element<NFA, AutomatonBase::visitor_type>, public MultiInitialStates, public InputAlphabet {
 protected:
 	std::map<std::pair<State, alphabet::Symbol>, std::set<State> > transitions;
 public:
+	virtual AutomatonBase* clone() const;
+	
+	virtual AutomatonBase* plunder() &&;
+
 	/**
 	 * @copydoc Automaton::removeState(const State&)
 	 */
@@ -85,7 +89,7 @@ public:
 	 */
 	bool isTotal() const;
 
-	virtual bool operator==(const Automaton& other) const;
+	virtual bool operator==(const AutomatonBase& other) const;
 
 	virtual bool operator==(const NFA& other) const;
 
diff --git a/alib2/src/automaton/PDA/PDA.cpp b/alib2/src/automaton/PDA/PDA.cpp
index 8c2278582f..7dd36ad9f7 100644
--- a/alib2/src/automaton/PDA/PDA.cpp
+++ b/alib2/src/automaton/PDA/PDA.cpp
@@ -12,6 +12,14 @@
 
 namespace automaton {
 
+AutomatonBase* PDA::clone() const {
+	return new PDA(*this);
+}
+
+AutomatonBase* PDA::plunder() && {
+	return new PDA(std::move(*this));
+}
+
 bool PDA::removeState(const State& state) {
 	if (initialStates.find(state) != initialStates.end()) {
 		throw AutomatonException("State \"" + state.getName() + "\" is initial state.");
@@ -159,7 +167,7 @@ const std::set<alphabet::Symbol>& PDA::getInitialSymbols() const {
 	return initialSymbols;
 }
 
-bool PDA::operator==(const Automaton& other) const {
+bool PDA::operator==(const AutomatonBase& other) const {
 	return other == *this;
 }
 
diff --git a/alib2/src/automaton/PDA/PDA.h b/alib2/src/automaton/PDA/PDA.h
index bd4f2079d1..2594295d00 100644
--- a/alib2/src/automaton/PDA/PDA.h
+++ b/alib2/src/automaton/PDA/PDA.h
@@ -12,7 +12,7 @@
 #include <map>
 #include <vector>
 #include "../../std/variant.hpp"
-#include "../Automaton.h"
+#include "../AutomatonBase.h"
 #include "../common/MultiInitialStates.h"
 #include "../common/InputAlphabet.h"
 #include "../../alphabet/Symbol.h"
@@ -23,12 +23,16 @@ namespace automaton {
 /**
  * Push Down Automaton
  */
-class PDA: public Automaton, public std::element<PDA, Automaton::visitor_type>, public MultiInitialStates, public InputAlphabet {
+class PDA: public AutomatonBase, public std::element<PDA, AutomatonBase::visitor_type>, public MultiInitialStates, public InputAlphabet {
 protected:
 	std::set<alphabet::Symbol> stackAlphabet;
 	std::map<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::set<std::pair<State, std::vector<alphabet::Symbol> > > > transitions;
 	std::set<alphabet::Symbol> initialSymbols;
 public:
+	virtual AutomatonBase* clone() const;
+	
+	virtual AutomatonBase* plunder() &&;
+
 	/**
 	 * @copydoc Automaton::removeState(const State&)
 	 */
@@ -117,7 +121,7 @@ public:
 	 */
 	const std::set<alphabet::Symbol>& getInitialSymbols() const;
 
-	virtual bool operator==(const Automaton& other) const;
+	virtual bool operator==(const AutomatonBase& other) const;
 
 	virtual bool operator==(const PDA& other) const;
 
diff --git a/alib2/src/automaton/TM/OneTapeDTM.cpp b/alib2/src/automaton/TM/OneTapeDTM.cpp
index 1b496fe653..4084985dd4 100644
--- a/alib2/src/automaton/TM/OneTapeDTM.cpp
+++ b/alib2/src/automaton/TM/OneTapeDTM.cpp
@@ -18,6 +18,14 @@ using namespace alphabet;
 OneTapeDTM::OneTapeDTM(const State& initialState, const alphabet::Symbol& blank) : SingleInitialState(initialState), BlankSymbolInputTapeAlphabet(blank) {
 }
 
+AutomatonBase* OneTapeDTM::clone() const {
+	return new OneTapeDTM(*this);
+}
+
+AutomatonBase* OneTapeDTM::plunder() && {
+	return new OneTapeDTM(std::move(*this));
+}
+
 bool OneTapeDTM::removeState(const State& state) {
 	if (initialState == state) {
 		throw AutomatonException("State \"" + state.getName() + "\" is initial state.");
@@ -106,7 +114,7 @@ const std::map<std::pair<State, alphabet::Symbol>, std::tuple<State, alphabet::S
 	return transitions;
 }
 
-bool OneTapeDTM::operator==(const Automaton& other) const {
+bool OneTapeDTM::operator==(const AutomatonBase& other) const {
 	return other == *this;
 }
 
diff --git a/alib2/src/automaton/TM/OneTapeDTM.h b/alib2/src/automaton/TM/OneTapeDTM.h
index 91b6b53994..b6963eb07e 100644
--- a/alib2/src/automaton/TM/OneTapeDTM.h
+++ b/alib2/src/automaton/TM/OneTapeDTM.h
@@ -8,7 +8,7 @@
 #ifndef ONE_TAPE_DTM_H_
 #define ONE_TAPE_DTM_H_
 
-#include "../Automaton.h"
+#include "../AutomatonBase.h"
 #include "../common/SingleInitialState.h"
 #include "../common/BlankSymbolInputTapeAlphabet.h"
 #include "../common/Shift.h"
@@ -22,11 +22,15 @@ namespace automaton {
 /**
  * One tape turing machine
  */
-class OneTapeDTM : public Automaton, public std::element<OneTapeDTM, Automaton::visitor_type>, public SingleInitialState, public BlankSymbolInputTapeAlphabet {
+class OneTapeDTM : public AutomatonBase, public std::element<OneTapeDTM, AutomatonBase::visitor_type>, public SingleInitialState, public BlankSymbolInputTapeAlphabet {
 protected:
 	std::map<std::pair<State, alphabet::Symbol>, std::tuple<State, alphabet::Symbol, Shift> > transitions;
 
 public:
+	virtual AutomatonBase* clone() const;
+	
+	virtual AutomatonBase* plunder() &&;
+
 	OneTapeDTM(const State& initialState, const alphabet::Symbol& blank);
 
 	/**
@@ -69,7 +73,7 @@ public:
 	 */
 	const std::map<std::pair<State, alphabet::Symbol>, std::tuple<State, alphabet::Symbol, Shift> >& getTransitions() const;
 
-	virtual bool operator==(const Automaton& other) const;
+	virtual bool operator==(const AutomatonBase& other) const;
 
 	virtual bool operator==(const OneTapeDTM& other) const;
 
diff --git a/alib2/src/automaton/UnknownAutomaton.cpp b/alib2/src/automaton/UnknownAutomaton.cpp
index 12ac46e0e2..b66f57f5d0 100644
--- a/alib2/src/automaton/UnknownAutomaton.cpp
+++ b/alib2/src/automaton/UnknownAutomaton.cpp
@@ -20,6 +20,14 @@ UnknownAutomaton::UnknownAutomaton() :
 UnknownAutomaton::~UnknownAutomaton() {
 }
 
+AutomatonBase* UnknownAutomaton::clone() const {
+	return new UnknownAutomaton(*this);
+}
+
+AutomatonBase* UnknownAutomaton::plunder() && {
+	return new UnknownAutomaton(std::move(*this));
+}
+
 bool UnknownAutomaton::addState(const State& state) {
 	return states.insert(state).second;
 }
@@ -171,7 +179,7 @@ const std::set<UnknownTransition>& UnknownAutomaton::getTransitions() const {
 }
 
 
-bool UnknownAutomaton::operator==(const Automaton& other) const {
+bool UnknownAutomaton::operator==(const AutomatonBase& other) const {
 	return other == *this;
 }
 
diff --git a/alib2/src/automaton/UnknownAutomaton.h b/alib2/src/automaton/UnknownAutomaton.h
index eb22448943..e6a2304f4b 100644
--- a/alib2/src/automaton/UnknownAutomaton.h
+++ b/alib2/src/automaton/UnknownAutomaton.h
@@ -11,7 +11,7 @@
 #include <set>
 #include <list>
 
-#include "Automaton.h"
+#include "AutomatonBase.h"
 #include "common/State.h"
 #include "../alphabet/Symbol.h"
 #include "UnknownTransition.h"
@@ -21,7 +21,7 @@ namespace automaton {
 /**
  * Class representing unknown automaton parsed from XML.
  */
-class UnknownAutomaton : public Automaton, public std::element<UnknownAutomaton, Automaton::visitor_type> {
+class UnknownAutomaton : public AutomatonBase, public std::element<UnknownAutomaton, AutomatonBase::visitor_type> {
 protected:
 	std::set<State> states;
 	std::set<State> initialStates;
@@ -37,6 +37,10 @@ public:
 	UnknownAutomaton();
 	~UnknownAutomaton() noexcept;
 
+	virtual AutomatonBase* clone() const;
+	
+	virtual AutomatonBase* plunder() &&;
+
 	/**
 	 * Adds new state to the automaton.
 	 * @param state State to add
@@ -273,7 +277,7 @@ public:
 	 */
 	virtual bool operator==(const UnknownAutomaton& other) const;
 
-	virtual bool operator==(const Automaton& other) const;
+	virtual bool operator==(const AutomatonBase& other) const;
 
 	virtual void operator>>(std::ostream& os) const;
 };
diff --git a/alib2/src/automaton/common/States.cpp b/alib2/src/automaton/common/States.cpp
index 654133a592..e5b2fcdbfe 100644
--- a/alib2/src/automaton/common/States.cpp
+++ b/alib2/src/automaton/common/States.cpp
@@ -106,10 +106,6 @@ const State& States::createUniqueState(const std::string& name, bool integerSuff
 	throw AutomatonException("Could not create unique state with name " + name + "." );
 }
 
-std::ostream& operator <<(std::ostream& out, const States& automaton) {
-	return out;
-}
-
 } /* namespace automaton */
 
 
diff --git a/alib2/src/automaton/common/States.h b/alib2/src/automaton/common/States.h
index 58bc89c0c7..a73f7602ec 100644
--- a/alib2/src/automaton/common/States.h
+++ b/alib2/src/automaton/common/States.h
@@ -91,13 +91,6 @@ public:
 	 * @return created state
 	 */
 	const State& createUniqueState(const std::string& name, bool integerSuffix = false);
-
-	/**
-	 * Prints XML representation of the automaton to the ostream.
-	 * @param out output stream to which print the automaton
-	 * @param automaton automaton to print
-	 */
-	friend std::ostream& operator<<(std::ostream& out, const States& automaton);
 };
 
 } /* namespace automaton */
diff --git a/alib2/src/factory/AutomatonConvertor.cpp b/alib2/src/factory/AutomatonConvertor.cpp
index 72e88f347c..a59ac88fb0 100644
--- a/alib2/src/factory/AutomatonConvertor.cpp
+++ b/alib2/src/factory/AutomatonConvertor.cpp
@@ -14,13 +14,13 @@
 
 namespace automaton {
 
-Automaton* AutomatonConvertor::buildAutomaton(const UnknownAutomaton& automaton) {
+Automaton AutomatonConvertor::buildAutomaton(const UnknownAutomaton& automaton) {
 	if (isEpsilonNFA(automaton)) {
-		return new EpsilonNFA(buildEpsilonNFA(automaton));
+		return Automaton(buildEpsilonNFA(automaton));
 	} else if (isPDA(automaton)) {
-		return new PDA(buildPDA(automaton));
+		return Automaton(buildPDA(automaton));
 	} else if (isOneTapeDTM(automaton)) {
-		return new OneTapeDTM(buildOneTapeDTM(automaton));
+		return Automaton(buildOneTapeDTM(automaton));
 	} else {
 		throw AutomatonException("Cannot determine automaton type.");
 	}
diff --git a/alib2/src/factory/AutomatonConvertor.h b/alib2/src/factory/AutomatonConvertor.h
index 1d82f77a64..04eaf17ab9 100644
--- a/alib2/src/factory/AutomatonConvertor.h
+++ b/alib2/src/factory/AutomatonConvertor.h
@@ -8,6 +8,7 @@
 #ifndef AUTOMATON_CONVERTOR_H_
 #define AUTOMATON_FONVERTOR_H_
 
+#include "../automaton/Automaton.h"
 #include "../automaton/UnknownAutomaton.h"
 #include "../automaton/FSM/EpsilonNFA.h"
 #include "../automaton/PDA/PDA.h"
@@ -27,7 +28,7 @@ public:
 	 * @throws AutomatonException when specific automaton cannot
 	 * be created form UnknownAutomaton (e.g. automaton type is not recognized)
 	 */
-	static Automaton* buildAutomaton(const UnknownAutomaton& automaton);
+	static Automaton buildAutomaton(const UnknownAutomaton& automaton);
 
 	/**
 	 * Checks that FSM can be build from UnknownAutomaton. That means UnknownAutomaton
diff --git a/alib2/src/factory/AutomatonFactory.cpp b/alib2/src/factory/AutomatonFactory.cpp
index 48a8a5a770..7fcda1eec2 100644
--- a/alib2/src/factory/AutomatonFactory.cpp
+++ b/alib2/src/factory/AutomatonFactory.cpp
@@ -14,54 +14,70 @@
 
 namespace automaton {
 
-Automaton* AutomatonFactory::fromFile(const std::string& filename) {
+Automaton AutomatonFactory::fromFile(const std::string& filename) {
 	std::list<sax::Token> tokens;
 	sax::SaxParseInterface::parseFile(filename, tokens);
 	return parse(tokens);
 }
 
-Automaton* AutomatonFactory::fromString(const std::string& str) {
+Automaton AutomatonFactory::fromString(const std::string& str) {
 	std::list<sax::Token> tokens;
 	sax::SaxParseInterface::parseMemory(str, tokens);
 	return parse(tokens);
 }
 
-Automaton* AutomatonFactory::fromStdin() {
+Automaton AutomatonFactory::fromStdin() {
 	return AutomatonFactory::fromStream(std::cin);
 }
 
-Automaton* AutomatonFactory::fromStream(std::istream& in) {
+Automaton AutomatonFactory::fromStream(std::istream& in) {
 	std::string input(std::istreambuf_iterator<char>(in), (std::istreambuf_iterator<char>()));
 	return AutomatonFactory::fromString(input);
 }
 
-Automaton* AutomatonFactory::parse(std::list<sax::Token> tokens) {
+Automaton AutomatonFactory::parse(std::list<sax::Token> tokens) {
 	AutomatonFromXMLParser parser;
 	return parser.parse(tokens);
 }
 
 void AutomatonFactory::toFile(const Automaton& automaton, const std::string& filename) {
+	toFile(automaton.getAutomaton(), filename);
+}
+
+std::string AutomatonFactory::toString(const Automaton& automaton) {
+	return toString(automaton.getAutomaton());
+}
+
+void AutomatonFactory::toStdout(const Automaton& automaton) {
+	return AutomatonFactory::toStdout(automaton.getAutomaton());
+}
+
+void AutomatonFactory::toStream(const Automaton& automaton, std::ostream& out) {
+	toStream(automaton.getAutomaton(), out);
+}
+
+void AutomatonFactory::toFile(const AutomatonBase& automaton, const std::string& filename) {
 	std::list<sax::Token> tokens = compose(automaton);
 	sax::SaxComposeInterface::printFile(filename, tokens);
 }
 
-std::string AutomatonFactory::toString(const Automaton& automaton) {
+std::string AutomatonFactory::toString(const AutomatonBase& automaton) {
 	std::list<sax::Token> tokens = compose(automaton);
 	std::string str;
 	sax::SaxComposeInterface::printMemory(str, tokens);
 	return str;
 }
 
-void AutomatonFactory::toStdout(const Automaton& automaton) {
+void AutomatonFactory::toStdout(const AutomatonBase& automaton) {
 	return AutomatonFactory::toStream(automaton, std::cout);
 }
 
-void AutomatonFactory::toStream(const Automaton& automaton, std::ostream& out) {
+void AutomatonFactory::toStream(const AutomatonBase& automaton, std::ostream& out) {
 	std::list<sax::Token> tokens = compose(automaton);
 	sax::SaxComposeInterface::printStream(out, tokens);
 }
 
-std::list<sax::Token> AutomatonFactory::compose(const Automaton& automaton) {
+std::list<sax::Token> AutomatonFactory::compose(const AutomatonBase& automaton) {
 	AutomatonToXMLComposer composer;
 	return composer.compose(automaton);
 }
diff --git a/alib2/src/factory/AutomatonFactory.h b/alib2/src/factory/AutomatonFactory.h
index 91726ce29d..74808c7896 100644
--- a/alib2/src/factory/AutomatonFactory.h
+++ b/alib2/src/factory/AutomatonFactory.h
@@ -25,26 +25,26 @@ public:
 	 * @param filename path to the file
 	 * @return Automaton*
 	 */
-	static Automaton* fromFile(const std::string& filename);
+	static Automaton fromFile(const std::string& filename);
 
 	/**
 	 * Parses the XML and returns Automaton*.
 	 * @param str string containing the XML
 	 * @return Automaton*
 	 */
-	static Automaton* fromString(const std::string& str);
+	static Automaton fromString(const std::string& str);
 	
 	/**
 	 * Parses the XML from stdin and returns Automaton*.
 	 * @return Automaton*
 	 */
-	static Automaton* fromStdin();
+	static Automaton fromStdin();
 	
 	/**
 	 * Parses the XML from stream and returns Automaton*.
 	 * @return Automaton*
 	 */
-	static Automaton* fromStream(std::istream& in);
+	static Automaton fromStream(std::istream& in);
 
 	/**
 	 * Parses the XML in file and returns the RegExp.
@@ -72,6 +72,32 @@ public:
 	 */
 	static void toStream(const Automaton&, std::ostream& out);
 	
+	/**
+	 * Parses the XML in file and returns the RegExp.
+	 * @param filename path to the file
+	 * @return RegExp
+	 */
+	static void toFile(const AutomatonBase&, const std::string& filename);
+
+	/**
+	 * Parses the XML and returns the RegExp.
+	 * @param str string containing the XML
+	 * @return RegExp
+	 */
+	static std::string toString(const AutomatonBase&);
+	
+	/**
+	 * Parses the XML from stdin and returns the RegExp.
+	 * @return RegExp
+	 */
+	static void toStdout(const AutomatonBase&);
+	
+	/**
+	 * Parses the XML from stream and returns the RegExp.
+	 * @return RegExp
+	 */
+	static void toStream(const AutomatonBase&, std::ostream& out);
+	
 protected:
 
 	/**
@@ -79,14 +105,14 @@ protected:
 	 * @param tokens XML represented as list of tokens
 	 * @return parsed Automaton*
 	 */
-	static Automaton* parse(std::list<sax::Token> tokens);
+	static Automaton parse(std::list<sax::Token> tokens);
 
 	/**
 	 * Parses the RegExp from list of tokens.
 	 * @param tokens XML represented as list of tokens
 	 * @return parsed RegExp
 	 */
-	static std::list<sax::Token> compose(const Automaton&);
+	static std::list<sax::Token> compose(const AutomatonBase&);
 };
 
 } /* namespace automaton */
diff --git a/alib2/src/regexp/RegExpElement.cpp b/alib2/src/regexp/RegExpElement.cpp
index ae6a9ac24b..ba1181b651 100644
--- a/alib2/src/regexp/RegExpElement.cpp
+++ b/alib2/src/regexp/RegExpElement.cpp
@@ -58,27 +58,27 @@ bool RegExpElement::operator<(const RegExpEmpty& other) const {
 }
 
 
-bool RegExpElement::operator==(const Concatenation& other) const {
+bool RegExpElement::operator==(const Concatenation&) const {
 	return false;
 }
 
-bool RegExpElement::operator==(const Alternation& other) const {
+bool RegExpElement::operator==(const Alternation&) const {
 	return false;
 }
 
-bool RegExpElement::operator==(const Iteration& other) const {
+bool RegExpElement::operator==(const Iteration&) const {
 	return false;
 }
 
-bool RegExpElement::operator==(const RegExpSymbol& other) const {
+bool RegExpElement::operator==(const RegExpSymbol&) const {
 	return false;
 }
 
-bool RegExpElement::operator==(const RegExpEpsilon& other) const {
+bool RegExpElement::operator==(const RegExpEpsilon&) const {
 	return false;
 }
 
-bool RegExpElement::operator==(const RegExpEmpty& other) const {
+bool RegExpElement::operator==(const RegExpEmpty&) const {
 	return false;
 }
 
diff --git a/alib2/src/regexp/RegExpEmpty.cpp b/alib2/src/regexp/RegExpEmpty.cpp
index bcc13aaf60..e7ce1a3623 100644
--- a/alib2/src/regexp/RegExpEmpty.cpp
+++ b/alib2/src/regexp/RegExpEmpty.cpp
@@ -13,20 +13,20 @@ RegExpEmpty::RegExpEmpty() {
   // so that default constructor is available
 }
   
-RegExpEmpty::RegExpEmpty(const RegExpEmpty& other) {
+RegExpEmpty::RegExpEmpty(const RegExpEmpty&) {
   // so that copy constructor is available
 }
 
-RegExpEmpty::RegExpEmpty(RegExpEmpty&& other) noexcept {
+RegExpEmpty::RegExpEmpty(RegExpEmpty&&) noexcept {
   this->attachRegExp(NULL);
 }
 
-RegExpEmpty& RegExpEmpty::operator =(const RegExpEmpty& other) {
+RegExpEmpty& RegExpEmpty::operator =(const RegExpEmpty&) {
   //this is actually different than default implementation
   return *this;
 }
 
-RegExpEmpty& RegExpEmpty::operator =(RegExpEmpty&& other) noexcept {
+RegExpEmpty& RegExpEmpty::operator =(RegExpEmpty&&) noexcept {
   //this is actually different than default implementation
   return *this;
 }
@@ -74,7 +74,7 @@ bool RegExpEmpty::attachRegExp(const RegExp * regexp ) {
 	return true;
 }
 
-void RegExpEmpty::computeMinimalAlphabet( std::set<alphabet::Symbol>& alphabet ) const {
+void RegExpEmpty::computeMinimalAlphabet( std::set<alphabet::Symbol>&) const {
 
 }
 
diff --git a/alib2/src/regexp/RegExpEpsilon.cpp b/alib2/src/regexp/RegExpEpsilon.cpp
index f4d004a876..36ea54fd85 100644
--- a/alib2/src/regexp/RegExpEpsilon.cpp
+++ b/alib2/src/regexp/RegExpEpsilon.cpp
@@ -13,20 +13,20 @@ RegExpEpsilon::RegExpEpsilon() {
   // so that default constructor is available
 }
   
-RegExpEpsilon::RegExpEpsilon(const RegExpEpsilon& other) {
+RegExpEpsilon::RegExpEpsilon(const RegExpEpsilon&) {
   // so that copy constructor is available
 }
 
-RegExpEpsilon::RegExpEpsilon(RegExpEpsilon&& other) noexcept {
+RegExpEpsilon::RegExpEpsilon(RegExpEpsilon&&) noexcept {
 	this->attachRegExp(NULL);
 }
 
-RegExpEpsilon& RegExpEpsilon::operator =(const RegExpEpsilon& other) {
+RegExpEpsilon& RegExpEpsilon::operator =(const RegExpEpsilon&) {
   //this is actually different than default implementation
   return *this;
 }
 
-RegExpEpsilon& RegExpEpsilon::operator =(RegExpEpsilon&& other) noexcept {
+RegExpEpsilon& RegExpEpsilon::operator =(RegExpEpsilon&&) noexcept {
   //this is actually different than default implementation
   return *this;
 }
@@ -74,7 +74,7 @@ bool RegExpEpsilon::attachRegExp(const RegExp * regexp ) {
 	return true;
 }
 
-void RegExpEpsilon::computeMinimalAlphabet( std::set<alphabet::Symbol>& alphabet ) const {
+void RegExpEpsilon::computeMinimalAlphabet( std::set<alphabet::Symbol>&) const {
 
 }
 
diff --git a/alib2/src/regexp/RegExpToStringComposer.cpp b/alib2/src/regexp/RegExpToStringComposer.cpp
index 7a4adf4405..d2a7bc73c7 100644
--- a/alib2/src/regexp/RegExpToStringComposer.cpp
+++ b/alib2/src/regexp/RegExpToStringComposer.cpp
@@ -89,12 +89,12 @@ void RegExpToStringComposer::Visit(void* userData, const RegExpSymbol& symbol) {
 	}
 }
 
-void RegExpToStringComposer::Visit(void* userData, const RegExpEpsilon& epsilon) {
+void RegExpToStringComposer::Visit(void* userData, const RegExpEpsilon&) {
 	std::stringstream &out = *((std::stringstream*) userData);
 	out << "\\e";
 }
 
-void RegExpToStringComposer::Visit(void* userData, const RegExpEmpty& empty) {
+void RegExpToStringComposer::Visit(void* userData, const RegExpEmpty&) {
 	std::stringstream &out = *((std::stringstream*) userData);
 	out << "\\0";
 }
diff --git a/alib2/src/regexp/RegExpToXMLComposer.cpp b/alib2/src/regexp/RegExpToXMLComposer.cpp
index 682b123d48..fa4d304f5a 100644
--- a/alib2/src/regexp/RegExpToXMLComposer.cpp
+++ b/alib2/src/regexp/RegExpToXMLComposer.cpp
@@ -74,14 +74,14 @@ void RegExpToXMLComposer::Visit(void* userData, const RegExpSymbol& symbol) {
 	out.push_back(sax::Token("symbol", sax::Token::END_ELEMENT));
 }
 
-void RegExpToXMLComposer::Visit(void* userData, const RegExpEpsilon& epsilon) {
+void RegExpToXMLComposer::Visit(void* userData, const RegExpEpsilon&) {
 	std::list<sax::Token> &out = *((std::list<sax::Token>*) userData);
 
 	out.push_back(sax::Token("epsilon", sax::Token::START_ELEMENT));
 	out.push_back(sax::Token("epsilon", sax::Token::END_ELEMENT));
 }
 
-void RegExpToXMLComposer::Visit(void* userData, const RegExpEmpty& empty) {
+void RegExpToXMLComposer::Visit(void* userData, const RegExpEmpty&) {
 	std::list<sax::Token> &out = *((std::list<sax::Token>*) userData);
 
 	out.push_back(sax::Token("empty", sax::Token::START_ELEMENT));
diff --git a/alib2/src/std/variant.hpp b/alib2/src/std/variant.hpp
index 784db111c4..8892d3419d 100644
--- a/alib2/src/std/variant.hpp
+++ b/alib2/src/std/variant.hpp
@@ -92,12 +92,12 @@ struct variant_helper<F, Ts...> {
 };
 
 template<> struct variant_helper<>  {
-inline static void destroy(size_t id, void * data) { }
-inline static bool move(size_t old_t, void * old_v, void * new_v) { return false; }
-inline static void copy(size_t old_t, const void * old_v, void * new_v) { }
-inline static bool compareEq(size_t this_t, const void * this_v, size_t other_t, const void * other_v) { return true; }
-inline static void print(ostream& out, const size_t id, const void* data) {}
-inline static bool compareLess(size_t this_t, const void * this_v, size_t other_t, const void * other_v) { return false; }
+inline static void destroy(size_t, void *) { }
+inline static bool move(size_t, void *, void *) { return false; }
+inline static void copy(size_t, const void *, void *) { }
+inline static bool compareEq(size_t, const void *, size_t, const void *) { return true; }
+inline static void print(ostream&, const size_t, const void *) {}
+inline static bool compareLess(size_t, const void *, size_t, const void *) { return false; }
 };
 
 template<typename F, typename... Ts>
diff --git a/alib2/src/string/Epsilon.cpp b/alib2/src/string/Epsilon.cpp
index 77a92db4af..7ea4ed67ed 100644
--- a/alib2/src/string/Epsilon.cpp
+++ b/alib2/src/string/Epsilon.cpp
@@ -13,15 +13,15 @@ Epsilon::Epsilon() : String(), CyclicString() {
 
 }
 
-bool Epsilon::operator<(const Epsilon& other) const {
+bool Epsilon::operator<(const Epsilon&) const {
   return false;
 }
 
-bool Epsilon::operator==(const Epsilon& other) const {
+bool Epsilon::operator==(const Epsilon&) const {
   return true;
 }
 
-bool Epsilon::operator!=(const Epsilon& other) const {
+bool Epsilon::operator!=(const Epsilon&) const {
   return false;
 }
 
diff --git a/alib2/test-src/automaton/AutomatonTest.cpp b/alib2/test-src/automaton/AutomatonTest.cpp
index 919d79efeb..9519029dbf 100644
--- a/alib2/test-src/automaton/AutomatonTest.cpp
+++ b/alib2/test-src/automaton/AutomatonTest.cpp
@@ -44,9 +44,9 @@ void AutomatonTest::testXMLParser() {
   }
   {
 	std::string tmp = automaton::AutomatonFactory::toString(automaton);
-	automaton::Automaton* automaton2 = automaton::AutomatonFactory::fromString(tmp);
+	automaton::Automaton automaton2 = automaton::AutomatonFactory::fromString(tmp);
 
-	CPPUNIT_ASSERT( automaton == *automaton2 );
+	CPPUNIT_ASSERT( automaton == automaton2.getAutomaton() );
   }
 }
 
-- 
GitLab