diff --git a/alib2/src/automaton/Automaton.h b/alib2/src/automaton/Automaton.h index de12346e3b7ed4e76bac4b3949746f9f542b2ec4..eb0a3685d6601204438fe73a4732d0673fc408ac 100644 --- a/alib2/src/automaton/Automaton.h +++ b/alib2/src/automaton/Automaton.h @@ -28,7 +28,7 @@ protected: std::set<State> initialStates; std::set<State> finalStates; public: - virtual ~Automaton(); + virtual ~Automaton() noexcept; /** * Adds new state to the automaton. @@ -50,6 +50,7 @@ public: */ const std::set<State>& getStates() const; + /** * Adds input symbol to input alphabet. * @param symbol Symbol to add @@ -70,6 +71,7 @@ public: */ const std::set<alphabet::Symbol>& getInputAlphabet() const; + /** * Adds the State to the initial states. * @param state State to add diff --git a/alib2/src/automaton/UnknownAutomaton.cpp b/alib2/src/automaton/UnknownAutomaton.cpp index bde550712ba833e30b7673abf28d08a9eaf71afe..e890400b2666faedae605602ad3685475ba8b25c 100644 --- a/alib2/src/automaton/UnknownAutomaton.cpp +++ b/alib2/src/automaton/UnknownAutomaton.cpp @@ -19,19 +19,31 @@ UnknownAutomaton::UnknownAutomaton() : UnknownAutomaton::~UnknownAutomaton() { } +void UnknownAutomaton::setStates(const std::set<State>& states) { + this->states = states; +} + void UnknownAutomaton::removeState(const State& state) { if (!states.erase(state)) throw AutomatonException("State \"" + state.getName() + "\" doesn't exist."); } + +void UnknownAutomaton::addInputSymbol(const alphabet::Symbol& symbol) { + if (!inputAlphabet.insert(symbol).second) { + throw AutomatonException("Input symbol \"" + symbol.getSymbol() + "\" already exists."); + } +} + +void UnknownAutomaton::setInputSymbols(const std::set<alphabet::Symbol>& symbols) { + this->inputAlphabet = symbols; +} + void UnknownAutomaton::removeInputSymbol(const alphabet::Symbol& symbol) { if (!inputAlphabet.erase(symbol)) throw AutomatonException("Input symbol \"" + symbol.getSymbol() + "\" doesn't exist."); } -const std::set<alphabet::Symbol>& UnknownAutomaton::getStackAlphabet() const { - return stackAlphabet; -} void UnknownAutomaton::addStackSymbol(const alphabet::Symbol& symbol) { if (!stackAlphabet.insert(symbol).second) { @@ -39,29 +51,50 @@ void UnknownAutomaton::addStackSymbol(const alphabet::Symbol& symbol) { } } +void UnknownAutomaton::setStackSymbols(const std::set<alphabet::Symbol>& symbols) { + stackAlphabet = symbols; +} + void UnknownAutomaton::removeStackSymbol(const alphabet::Symbol& symbol) { if (!stackAlphabet.erase(symbol)) throw AutomatonException("Stack symbol \"" + symbol.getSymbol() + "\" doesn't exist."); } -const std::set<alphabet::Symbol>& UnknownAutomaton::getInitialSymbols() const { - return initialSymbols; +const std::set<alphabet::Symbol>& UnknownAutomaton::getStackAlphabet() const { + return stackAlphabet; +} + + +void UnknownAutomaton::addInitialSymbol(const alphabet::Symbol& symbol) { + if (!stackAlphabet.insert(symbol).second) { + throw AutomatonException("Stack symbol \"" + symbol.getSymbol() + "\" already exists."); + } } void UnknownAutomaton::setInitialSymbols(const std::set<alphabet::Symbol>& symbols) { this->initialSymbols = symbols; } -const std::set<alphabet::Symbol>& UnknownAutomaton::getTapeAlphabet() const { - return tapeAlphabet; +void UnknownAutomaton::removeInitialSymbol(const alphabet::Symbol& symbol) { + if (!stackAlphabet.erase(symbol)) + throw AutomatonException("Stack symbol \"" + symbol.getSymbol() + "\" doesn't exist."); +} + +const std::set<alphabet::Symbol>& UnknownAutomaton::getInitialSymbols() const { + return initialSymbols; } + void UnknownAutomaton::addTapeSymbol(const alphabet::Symbol& symbol) { if (!tapeAlphabet.insert(symbol).second) { throw AutomatonException("Tape symbol \"" + symbol.getSymbol() + "\" already exists."); } } +void UnknownAutomaton::setTapeAlphabet(const std::set<alphabet::Symbol>& symbols) { + tapeAlphabet = symbols; +} + void UnknownAutomaton::removeTapeSymbol(const alphabet::Symbol& symbol) { int removed = tapeAlphabet.erase(symbol); if (!removed) { @@ -69,18 +102,20 @@ void UnknownAutomaton::removeTapeSymbol(const alphabet::Symbol& symbol) { } } -const alphabet::Symbol& UnknownAutomaton::getBlankSymbol() const { - return blankSymbol; +const std::set<alphabet::Symbol>& UnknownAutomaton::getTapeAlphabet() const { + return tapeAlphabet; } + void UnknownAutomaton::setBlankSymbol(const alphabet::Symbol& symbol) { blankSymbol = symbol; } -const std::set<UnknownTransition>& UnknownAutomaton::getTransitions() const { - return transitions; +const alphabet::Symbol& UnknownAutomaton::getBlankSymbol() const { + return blankSymbol; } + void UnknownAutomaton::addTransition(const UnknownTransition& transition) { if (!transitions.insert(transition).second) { throw AutomatonException("Transition already exists."); @@ -93,4 +128,9 @@ void UnknownAutomaton::removeTransition(const UnknownTransition& transition) { } } +const std::set<UnknownTransition>& UnknownAutomaton::getTransitions() const { + return transitions; +} + } /* namespace automaton */ + diff --git a/alib2/src/automaton/UnknownAutomaton.h b/alib2/src/automaton/UnknownAutomaton.h index eaaee87f873d22f1c2b3b176b4beec21c3ead4d5..dc4bb3e8b770e6c549f7df7788ff3cacdbb844b5 100644 --- a/alib2/src/automaton/UnknownAutomaton.h +++ b/alib2/src/automaton/UnknownAutomaton.h @@ -5,8 +5,8 @@ * Author: Martin Zak */ -#ifndef UNKNOWNAUTOMATON_H_ -#define UNKNOWNAUTOMATON_H_ +#ifndef UNKNOWN_AUTOMATON_H_ +#define UNKNOWN_AUTOMATON_H_ #include <set> #include <list> @@ -33,6 +33,12 @@ public: UnknownAutomaton(); virtual ~UnknownAutomaton(); + /** + * Set new states of the automaton. + * @param states New states of the automaton + */ + void setStates(const std::set<State>& states); + /** * Removes the state from the automaton. * @param state State to remove @@ -40,6 +46,20 @@ public: */ void removeState(const State& state); + + /** + * Adds the input symbol to the automaton. + * @param symbol Symbol to add + * @throws AutomatonException when symbol is already present in the automaton + */ + void addInputSymbol(const alphabet::Symbol& symbol); + + /** + * Sets the input symbols of the automaton. + * @param symbols Symbol to be new input symbol of the automaton + */ + void setInputSymbols(const std::set<alphabet::Symbol>& symbols); + /** * Removes input symbol from the input alphabet. * @param symbol Symbol to remove @@ -47,10 +67,6 @@ public: */ void removeInputSymbol(const alphabet::Symbol& symbol); - /** - * @return the stack alphabet - */ - const std::set<alphabet::Symbol>& getStackAlphabet() const; /** * Adds symbol to the stack alphabet. @@ -59,6 +75,12 @@ public: */ void addStackSymbol(const alphabet::Symbol& symbol); + /** + * Sets symbols of the stack alphabet. + * @param symbol Symbol to add + */ + void setStackSymbols(const std::set<alphabet::Symbol>& symbols); + /** * Removes symbol from the stack alphabet. * @param symbol Symbol to remove @@ -67,9 +89,17 @@ public: void removeStackSymbol(const alphabet::Symbol& symbol); /** - * @return list of initial symbols + * @return the stack alphabet */ - const std::set<alphabet::Symbol>& getInitialSymbols() const; + const std::set<alphabet::Symbol>& getStackAlphabet() const; + + + /** + * Adds symbol to the set of initial stack symbols. + * @param symbol Symbol to add + * @throw AutomatonException when Symbol is already present in the set of initial symbols + */ + void addInitialSymbol(const alphabet::Symbol& symbol); /** * Set the initial symbol list. @@ -78,9 +108,17 @@ public: void setInitialSymbols(const std::set<alphabet::Symbol>& symbols); /** - * @return the tape alphabet + * Removes symbol from the set of initial stack symbols. + * @param symbol Symbol to remove + * @throw AutomatonException when Symbol is not present in the set of initial symbols */ - const std::set<alphabet::Symbol>& getTapeAlphabet() const; + void removeInitialSymbol(const alphabet::Symbol& symbol); + + /** + * @return list of initial symbols + */ + const std::set<alphabet::Symbol>& getInitialSymbols() const; + /** * Adds symbol to the tape alphabet. @@ -89,6 +127,12 @@ public: */ void addTapeSymbol(const alphabet::Symbol& symbol); + /** + * Sets the tape alphabet. + * @param symbols Symbols to become new tape alphabet + */ + void setTapeAlphabet(const std::set<alphabet::Symbol>& symbols); + /** * Removes symbol from the tape alphabet. * @param symbol Symbol to remove @@ -97,9 +141,10 @@ public: void removeTapeSymbol(const alphabet::Symbol& symbol); /** - * @return the blank symbol + * @return the tape alphabet */ - const alphabet::Symbol& getBlankSymbol() const; + const std::set<alphabet::Symbol>& getTapeAlphabet() const; + /** * Sets the blank symbol. @@ -108,9 +153,10 @@ public: void setBlankSymbol(const alphabet::Symbol& symbol); /** - * @return transitions of the automaton + * @return the blank symbol */ - const std::set<UnknownTransition>& getTransitions() const; + const alphabet::Symbol& getBlankSymbol() const; + /** * Adds new transition to the automaton. @@ -126,7 +172,13 @@ public: */ void removeTransition(const UnknownTransition& transition); + /** + * @return transitions of the automaton + */ + const std::set<UnknownTransition>& getTransitions() const; + }; } /* namespace automaton */ -#endif /* UNKNOWNAUTOMATON_H_ */ + +#endif /* UNKNOWN_AUTOMATON_H_ */