diff --git a/alib2data/src/automaton/FSM/CompactNFA.cpp b/alib2data/src/automaton/FSM/CompactNFA.cpp index b2d8c4266dad5cefd37b6cd2bbcc0fcb5973cc74..7de169a84e2ae9c7b6ad8fcc522a70e4f2291cd0 100644 --- a/alib2data/src/automaton/FSM/CompactNFA.cpp +++ b/alib2data/src/automaton/FSM/CompactNFA.cpp @@ -97,9 +97,8 @@ bool CompactNFA::removeState(const State& state) { } bool CompactNFA::removeInputSymbol(const alphabet::Symbol& symbol) { - for (std::map<std::pair<State, string::LinearString>, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->first.second.getAlphabet().count(symbol) == 1) + for (const std::pair<std::pair<State, string::LinearString>, std::set<State> >& transition : transitions) { + if (transition.first.second.getAlphabet().count(symbol) == 1) throw AutomatonException("Input symbol \"" + (std::string) symbol + "\" is used."); } @@ -139,10 +138,9 @@ std::map<std::pair<State, string::LinearString>, std::set<State>> CompactNFA::ge throw AutomatonException("State \"" + (std::string) from.getName() + "\" doesn't exist"); std::map<std::pair<State, string::LinearString>, std::set<State>> transitionsFromState; - for (std::map<std::pair<State, string::LinearString>, std::set<State>>::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->first.first == from) { - transitionsFromState.insert(make_pair(transition->first, transition->second)); + for (const std::pair<std::pair<State, string::LinearString>, std::set<State>>& transition : transitions) { + if (transition.first.first == from) { + transitionsFromState.insert(make_pair(transition.first, transition.second)); } } @@ -154,10 +152,9 @@ std::map<std::pair<State, string::LinearString>, std::set<State>> CompactNFA::ge throw AutomatonException("State \"" + (std::string) to.getName() + "\" doesn't exist"); std::map<std::pair<State, string::LinearString>, std::set<State>> transitionsToState; - for (std::map<std::pair<State, string::LinearString>, std::set<State>>::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->second.find(to) != transition->second.end()) { - transitionsToState.insert(make_pair(transition->first, transition->second)); + for (const std::pair<std::pair<State, string::LinearString>, std::set<State>>& transition : transitions) { + if (transition.second.find(to) != transition.second.end()) { + transitionsToState.insert(make_pair(transition.first, transition.second)); } } diff --git a/alib2data/src/automaton/FSM/EpsilonNFA.cpp b/alib2data/src/automaton/FSM/EpsilonNFA.cpp index 4601d595a996256750ec45efbdda2ac935ea37b3..284910659e921d813b2084fad4eabbe786f8a607 100644 --- a/alib2data/src/automaton/FSM/EpsilonNFA.cpp +++ b/alib2data/src/automaton/FSM/EpsilonNFA.cpp @@ -71,8 +71,8 @@ bool EpsilonNFA::removeState(const State& state) { throw AutomatonException("State \"" + (std::string) state.getName() + "\" is final state."); } - for (std::map<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> >::const_iterator t = transitions.begin(); t != transitions.end(); t++) { - if (t->first.first == state || t->second.find(state) != t->second.end()) + for (const std::pair<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> >& transition : transitions) { + if (transition.first.first == state || transition.second.find(state) != transition.second.end()) throw AutomatonException("State \"" + (std::string) state.getName() + "\" is used in transition."); } @@ -81,9 +81,8 @@ bool EpsilonNFA::removeState(const State& state) { bool EpsilonNFA::removeInputSymbol(const alphabet::Symbol& symbol) { std::variant<string::Epsilon, alphabet::Symbol> inputVariant(symbol); - for (std::map<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->first.second.is<alphabet::Symbol>() && transition->first.second.get<alphabet::Symbol>() == symbol) + for (const std::pair<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> >& transition : transitions) { + if (transition.first.second.is<alphabet::Symbol>() && transition.first.second.get<alphabet::Symbol>() == symbol) throw AutomatonException("Input symbol \"" + (std::string) symbol + "\" is used."); } @@ -135,20 +134,18 @@ const std::map<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> std::map<State, std::set<State> > EpsilonNFA::getEpsilonTransitions() const { std::map<State, std::set<State> > result; - for (std::map<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->first.second.is<string::Epsilon>()) - result[transition->first.first].insert(transition->second.begin(), transition->second.end()); + for (const std::pair<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> >& transition : transitions) { + if (transition.first.second.is<string::Epsilon>()) + result[transition.first.first].insert(transition.second.begin(), transition.second.end()); } return result; } std::map<std::pair<State, alphabet::Symbol>, std::set<State> > EpsilonNFA::getSymbolTransitions() const { std::map<std::pair<State, alphabet::Symbol>, std::set<State> > result; - for (std::map<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->first.second.is<alphabet::Symbol>()) - result[std::pair<State, alphabet::Symbol>(transition->first.first, transition->first.second.get<alphabet::Symbol>())].insert(transition->second.begin(), transition->second.end()); + for (const std::pair<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> >& transition : transitions) { + if (transition.first.second.is<alphabet::Symbol>()) + result[std::pair<State, alphabet::Symbol>(transition.first.first, transition.first.second.get<alphabet::Symbol>())].insert(transition.second.begin(), transition.second.end()); } return result; } @@ -158,11 +155,9 @@ std::map<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std throw AutomatonException("State \"" + (std::string) from.getName() + "\" doesn't exist"); std::map<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> > transitionsFromState; - for (std::map<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->first.first == from) { - transitionsFromState[transition->first].insert(transition->second.begin(), transition->second.end()); - } + for (const std::pair<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> >& transition : transitions) { + if (transition.first.first == from) + transitionsFromState[transition.first].insert(transition.second.begin(), transition.second.end()); } return transitionsFromState; @@ -185,11 +180,9 @@ std::map<std::pair<State, alphabet::Symbol>, std::set<State> > EpsilonNFA::getSy throw AutomatonException("State \"" + (std::string) from.getName() + "\" doesn't exist"); std::map<std::pair<State, alphabet::Symbol>, std::set<State> > transitionsFromState; - for (std::map<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->first.first == from && transition->first.second.is<alphabet::Symbol>()) { - transitionsFromState[std::pair<State, alphabet::Symbol>(transition->first.first, transition->first.second.get<alphabet::Symbol>())].insert(transition->second.begin(), transition->second.end()); - } + for (const std::pair<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> >& transition : transitions) { + if (transition.first.first == from && transition.first.second.is<alphabet::Symbol>()) + transitionsFromState[std::pair<State, alphabet::Symbol>(transition.first.first, transition.first.second.get<alphabet::Symbol>())].insert(transition.second.begin(), transition.second.end()); } return transitionsFromState; @@ -200,11 +193,9 @@ std::map<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std throw AutomatonException("State \"" + (std::string) to.getName() + "\" doesn't exist"); std::map<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> > transitionsToState; - for (std::map<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->second.find(to) != transition->second.end()) { - transitionsToState[transition->first].insert(transition->second.begin(), transition->second.end()); - } + for (const std::pair<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> >& transition : transitions) { + if (transition.second.find(to) != transition.second.end()) + transitionsToState[transition.first].insert(transition.second.begin(), transition.second.end()); } return transitionsToState; @@ -215,11 +206,9 @@ std::map<State, std::set<State> > EpsilonNFA::getEpsilonTransitionsToState(const throw AutomatonException("State \"" + (std::string) to.getName() + "\" doesn't exist"); std::map<State, std::set<State> > transitionsToState; - for (std::map<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->second.find(to) != transition->second.end() && transition->first.second.is<string::Epsilon>()) { - transitionsToState[transition->first.first].insert(transition->second.begin(), transition->second.end()); - } + for (const std::pair<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> >& transition : transitions) { + if (transition.second.find(to) != transition.second.end() && transition.first.second.is<string::Epsilon>()) + transitionsToState[transition.first.first].insert(transition.second.begin(), transition.second.end()); } return transitionsToState; @@ -230,32 +219,26 @@ std::map<std::pair<State, alphabet::Symbol>, std::set<State> > EpsilonNFA::getSy throw AutomatonException("State \"" + (std::string) to.getName() + "\" doesn't exist"); std::map<std::pair<State, alphabet::Symbol>, std::set<State> > transitionsToState; - for (std::map<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->second.find(to) != transition->second.end() && transition->first.second.is<alphabet::Symbol>()) { - transitionsToState[std::pair<State, alphabet::Symbol>(transition->first.first, transition->first.second.get<alphabet::Symbol>())].insert(transition->second.begin(), transition->second.end()); - } + for (const std::pair<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> >& transition : transitions) { + if (transition.second.find(to) != transition.second.end() && transition.first.second.is<alphabet::Symbol>()) + transitionsToState[std::pair<State, alphabet::Symbol>(transition.first.first, transition.first.second.get<alphabet::Symbol>())].insert(transition.second.begin(), transition.second.end()); } return transitionsToState; } bool EpsilonNFA::isEpsilonFree() const { - for (std::map<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->first.second.is<string::Epsilon>()) { + for (const std::pair<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> >& transition : transitions) { + if (transition.first.second.is<string::Epsilon>()) return false; - } } return true; } bool EpsilonNFA::isDeterministic() const { - for (std::map<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->second.size() != 1 || transition->second.size() != 0) { + for (const std::pair<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> >& transition : transitions) { + if (transition.second.size() != 1 || transition.second.size() != 0) return false; - } } return true; diff --git a/alib2data/src/automaton/FSM/ExtendedNFA.cpp b/alib2data/src/automaton/FSM/ExtendedNFA.cpp index 14b34fcbd994593d77bda79cfa930406bee66833..8f64c22153ef1f1cbfea6ed7e3ce881fc62930fa 100644 --- a/alib2data/src/automaton/FSM/ExtendedNFA.cpp +++ b/alib2data/src/automaton/FSM/ExtendedNFA.cpp @@ -100,8 +100,8 @@ bool ExtendedNFA::removeState(const State& state) { throw AutomatonException("State \"" + (std::string) state.getName() + "\" is final state."); } - for (std::map<std::pair<State, regexp::RegExp>, std::set<State> >::const_iterator t = transitions.begin(); t != transitions.end(); t++) { - if (t->first.first == state || t->second.find(state) != t->second.end()) + for (const std::pair<std::pair<State, regexp::RegExp>, std::set<State> >& transition : transitions) { + if (transition.first.first == state || transition.second.find(state) != transition.second.end()) throw AutomatonException("State \"" + (std::string) state.getName() + "\" is used in transition."); } @@ -109,9 +109,8 @@ bool ExtendedNFA::removeState(const State& state) { } bool ExtendedNFA::removeInputSymbol(const alphabet::Symbol& symbol) { - for (std::map<std::pair<State, regexp::RegExp>, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (regexp::RegExpAlphabetGetter::REG_EXP_ALPHABET_GETTER.getAlphabet(transition->first.second).count(symbol) == 1) + for (const std::pair<std::pair<State, regexp::RegExp>, std::set<State> >& transition : transitions) { + if (regexp::RegExpAlphabetGetter::REG_EXP_ALPHABET_GETTER.getAlphabet(transition.first.second).count(symbol) == 1) throw AutomatonException("Input symbol \"" + (std::string) symbol + "\" is used."); } @@ -151,11 +150,9 @@ std::map<std::pair<State, regexp::RegExp>, std::set<State> > ExtendedNFA::getTra throw AutomatonException("State \"" + (std::string) from.getName() + "\" doesn't exist"); std::map<std::pair<State, regexp::RegExp>, std::set<State>> transitionsFromState; - for (std::map<std::pair<State, regexp::RegExp>, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->first.first == from) { - transitionsFromState.insert(make_pair(transition->first, transition->second)); - } + for (const std::pair<std::pair<State, regexp::RegExp>, std::set<State> >& transition : transitions) { + if (transition.first.first == from) + transitionsFromState.insert(make_pair(transition.first, transition.second)); } return transitionsFromState; @@ -166,11 +163,9 @@ std::map<std::pair<State, regexp::RegExp>, std::set<State> > ExtendedNFA::getTra throw AutomatonException("State \"" + (std::string) to.getName() + "\" doesn't exist"); std::map<std::pair<State, regexp::RegExp>, std::set<State>> transitionsToState; - for (std::map<std::pair<State, regexp::RegExp>, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->second.find(to) != transition->second.end()) { - transitionsToState.insert(make_pair(transition->first, transition->second)); - } + for (const std::pair<std::pair<State, regexp::RegExp>, std::set<State> >& transition : transitions) { + if (transition.second.find(to) != transition.second.end()) + transitionsToState.insert(make_pair(transition.first, transition.second)); } return transitionsToState; diff --git a/alib2data/src/automaton/FSM/MultiInitialStateNFA.cpp b/alib2data/src/automaton/FSM/MultiInitialStateNFA.cpp index 58447e8b100d6398513b6b988584bec45b0ba7cb..8c13cce3ab0a928fa9f0b232249338b9126b3131 100644 --- a/alib2data/src/automaton/FSM/MultiInitialStateNFA.cpp +++ b/alib2data/src/automaton/FSM/MultiInitialStateNFA.cpp @@ -55,8 +55,8 @@ bool MultiInitialStateNFA::removeState(const State& state) { throw AutomatonException("State \"" + (std::string) state.getName() + "\" is final state."); } - for (std::map<std::pair<State, alphabet::Symbol>, std::set<State> >::const_iterator t = transitions.begin(); t != transitions.end(); t++) { - if (t->first.first == state || t->second.find(state) != t->second.end()) + for (const std::pair<std::pair<State, alphabet::Symbol>, std::set<State> >& transition : transitions) { + if (transition.first.first == state || transition.second.find(state) != transition.second.end()) throw AutomatonException("State \"" + (std::string) state.getName() + "\" is used in transition."); } @@ -64,9 +64,8 @@ bool MultiInitialStateNFA::removeState(const State& state) { } bool MultiInitialStateNFA::removeInputSymbol(const alphabet::Symbol& symbol) { - for (std::map<std::pair<State, alphabet::Symbol>, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->first.second == symbol) + for (const std::pair<std::pair<State, alphabet::Symbol>, std::set<State> >& transition : transitions) { + if (transition.first.second == symbol) throw AutomatonException("Input symbol \"" + (std::string) symbol + "\" is used."); } @@ -103,11 +102,9 @@ std::map<std::pair<State, alphabet::Symbol>, std::set<State> > MultiInitialState throw AutomatonException("State \"" + (std::string) from.getName() + "\" doesn't exist"); std::map<std::pair<State, alphabet::Symbol>, std::set<State> > transitionsFromState; - for (std::map<std::pair<State, alphabet::Symbol>, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->first.first == from) { - transitionsFromState[transition->first].insert(transition->second.begin(), transition->second.end()); - } + for (const std::pair<std::pair<State, alphabet::Symbol>, std::set<State> >& transition : transitions) { + if (transition.first.first == from) + transitionsFromState[transition.first].insert(transition.second.begin(), transition.second.end()); } return transitionsFromState; @@ -118,11 +115,9 @@ std::map<std::pair<State, alphabet::Symbol>, std::set<State> > MultiInitialState throw AutomatonException("State \"" + (std::string) to.getName() + "\" doesn't exist"); std::map<std::pair<State, alphabet::Symbol>, std::set<State> > transitionsToState; - for (std::map<std::pair<State, alphabet::Symbol>, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->second.find(to) != transition->second.end()) { - transitionsToState[transition->first].insert(transition->second.begin(), transition->second.end()); - } + for (const std::pair<std::pair<State, alphabet::Symbol>, std::set<State> >& transition : transitions) { + if (transition.second.find(to) != transition.second.end()) + transitionsToState[transition.first].insert(transition.second.begin(), transition.second.end()); } return transitionsToState; @@ -133,11 +128,9 @@ bool MultiInitialStateNFA::isDeterministic() const { return false; } - for (std::map<std::pair<State, alphabet::Symbol>, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->second.size() != 1 || transition->second.size() != 0) { + for (const std::pair<std::pair<State, alphabet::Symbol>, std::set<State> >& transition : transitions) { + if (transition.second.size() != 1 || transition.second.size() != 0) return false; - } } return true; diff --git a/alib2data/src/automaton/FSM/NFA.cpp b/alib2data/src/automaton/FSM/NFA.cpp index 42b76332d80c81c84a16c2fb27d97da69f429982..215aa83490ce9da18eb1a8976e3f15f16b5ef542 100644 --- a/alib2data/src/automaton/FSM/NFA.cpp +++ b/alib2data/src/automaton/FSM/NFA.cpp @@ -42,8 +42,8 @@ bool NFA::removeState(const State& state) { throw AutomatonException("State \"" + (std::string) state.getName() + "\" is final state."); } - for (std::map<std::pair<State, alphabet::Symbol>, std::set<State> >::const_iterator t = transitions.begin(); t != transitions.end(); t++) { - if (t->first.first == state || t->second.find(state) != t->second.end()) + for (const std::pair<std::pair<State, alphabet::Symbol>, std::set<State> >& transition : transitions) { + if (transition.first.first == state || transition.second.find(state) != transition.second.end()) throw AutomatonException("State \"" + (std::string) state.getName() + "\" is used in transition."); } @@ -51,9 +51,8 @@ bool NFA::removeState(const State& state) { } bool NFA::removeInputSymbol(const alphabet::Symbol& symbol) { - for (std::map<std::pair<State, alphabet::Symbol>, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->first.second == symbol) + for (const std::pair<std::pair<State, alphabet::Symbol>, std::set<State> >& transition : transitions) { + if (transition.first.second == symbol) throw AutomatonException("Input symbol \"" + (std::string) symbol + "\" is used."); } @@ -90,11 +89,9 @@ std::map<std::pair<State, alphabet::Symbol>, std::set<State> > NFA::getTransitio throw AutomatonException("State \"" + (std::string) from.getName() + "\" doesn't exist"); std::map<std::pair<State, alphabet::Symbol>, std::set<State> > transitionsFromState; - for (std::map<std::pair<State, alphabet::Symbol>, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->first.first == from) { - transitionsFromState[transition->first].insert(transition->second.begin(), transition->second.end()); - } + for (const std::pair<std::pair<State, alphabet::Symbol>, std::set<State> >& transition : transitions) { + if (transition.first.first == from) + transitionsFromState[transition.first].insert(transition.second.begin(), transition.second.end()); } return transitionsFromState; @@ -105,22 +102,18 @@ std::map<std::pair<State, alphabet::Symbol>, std::set<State> > NFA::getTransitio throw AutomatonException("State \"" + (std::string) to.getName() + "\" doesn't exist"); std::map<std::pair<State, alphabet::Symbol>, std::set<State> > transitionsToState; - for (std::map<std::pair<State, alphabet::Symbol>, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->second.find(to) != transition->second.end()) { - transitionsToState[transition->first].insert(transition->second.begin(), transition->second.end()); - } + for (const std::pair<std::pair<State, alphabet::Symbol>, std::set<State> >& transition : transitions) { + if (transition.second.find(to) != transition.second.end()) + transitionsToState[transition.first].insert(transition.second.begin(), transition.second.end()); } return transitionsToState; } bool NFA::isDeterministic() const { - for (std::map<std::pair<State, alphabet::Symbol>, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->second.size() != 1 || transition->second.size() != 0) { + for (const std::pair<std::pair<State, alphabet::Symbol>, std::set<State> >& transition : transitions) { + if (transition.second.size() != 1 || transition.second.size() != 0) return false; - } } return true; diff --git a/alib2data/src/automaton/PDA/DPDA.cpp b/alib2data/src/automaton/PDA/DPDA.cpp index be0e9012c4002c9833d484f3dc1c9cebb89abbe9..e6d3ad8543e256099ab6c986ed9cb83e05a2acbb 100644 --- a/alib2data/src/automaton/PDA/DPDA.cpp +++ b/alib2data/src/automaton/PDA/DPDA.cpp @@ -34,10 +34,10 @@ bool DPDA::removeState(const State& state) { throw AutomatonException("State \"" + (std::string) state.getName() + "\" is final state."); } - for (std::map<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<State, std::vector<alphabet::Symbol> > >::const_iterator transition = transitions.begin(); transition != transitions.end(); transition++) { - if (state == std::get<0>(transition->first)) + for (const std::pair<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<State, std::vector<alphabet::Symbol> > >& transition : transitions) { + if (state == std::get<0>(transition.first)) throw AutomatonException("State \"" + (std::string) state.getName() + "\" is used in transition."); - if( transition->second.first == state) + if( transition.second.first == state) throw AutomatonException("State \"" + (std::string) state.getName() + "\" is used in transition."); } @@ -45,8 +45,8 @@ bool DPDA::removeState(const State& state) { } bool DPDA::removeInputSymbol(const alphabet::Symbol& symbol) { - for (std::map<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<State, std::vector<alphabet::Symbol> > >::const_iterator transition = transitions.begin(); transition != transitions.end(); transition++) { - if (std::get<1>(transition->first).is<alphabet::Symbol>() && symbol == std::get<1>(transition->first).get<alphabet::Symbol>()) + for (const std::pair<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<State, std::vector<alphabet::Symbol> > >& transition : transitions) { + if (std::get<1>(transition.first).is<alphabet::Symbol>() && symbol == std::get<1>(transition.first).get<alphabet::Symbol>()) throw AutomatonException("Symbol \"" + (std::string) symbol + "\" is used in transition."); } @@ -54,13 +54,12 @@ bool DPDA::removeInputSymbol(const alphabet::Symbol& symbol) { } bool DPDA::removeStackSymbol(const alphabet::Symbol& symbol) { - for (std::map<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<State, std::vector<alphabet::Symbol> > >::const_iterator transition = transitions.begin(); transition != transitions.end(); transition++) { - for (std::vector<alphabet::Symbol>::const_iterator popSymbol = std::get<2>(transition->first).begin(); popSymbol != std::get<2>(transition->first).end(); - popSymbol++) { - if (symbol == *popSymbol) + for (const std::pair<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<State, std::vector<alphabet::Symbol> > >& transition : transitions) { + for (const alphabet::Symbol& popSymbol : std::get<2>(transition.first)) { + if (symbol == popSymbol) throw AutomatonException("Stack symbol \"" + (std::string) symbol + "\" is used in transition."); } - if (std::find(transition->second.second.begin(), transition->second.second.end(), symbol) != transition->second.second.end()) + if (std::find(transition.second.second.begin(), transition.second.second.end(), symbol) != transition.second.second.end()) throw AutomatonException("Stack symbol \"" + (std::string) symbol + "\" is used in transition."); } @@ -84,21 +83,21 @@ bool DPDA::addTransition(const State& from, const std::variant<string::Epsilon, throw AutomatonException("State \"" + (std::string) to.getName() + "\" doesn't exist."); } - for(std::vector<alphabet::Symbol>::const_iterator popSymbol = pop.begin(); popSymbol != pop.end(); popSymbol++) { - if (stackAlphabet.find(*popSymbol) == stackAlphabet.end()) { - throw AutomatonException("Stack symbol \"" + (std::string) *popSymbol + "\" doesn't exist."); + for(const alphabet::Symbol& popSymbol : pop) { + if (stackAlphabet.find(popSymbol) == stackAlphabet.end()) { + throw AutomatonException("Stack symbol \"" + (std::string) popSymbol + "\" doesn't exist."); } } - for(std::vector<alphabet::Symbol>::const_iterator pushSymbol = push.begin(); pushSymbol != push.end(); pushSymbol++) { - if (stackAlphabet.find(*pushSymbol) == stackAlphabet.end()) { - throw AutomatonException("Stack symbol \"" + (std::string) *pushSymbol + "\" doesn't exist."); + for(const alphabet::Symbol& pushSymbol : push) { + if (stackAlphabet.find(pushSymbol) == stackAlphabet.end()) { + throw AutomatonException("Stack symbol \"" + (std::string) pushSymbol + "\" doesn't exist."); } } std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> > key(from, input, pop); std::pair<automaton::State, std::vector<alphabet::Symbol> > value = std::make_pair(to, push); - + if (transitions.find(key) != transitions.end()) { if(transitions.find(key)->second == value) return false; @@ -199,9 +198,9 @@ std::map<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, std: throw AutomatonException("State \"" + (std::string) from.getName() + "\" doesn't exist"); std::map<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<State, std::vector<alphabet::Symbol> > > transitionsFromState; - for (auto transition = transitions.begin(); transition != transitions.end(); transition++) { - if (std::get<0>(transition->first) == from) { - transitionsFromState.insert(std::make_pair(transition->first, transition->second)); + for (const std::pair<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<State, std::vector<alphabet::Symbol> > >& transition : transitions) { + if (std::get<0>(transition.first) == from) { + transitionsFromState.insert(std::make_pair(transition.first, transition.second)); } } @@ -213,9 +212,9 @@ std::map<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, std: throw AutomatonException("State \"" + (std::string) to.getName() + "\" doesn't exist"); std::map<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<State, std::vector<alphabet::Symbol> > > transitionsToState; - for (auto transition = transitions.begin(); transition != transitions.end(); transition++) { - if (transition->second.first == to) { - transitionsToState.insert(std::make_pair(transition->first, transition->second)); + for (const std::pair<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<State, std::vector<alphabet::Symbol> > >& transition : transitions) { + if (transition.second.first == to) { + transitionsToState.insert(std::make_pair(transition.first, transition.second)); } } diff --git a/alib2data/src/automaton/PDA/InputDrivenNPDA.cpp b/alib2data/src/automaton/PDA/InputDrivenNPDA.cpp index 2c35eb615b9245dff24f482e49d6c3b7961cd8d7..d0fbcfac96b5e9094ab20037fbaa78150c40fc79 100644 --- a/alib2data/src/automaton/PDA/InputDrivenNPDA.cpp +++ b/alib2data/src/automaton/PDA/InputDrivenNPDA.cpp @@ -34,8 +34,8 @@ bool InputDrivenNPDA::removeState(const State& state) { throw AutomatonException("State \"" + (std::string) state.getName() + "\" is final state."); } - for (std::map<std::pair<State, alphabet::Symbol>, std::set<State> >::const_iterator t = transitions.begin(); t != transitions.end(); t++) { - if (t->first.first == state || t->second.find(state) != t->second.end()) + for (const std::pair<std::pair<State, alphabet::Symbol>, std::set<State> >& transition : transitions) { + if (transition.first.first == state || transition.second.find(state) != transition.second.end()) throw AutomatonException("State \"" + (std::string) state.getName() + "\" is used in transition."); } @@ -43,9 +43,8 @@ bool InputDrivenNPDA::removeState(const State& state) { } bool InputDrivenNPDA::removeInputSymbol(const alphabet::Symbol& symbol) { - for (std::map<std::pair<State, alphabet::Symbol>, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->first.second == symbol) + for (const std::pair<std::pair<State, alphabet::Symbol>, std::set<State> >& transition : transitions) { + if (transition.first.second == symbol) throw AutomatonException("Input symbol \"" + (std::string) symbol + "\" is used."); } @@ -72,15 +71,15 @@ bool InputDrivenNPDA::setPushdownStoreOperation(const alphabet::Symbol& input, c throw AutomatonException("Input symbol \"" + (std::string) input + "\" doesn't exist."); } - for(std::vector<alphabet::Symbol>::const_iterator popSymbol = pop.begin(); popSymbol != pop.end(); popSymbol++) { - if (stackAlphabet.find(*popSymbol) == stackAlphabet.end()) { - throw AutomatonException("Stack symbol \"" + (std::string) *popSymbol + "\" doesn't exist."); + for(const alphabet::Symbol& popSymbol : pop) { + if (stackAlphabet.find(popSymbol) == stackAlphabet.end()) { + throw AutomatonException("Stack symbol \"" + (std::string) popSymbol + "\" doesn't exist."); } } - for(std::vector<alphabet::Symbol>::const_iterator pushSymbol = push.begin(); pushSymbol != push.end(); pushSymbol++) { - if (stackAlphabet.find(*pushSymbol) == stackAlphabet.end()) { - throw AutomatonException("Stack symbol \"" + (std::string) *pushSymbol + "\" doesn't exist."); + for(const alphabet::Symbol& pushSymbol : push) { + if (stackAlphabet.find(pushSymbol) == stackAlphabet.end()) { + throw AutomatonException("Stack symbol \"" + (std::string) pushSymbol + "\" doesn't exist."); } } @@ -101,9 +100,8 @@ void InputDrivenNPDA::setPushdownStoreOperations(const std::map<alphabet::Symbol } bool InputDrivenNPDA::clearPushdownStoreOperation(const alphabet::Symbol& input) { - for (std::map<std::pair<State, alphabet::Symbol>, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->first.second == input) + for (const std::pair<std::pair<State, alphabet::Symbol>, std::set<State> >& transition : transitions) { + if (transition.first.second == input) throw AutomatonException("Input symbol \"" + (std::string) input + "\" is used."); } @@ -147,10 +145,9 @@ std::map<std::pair<State, alphabet::Symbol>, std::set<State> > InputDrivenNPDA:: throw AutomatonException("State \"" + (std::string) from.getName() + "\" doesn't exist"); std::map<std::pair<State, alphabet::Symbol>, std::set<State> > transitionsFromState; - for (std::map<std::pair<State, alphabet::Symbol>, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->first.first == from) { - transitionsFromState[transition->first].insert(transition->second.begin(), transition->second.end()); + for (const std::pair<std::pair<State, alphabet::Symbol>, std::set<State> >& transition : transitions) { + if (transition.first.first == from) { + transitionsFromState[transition.first].insert(transition.second.begin(), transition.second.end()); } } @@ -162,10 +159,9 @@ std::map<std::pair<State, alphabet::Symbol>, std::set<State> > InputDrivenNPDA:: throw AutomatonException("State \"" + (std::string) to.getName() + "\" doesn't exist"); std::map<std::pair<State, alphabet::Symbol>, std::set<State> > transitionsToState; - for (std::map<std::pair<State, alphabet::Symbol>, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->second.find(to) != transition->second.end()) { - transitionsToState[transition->first].insert(transition->second.begin(), transition->second.end()); + for (const std::pair<std::pair<State, alphabet::Symbol>, std::set<State> >& transition : transitions) { + if (transition.second.find(to) != transition.second.end()) { + transitionsToState[transition.first].insert(transition.second.begin(), transition.second.end()); } } @@ -173,9 +169,8 @@ std::map<std::pair<State, alphabet::Symbol>, std::set<State> > InputDrivenNPDA:: } bool InputDrivenNPDA::isDeterministic() const { - for (std::map<std::pair<State, alphabet::Symbol>, std::set<State> >::const_iterator transition = transitions.begin(); transition != transitions.end(); - transition++) { - if (transition->second.size() != 1 || transition->second.size() != 0) { + for (const std::pair<std::pair<State, alphabet::Symbol>, std::set<State> >& transition : transitions) { + if (transition.second.size() != 1 || transition.second.size() != 0) { return false; } }