diff --git a/alib2data/src/automaton/FSM/ExtendedNFA.cpp b/alib2data/src/automaton/FSM/ExtendedNFA.cpp index 356765631d9627019be69dc88ee531bc9dce78a3..e37ca4e82dc098bb1624e03f9173a566a12f9e22 100644 --- a/alib2data/src/automaton/FSM/ExtendedNFA.cpp +++ b/alib2data/src/automaton/FSM/ExtendedNFA.cpp @@ -16,7 +16,6 @@ #include "../../regexp/RegExp.h" #include <ostream> #include <algorithm> -#include "../../regexp/RegExpAlphabetGetter.h" #include <sstream> #include "../../sax/FromXMLParserHelper.h" @@ -116,7 +115,7 @@ bool ExtendedNFA::removeState(const State& state) { bool ExtendedNFA::removeInputSymbol(const alphabet::Symbol& symbol) { for (const std::pair<std::pair<State, regexp::RegExp>, std::set<State> >& transition : transitions) { - if (regexp::RegExpAlphabetGetter::getAlphabet(transition.first.second).count(symbol) == 1) + if (transition.first.second.getAlphabet().count(symbol) == 1) throw AutomatonException("Input symbol \"" + (std::string) symbol + "\" is used."); } @@ -127,7 +126,7 @@ bool ExtendedNFA::addTransition(State from, regexp::RegExp input, State to) { if (states.find(from) == states.end()) throw AutomatonException("State \"" + (std::string) from.getName() + "\" doesn't exist."); - const std::set<alphabet::Symbol>& inputRegExpAlphabet = regexp::RegExpAlphabetGetter::getAlphabet(input); + const std::set<alphabet::Symbol>& inputRegExpAlphabet = input.getAlphabet(); // Transition regexp's alphabet must be subset of automaton's alphabet if (inputRegExpAlphabet.size() > 0 && ! std::includes(inputAlphabet.begin(), inputAlphabet.end(), inputRegExpAlphabet.begin(), inputRegExpAlphabet.end())) diff --git a/alib2data/src/regexp/RegExp.cpp b/alib2data/src/regexp/RegExp.cpp index 93b9870825081be4786b543214c6cb345f9dcbba..0794884e5478ee8ec3650748a35c5bc8af68603b 100644 --- a/alib2data/src/regexp/RegExp.cpp +++ b/alib2data/src/regexp/RegExp.cpp @@ -16,6 +16,10 @@ namespace regexp { +const std::set<alphabet::Symbol>& RegExp::getAlphabet() const { + return this->getData().getAlphabet(); +} + regexp::RegExp regexpFrom( const std::string & string ) { regexp::UnboundedRegExpConcatenation con; for(const char& symbol : string) { diff --git a/alib2data/src/regexp/RegExp.h b/alib2data/src/regexp/RegExp.h index 2be1c82596b064a983aa7ea023a12457288d2573..fd6d99434a5d3b9d4ce0f2b82e229521f7391212 100644 --- a/alib2data/src/regexp/RegExp.h +++ b/alib2data/src/regexp/RegExp.h @@ -15,6 +15,7 @@ #include "../alphabet/SymbolFeatures.h" #include "../string/StringFeatures.h" #include <string> +#include <set> namespace regexp { @@ -23,6 +24,8 @@ namespace regexp { */ class RegExp : public alib::wrapper<RegExpBase>, public alib::WrapperBase { using alib::wrapper<RegExpBase>::wrapper; +public: + const std::set<alphabet::Symbol>& getAlphabet() const; }; regexp::RegExp regexpFrom( const std::string& string ); diff --git a/alib2data/src/regexp/RegExpAlphabetGetter.cpp b/alib2data/src/regexp/RegExpAlphabetGetter.cpp deleted file mode 100644 index 02cbc4c8d89e6309da8076fab2ccc3fc0aac5cef..0000000000000000000000000000000000000000 --- a/alib2data/src/regexp/RegExpAlphabetGetter.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * RegExpAlphabetGetter.cpp - * - * Created on: Nov 23, 2013 - * Author: Jan Travnicek - */ - -#include "RegExpAlphabetGetter.h" -#include "RegExp.h" -#include "RegExpClasses.h" - -namespace regexp { - -void RegExpAlphabetGetter::Visit(void* userData, const UnboundedRegExp& regexp) const { - const std::set<alphabet::Symbol>* &res = *((const std::set<alphabet::Symbol>**) userData); - res = ®exp.getAlphabet(); -} - -void RegExpAlphabetGetter::Visit(void* userData, const FormalRegExp& regexp) const { - const std::set<alphabet::Symbol>* &res = *((const std::set<alphabet::Symbol>**) userData); - res = ®exp.getAlphabet(); -} - -const std::set<alphabet::Symbol>& RegExpAlphabetGetter::getAlphabet(const RegExp& regexp) { - const std::set<alphabet::Symbol>* res; - regexp.getData().Accept((void*) &res, RegExpAlphabetGetter::REG_EXP_ALPHABET_GETTER); - return *res; -} - -const RegExpAlphabetGetter RegExpAlphabetGetter::REG_EXP_ALPHABET_GETTER; - -} /* namespace regexp */ diff --git a/alib2data/src/regexp/RegExpAlphabetGetter.h b/alib2data/src/regexp/RegExpAlphabetGetter.h deleted file mode 100644 index 49d570c59a716f01255301798669a97232b9f1b8..0000000000000000000000000000000000000000 --- a/alib2data/src/regexp/RegExpAlphabetGetter.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * RegExpAlphabetGetter.h - * - * Created on: Nov 23, 2013 - * Author: Jan Travnicek - */ - -#ifndef REG_EXP_ALPHABET_GETTER_H_ -#define REG_EXP_ALPHABET_GETTER_H_ - -#include "RegExpBase.h" -#include <set> -#include "../alphabet/Symbol.h" - -namespace regexp { - -class RegExpAlphabetGetter : public VisitableRegExpBase::const_visitor_type { - void Visit(void*, const UnboundedRegExp& empty) const; - void Visit(void*, const FormalRegExp& empty) const; - -public: - RegExpAlphabetGetter() {} - - /** - * Composes string representation of RegExp. - * @param regexp RegExp to print - * @returns string representation of regexp - */ - static const std::set<alphabet::Symbol>& getAlphabet(const RegExp& regexp); - - static const RegExpAlphabetGetter REG_EXP_ALPHABET_GETTER; -}; - -} /* namespace regexp */ - -#endif /* REG_EXP_ALPHABET_GETTER_H_ */ diff --git a/alib2data/src/regexp/RegExpBase.h b/alib2data/src/regexp/RegExpBase.h index 993e7e7f1f888267e65746e40f6e3a3cb5e5d4d1..d9c4eff8da4e540a9fba281af8a35d40e35ec198 100644 --- a/alib2data/src/regexp/RegExpBase.h +++ b/alib2data/src/regexp/RegExpBase.h @@ -9,6 +9,7 @@ #define REG_EXP_BASE_H_ #include "../object/ObjectBase.h" +#include <set> namespace regexp { @@ -41,6 +42,8 @@ public: virtual RegExpBase* clone() const = 0; virtual RegExpBase* plunder() && = 0; + + virtual const std::set<alphabet::Symbol>& getAlphabet() const = 0; }; } /* namespace regexp */ diff --git a/alib2data/src/regexp/formal/FormalRegExp.h b/alib2data/src/regexp/formal/FormalRegExp.h index 20cd473deb740538a0d92beba65de3968c73a988..a76be404f34ae2b9fcc0cad86791d431c8647675 100644 --- a/alib2data/src/regexp/formal/FormalRegExp.h +++ b/alib2data/src/regexp/formal/FormalRegExp.h @@ -78,6 +78,10 @@ public: */ void setRegExp(FormalRegExpElement&& regExp); + virtual const std::set<alphabet::Symbol>& getAlphabet() const { + return RegExpAlphabet::getAlphabet(); + } + /** * Removes symbol from the alphabet of symbol available in the regular expression * @param symbol removed symbol from the alphabet diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExp.h b/alib2data/src/regexp/unbounded/UnboundedRegExp.h index 4f706e24560b1bc331210ebb3a43406266bafa57..3e08e3cc6889feb5df778baad69d3f6b6ed6f8c3 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExp.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExp.h @@ -79,6 +79,10 @@ public: */ void setRegExp(UnboundedRegExpElement&& regExp); + virtual const std::set<alphabet::Symbol>& getAlphabet() const { + return RegExpAlphabet::getAlphabet(); + } + /** * Removes symbol from the alphabet of symbol available in the regular expression * @param symbol removed symbol from the alphabet