Skip to content
Snippets Groups Projects
Commit 20c8fa05 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

simplify operators

parent d5cacaf3
No related branches found
No related tags found
No related merge requests found
......@@ -194,6 +194,9 @@ bool UnknownAutomaton::operator>(const AutomatonBase& other) const {
}
 
bool UnknownAutomaton::operator==(const UnknownAutomaton& other) const {
std::pointer<alphabet::Symbol> blankSymbolPointer(blankSymbol);
std::pointer<alphabet::Symbol> otherBlankSymbolPointer(other.blankSymbol);
return states == other.states
&& inputAlphabet == other.inputAlphabet
&& initialStates == other.initialStates
......@@ -201,7 +204,7 @@ bool UnknownAutomaton::operator==(const UnknownAutomaton& other) const {
&& stackAlphabet == other.stackAlphabet
&& initialSymbols == other.initialSymbols
&& tapeAlphabet == other.tapeAlphabet
&& (blankSymbol == other.blankSymbol || (blankSymbol != NULL && other.blankSymbol != NULL && *blankSymbol == *other.blankSymbol))
&& blankSymbolPointer == otherBlankSymbolPointer
&& transitions == other.transitions;
}
 
......@@ -213,6 +216,8 @@ bool UnknownAutomaton::operator<(const UnknownAutomaton& other) const {
}
 
void UnknownAutomaton::operator>>(std::ostream& out) const {
std::pointer<alphabet::Symbol> blankSymbolPointer(blankSymbol);
out << "(UnknownAutomaton"
<< " states = " << states
<< " inputAlphabet = " << inputAlphabet
......@@ -221,9 +226,8 @@ void UnknownAutomaton::operator>>(std::ostream& out) const {
<< " stackAlphabet = " << stackAlphabet
<< " initialSymbols = " << initialSymbols
<< " tapeAlphabet = " << tapeAlphabet
<< " blankSymbol = ";
if(blankSymbol == NULL) out << "NULL"; else out << *blankSymbol;
out << " transitions = " << transitions
<< " blankSymbol = " << blankSymbolPointer
<< " transitions = " << transitions
<< ")";
}
 
......
......@@ -7,6 +7,7 @@
 
#include "UnknownTransition.h"
#include "../std/vector.hpp"
#include "../std/pointer.hpp"
 
namespace automaton {
 
......@@ -128,39 +129,35 @@ void UnknownTransition::setShift(const Shift& shift) {
}
 
bool UnknownTransition::operator <(const UnknownTransition& other) const {
if (from != other.from && from != NULL && other.from != NULL && *from != *other.from) {
if(from == NULL) return -1;
else if(other.from == NULL) return 1;
else return *from < *other.from;
} else if (input != other.input && input != NULL && other.input != NULL && *input != *other.input) {
if(input == NULL) return -1;
else if(other.input == NULL) return 1;
else return *input < *other.input;
} else if (pop != other.pop) {
return pop < other.pop;
} else if (shift != other.shift) {
return shift < other.shift;
} else if (to != other.to && to != NULL && other.to != NULL && *to != *other.to) {
if(to == NULL) return 1;
else if(other.to == NULL) return -1;
else return *to < *other.to;
} else if (output != other.output && output != NULL && other.output != NULL && *output != *other.output) {
if(output == NULL) return 1;
else if(other.output == NULL) return -1;
else return *output < *other.output;
} else {
return push < other.push;
}
std::pointer<automaton::State> fromPointer(from);
std::pointer<automaton::State> otherFromPointer(other.from);
std::pointer<std::variant<string::Epsilon, alphabet::Symbol>> inputPointer(input);
std::pointer<std::variant<string::Epsilon, alphabet::Symbol>> otherInputPointer(other.input);
std::pointer<automaton::State> toPointer(to);
std::pointer<automaton::State> otherToPointer(other.to);
std::pointer<std::variant<string::Epsilon, alphabet::Symbol>> outputPointer(output);
std::pointer<std::variant<string::Epsilon, alphabet::Symbol>> otherOutputPointer(other.output);
return std::tie(fromPointer, inputPointer, pop, shift, toPointer, outputPointer, push) < std::tie(otherFromPointer, otherInputPointer, pop, shift, otherToPointer, otherOutputPointer, push);
}
 
bool UnknownTransition::operator ==(const UnknownTransition& other) const {
return (from == other.from || (from != NULL && other.from != NULL && *from == *other.from))
&& (input == other.input || (input != NULL && other.input != NULL && *input == *other.input))
&& pop == other.pop
&& shift == other.shift
&& (to == other.to || (to != NULL && other.to != NULL && *to == *other.to))
&& (output == other.output || (output != NULL && other.output != NULL && *output == *other.output))
&& push == other.push;
std::pointer<automaton::State> fromPointer(from);
std::pointer<automaton::State> otherFromPointer(other.from);
std::pointer<std::variant<string::Epsilon, alphabet::Symbol>> inputPointer(input);
std::pointer<std::variant<string::Epsilon, alphabet::Symbol>> otherInputPointer(other.input);
std::pointer<automaton::State> toPointer(to);
std::pointer<automaton::State> otherToPointer(other.to);
std::pointer<std::variant<string::Epsilon, alphabet::Symbol>> outputPointer(output);
std::pointer<std::variant<string::Epsilon, alphabet::Symbol>> otherOutputPointer(other.output);
return fromPointer == otherFromPointer && inputPointer == otherInputPointer && pop == other.pop && shift == other.shift && toPointer == otherToPointer && outputPointer == otherOutputPointer && push == other.push;
}
 
bool UnknownTransition::operator !=(const UnknownTransition& other) const {
......@@ -168,15 +165,17 @@ bool UnknownTransition::operator !=(const UnknownTransition& other) const {
}
 
std::ostream& operator<<(std::ostream& out, const UnknownTransition& transition) {
out << "(UnknownTransition" << " from = ";
if(transition.from == NULL) out << "NULL"; else out << *transition.from;
out << " input = ";
if(transition.input == NULL) out << "NULL"; else out << *transition.input;
out << " to = ";
if(transition.to == NULL) out << "NULL"; else out << *transition.to;
out << " output = ";
if(transition.output == NULL) out << "NULL"; else out << *transition.output;
out << " pop = " << transition.pop
std::pointer<automaton::State> fromPointer(transition.from);
std::pointer<std::variant<string::Epsilon, alphabet::Symbol>> inputPointer(transition.input);
std::pointer<automaton::State> toPointer(transition.to);
std::pointer<std::variant<string::Epsilon, alphabet::Symbol>> outputPointer(transition.output);
out << "(UnknownTransition"
<< " from = " << fromPointer
<< " input = " << inputPointer
<< " to = " << toPointer
<< " output = " << outputPointer
<< " pop = " << transition.pop
<< " push = " << transition.push
<< " shift = " << SHIFT_NAMES[transition.shift]
<< ")";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment