diff --git a/alib2data/src/Api.hpp b/alib2data/src/Api.hpp index f457f162c46cb163d92dffca8861d01fe546ccfa..863443aa29a2c6711bc5be12d0a51b874d32ee79 100644 --- a/alib2data/src/Api.hpp +++ b/alib2data/src/Api.hpp @@ -340,7 +340,7 @@ public: }; -class ToXMLComposers : public ObjectBase::const_visitor_type { +class ToXMLComposers : public VisitableObjectBase::const_visitor_type { void Visit(void*, const exception::AlibException& symbol) const; void Visit(void*, const alphabet::LabeledSymbol& symbol) const; diff --git a/alib2data/src/alphabet/BlankSymbol.h b/alib2data/src/alphabet/BlankSymbol.h index 15a23388a28e0b3d5e541982dcfa49804e19db03..7425b628bf89af48e4084f041fa07c1b3f02633b 100644 --- a/alib2data/src/alphabet/BlankSymbol.h +++ b/alib2data/src/alphabet/BlankSymbol.h @@ -15,7 +15,7 @@ namespace alphabet { /** * Represents blank symbol in an alphabet. */ -class BlankSymbol : public std::element<BlankSymbol, SymbolBase> { +class BlankSymbol : public std::acceptor<BlankSymbol, VisitableSymbolBase, std::acceptor<BlankSymbol, alib::VisitableObjectBase, SymbolBase> > { public: /** * Creates a blank symbol. @@ -26,9 +26,9 @@ public: virtual SymbolBase* clone() const; virtual SymbolBase* plunder() &&; - virtual bool operator <(const ObjectBase& other) const; - virtual bool operator ==(const ObjectBase& other) const; - virtual bool operator >(const ObjectBase& other) const; + virtual bool operator <(const alib::ObjectBase& other) const; + virtual bool operator ==(const alib::ObjectBase& other) const; + virtual bool operator >(const alib::ObjectBase& other) const; virtual bool operator ==(const BlankSymbol& other) const; virtual bool operator <(const BlankSymbol& other) const; diff --git a/alib2data/src/alphabet/BottomOfTheStackSymbol.h b/alib2data/src/alphabet/BottomOfTheStackSymbol.h index acb5b0d63dda78bb85701f5b5547be76c2eaf0b6..0a536a0bafa4db9508d51d672f186c9c34bb67c9 100644 --- a/alib2data/src/alphabet/BottomOfTheStackSymbol.h +++ b/alib2data/src/alphabet/BottomOfTheStackSymbol.h @@ -15,7 +15,7 @@ namespace alphabet { /** * Represents blank symbol in an alphabet. */ -class BottomOfTheStackSymbol : public std::element<BottomOfTheStackSymbol, SymbolBase> { +class BottomOfTheStackSymbol : public std::acceptor<BottomOfTheStackSymbol, VisitableSymbolBase, std::acceptor<BottomOfTheStackSymbol, alib::VisitableObjectBase, SymbolBase> > { public: /** * Creates a blank symbol. @@ -26,9 +26,9 @@ public: virtual SymbolBase* clone() const; virtual SymbolBase* plunder() &&; - virtual bool operator <(const ObjectBase& other) const; - virtual bool operator ==(const ObjectBase& other) const; - virtual bool operator >(const ObjectBase& other) const; + virtual bool operator <(const alib::ObjectBase& other) const; + virtual bool operator ==(const alib::ObjectBase& other) const; + virtual bool operator >(const alib::ObjectBase& other) const; virtual bool operator ==(const BottomOfTheStackSymbol& other) const; virtual bool operator <(const BottomOfTheStackSymbol& other) const; diff --git a/alib2data/src/alphabet/EndSymbol.h b/alib2data/src/alphabet/EndSymbol.h index ec50eeb33319352698c58406ba5ec80f5f481e02..0941ad114b01b89e820e89c7c8664bd85c0722c6 100644 --- a/alib2data/src/alphabet/EndSymbol.h +++ b/alib2data/src/alphabet/EndSymbol.h @@ -15,7 +15,7 @@ namespace alphabet { /** * Represents blank symbol in an alphabet. */ -class EndSymbol : public std::element<EndSymbol, SymbolBase> { +class EndSymbol : public std::acceptor<EndSymbol, VisitableSymbolBase, std::acceptor<EndSymbol, alib::VisitableObjectBase, SymbolBase> > { public: /** * Creates a blank symbol. @@ -26,9 +26,9 @@ public: virtual SymbolBase* clone() const; virtual SymbolBase* plunder() &&; - virtual bool operator <(const ObjectBase& other) const; - virtual bool operator ==(const ObjectBase& other) const; - virtual bool operator >(const ObjectBase& other) const; + virtual bool operator <(const alib::ObjectBase& other) const; + virtual bool operator ==(const alib::ObjectBase& other) const; + virtual bool operator >(const alib::ObjectBase& other) const; virtual bool operator ==(const EndSymbol& other) const; virtual bool operator <(const EndSymbol& other) const; diff --git a/alib2data/src/alphabet/LabeledSymbol.h b/alib2data/src/alphabet/LabeledSymbol.h index 0b684a979ceb7103b7fcf64a19190bf7c7c14381..5b122c9772bce5c50ab1a96ec3eb1f5a3bc307a1 100644 --- a/alib2data/src/alphabet/LabeledSymbol.h +++ b/alib2data/src/alphabet/LabeledSymbol.h @@ -17,7 +17,7 @@ namespace alphabet { /** * Represents symbol in an alphabet. */ -class LabeledSymbol : public std::element<LabeledSymbol, SymbolBase> { +class LabeledSymbol : public std::acceptor<LabeledSymbol, VisitableSymbolBase, std::acceptor<LabeledSymbol, alib::VisitableObjectBase, SymbolBase> > { protected: label::Label label; @@ -37,9 +37,9 @@ public: */ const label::Label& getLabel() const; - virtual bool operator <(const ObjectBase& other) const; - virtual bool operator ==(const ObjectBase& other) const; - virtual bool operator >(const ObjectBase& other) const; + virtual bool operator <(const alib::ObjectBase& other) const; + virtual bool operator ==(const alib::ObjectBase& other) const; + virtual bool operator >(const alib::ObjectBase& other) const; virtual bool operator ==(const LabeledSymbol& other) const; virtual bool operator <(const LabeledSymbol& other) const; diff --git a/alib2data/src/alphabet/SymbolBase.h b/alib2data/src/alphabet/SymbolBase.h index 6e3fd5987dd7e17df5b650f9a6c313830d280981..ce062e65ae78abf67d4dc4604bb850c0647d02a9 100644 --- a/alib2data/src/alphabet/SymbolBase.h +++ b/alib2data/src/alphabet/SymbolBase.h @@ -13,11 +13,18 @@ namespace alphabet { +typedef std::acceptor_base< + LabeledSymbol, BlankSymbol, BottomOfTheStackSymbol, EndSymbol + > VisitableSymbolBase; + /** * Represents symbol in an alphabet. */ -class SymbolBase : public alib::ObjectBase { +class SymbolBase : public alib::ObjectBase, public VisitableSymbolBase { public: + using VisitableSymbolBase::Accept; + using alib::VisitableObjectBase::Accept; + virtual SymbolBase* clone() const = 0; virtual SymbolBase* plunder() && = 0; diff --git a/alib2data/src/alphabet/SymbolToStringComposer.cpp b/alib2data/src/alphabet/SymbolToStringComposer.cpp index 610052de8655d9cac76a8fda31853b3269153942..eacdda14b0b68ac4b6f03a4a71fdba8c99d552d8 100644 --- a/alib2data/src/alphabet/SymbolToStringComposer.cpp +++ b/alib2data/src/alphabet/SymbolToStringComposer.cpp @@ -37,14 +37,9 @@ void SymbolToStringComposer::Visit(void* userData, const EndSymbol&) { out << "#E"; } -void SymbolToStringComposer::Visit(void* userData, const Symbol& symbol) { - symbol.getData().Accept(userData, *this); - -} - std::string SymbolToStringComposer::compose(const Symbol& symbol) { std::stringstream out; - Visit((void*) &out, symbol); + symbol.getData().Accept((void*) &out, *this); return std::move(out).str(); } diff --git a/alib2data/src/alphabet/SymbolToStringComposer.h b/alib2data/src/alphabet/SymbolToStringComposer.h index 7a11e46f49e4e5937bd7f837308ca372d12ed034..66b1db2b5751d4ed888d8741456182d3e0e0343f 100644 --- a/alib2data/src/alphabet/SymbolToStringComposer.h +++ b/alib2data/src/alphabet/SymbolToStringComposer.h @@ -18,8 +18,7 @@ namespace alphabet { /** * This class contains methods to print XML representation of string to the output stream. */ -class SymbolToStringComposer : public SymbolBase::visitor_type { - void Visit(void*, const Symbol& symbol); +class SymbolToStringComposer : public VisitableSymbolBase::visitor_type { void Visit(void*, const LabeledSymbol& symbol); void Visit(void*, const BlankSymbol& symbol); void Visit(void*, const BottomOfTheStackSymbol& symbol); diff --git a/alib2data/src/automaton/AutomatonBase.h b/alib2data/src/automaton/AutomatonBase.h index 813a874ce5dce38062295e314beb4e13aa9b6595..07ff350f0127675a872f2cb57dde5fc2bbcf8d9a 100644 --- a/alib2data/src/automaton/AutomatonBase.h +++ b/alib2data/src/automaton/AutomatonBase.h @@ -13,11 +13,18 @@ namespace automaton { +typedef std::acceptor_base< + automaton::UnknownAutomaton, automaton::DFA, automaton::NFA, automaton::EpsilonNFA, automaton::CompactNFA, automaton::ExtendedNFA, automaton::NPDA, automaton::SinglePopNPDA, automaton::OneTapeDTM + > VisitableAutomatonBase; + /** * Abstract base class for all automata. */ -class AutomatonBase : public alib::ObjectBase { +class AutomatonBase : public alib::ObjectBase, public VisitableAutomatonBase { public: + using VisitableAutomatonBase::Accept; + using alib::VisitableObjectBase::Accept; + virtual AutomatonBase* clone() const = 0; virtual AutomatonBase* plunder() && = 0; diff --git a/alib2data/src/automaton/FSM/CompactNFA.h b/alib2data/src/automaton/FSM/CompactNFA.h index faf6c70406fd4205f8d0ad584973caf02c73ae68..12681a0a1bd83d20857b725c835201a147ae2ce3 100644 --- a/alib2data/src/automaton/FSM/CompactNFA.h +++ b/alib2data/src/automaton/FSM/CompactNFA.h @@ -20,7 +20,7 @@ namespace automaton { * Represents Finite Automaton. * Can store nondeterministic finite automaton without epsilon transitions. */ -class CompactNFA : public std::element<CompactNFA, AutomatonBase>, public MultiInitialStates, public InputAlphabet { +class CompactNFA : public std::acceptor<CompactNFA, VisitableAutomatonBase, std::acceptor<CompactNFA, alib::VisitableObjectBase, AutomatonBase> >, public MultiInitialStates, public InputAlphabet { protected: std::map<std::pair<State, string::String>, std::set<State> > transitions; //TODO LinearString public: @@ -70,9 +70,9 @@ public: */ std::map<std::pair<State, string::String>, std::set<State>> getTransitionsToState(const State& from) const; - virtual bool operator<(const ObjectBase& other) const; - virtual bool operator==(const ObjectBase& other) const; - virtual bool operator>(const ObjectBase& other) const; + virtual bool operator<(const alib::ObjectBase& other) const; + virtual bool operator==(const alib::ObjectBase& other) const; + virtual bool operator>(const alib::ObjectBase& other) const; virtual bool operator==(const CompactNFA& other) const; virtual bool operator<(const CompactNFA& other) const; diff --git a/alib2data/src/automaton/FSM/DFA.h b/alib2data/src/automaton/FSM/DFA.h index 568b81d1d75cc20955acfa4d40481d194240d8a0..3749c9310fd342e9119232d846ae92b252f24935 100644 --- a/alib2data/src/automaton/FSM/DFA.h +++ b/alib2data/src/automaton/FSM/DFA.h @@ -20,7 +20,7 @@ namespace automaton { * Represents Finite Automaton. * Can store nondeterministic finite automaton without epsilon transitions. */ -class DFA : public std::element<DFA, AutomatonBase>, public SingleInitialState, public InputAlphabet { +class DFA : public std::acceptor<DFA, VisitableAutomatonBase, std::acceptor<DFA, alib::VisitableObjectBase, AutomatonBase> >, public SingleInitialState, public InputAlphabet { protected: std::map<std::pair<State, alphabet::Symbol>, State> transitions; public: @@ -80,9 +80,9 @@ public: */ bool isTotal() const; - virtual bool operator<(const ObjectBase& other) const; - virtual bool operator==(const ObjectBase& other) const; - virtual bool operator>(const ObjectBase& other) const; + virtual bool operator<(const alib::ObjectBase& other) const; + virtual bool operator==(const alib::ObjectBase& other) const; + virtual bool operator>(const alib::ObjectBase& other) const; virtual bool operator==(const DFA& other) const; virtual bool operator<(const DFA& other) const; diff --git a/alib2data/src/automaton/FSM/EpsilonNFA.h b/alib2data/src/automaton/FSM/EpsilonNFA.h index 3acf51dda29e47eecd9171026c243b076dea3a85..a77d18cd94fc256bbaf9340a1655210f06eeb2b7 100644 --- a/alib2data/src/automaton/FSM/EpsilonNFA.h +++ b/alib2data/src/automaton/FSM/EpsilonNFA.h @@ -22,7 +22,7 @@ namespace automaton { * Represents Finite Automaton. * Can store nondeterministic finite automaton with epsilon transitions. */ -class EpsilonNFA : public std::element<EpsilonNFA, AutomatonBase>, public MultiInitialStates, public InputAlphabet { +class EpsilonNFA : public std::acceptor<EpsilonNFA, VisitableAutomatonBase, std::acceptor<EpsilonNFA, alib::VisitableObjectBase, AutomatonBase> >, public MultiInitialStates, public InputAlphabet { protected: std::map<std::pair<State, std::variant<string::Epsilon, alphabet::Symbol> >, std::set<State> > transitions; public: @@ -151,9 +151,9 @@ public: */ bool isTotal() const; - virtual bool operator<(const ObjectBase& other) const; - virtual bool operator==(const ObjectBase& other) const; - virtual bool operator>(const ObjectBase& other) const; + virtual bool operator<(const alib::ObjectBase& other) const; + virtual bool operator==(const alib::ObjectBase& other) const; + virtual bool operator>(const alib::ObjectBase& other) const; virtual bool operator==(const EpsilonNFA& other) const; virtual bool operator<(const EpsilonNFA& other) const; diff --git a/alib2data/src/automaton/FSM/ExtendedNFA.h b/alib2data/src/automaton/FSM/ExtendedNFA.h index 130c6330a28e73025952ccca087abb15bbb19337..d77501228cfed012f71c2601bfd52e4404fb663c 100644 --- a/alib2data/src/automaton/FSM/ExtendedNFA.h +++ b/alib2data/src/automaton/FSM/ExtendedNFA.h @@ -20,7 +20,7 @@ namespace automaton { * Represents Finite Automaton. * Can store nondeterministic finite automaton without epsilon transitions. */ -class ExtendedNFA : public std::element<ExtendedNFA, AutomatonBase>, public MultiInitialStates, public InputAlphabet { +class ExtendedNFA : public std::acceptor<ExtendedNFA, VisitableAutomatonBase, std::acceptor<ExtendedNFA, alib::VisitableObjectBase, AutomatonBase> >, public MultiInitialStates, public InputAlphabet { protected: std::map<std::pair<State, regexp::RegExp>, std::set<State> > transitions; public: @@ -69,9 +69,9 @@ public: */ std::map<std::pair<State, regexp::RegExp>, std::set<State> > getTransitionsToState(const State& from) const; - virtual bool operator<(const ObjectBase& other) const; - virtual bool operator==(const ObjectBase& other) const; - virtual bool operator>(const ObjectBase& other) const; + virtual bool operator<(const alib::ObjectBase& other) const; + virtual bool operator==(const alib::ObjectBase& other) const; + virtual bool operator>(const alib::ObjectBase& other) const; virtual bool operator==(const ExtendedNFA& other) const; virtual bool operator<(const ExtendedNFA& other) const; diff --git a/alib2data/src/automaton/FSM/FiniteAutomatonToStringComposer.cpp b/alib2data/src/automaton/FSM/FiniteAutomatonToStringComposer.cpp index 176476502928a16c1ea2272e3e62d68efb3b8ff4..8a6eab24581c8607752174fd6032b1e091f85508 100644 --- a/alib2data/src/automaton/FSM/FiniteAutomatonToStringComposer.cpp +++ b/alib2data/src/automaton/FSM/FiniteAutomatonToStringComposer.cpp @@ -162,10 +162,6 @@ std::string FiniteAutomatonToStringComposer::compose(const Automaton& automaton) return out.str(); } -void FiniteAutomatonToStringComposer::Visit(void* data, const Automaton& automaton) const { - *((std::stringstream*) data) << this->compose(automaton); -} - void FiniteAutomatonToStringComposer::Visit(void*, const UnknownAutomaton&) const { throw exception::AlibException(); } diff --git a/alib2data/src/automaton/FSM/FiniteAutomatonToStringComposer.h b/alib2data/src/automaton/FSM/FiniteAutomatonToStringComposer.h index 32e7332210d8d19f1fd61a199c00bca191eba993..7998f253b154f1dc0b8153189e95b9370a95cda7 100644 --- a/alib2data/src/automaton/FSM/FiniteAutomatonToStringComposer.h +++ b/alib2data/src/automaton/FSM/FiniteAutomatonToStringComposer.h @@ -9,8 +9,7 @@ namespace automaton { -class FiniteAutomatonToStringComposer : public AutomatonBase::const_visitor_type { - void Visit(void*, const Automaton& automaton) const; +class FiniteAutomatonToStringComposer : public VisitableAutomatonBase::const_visitor_type { void Visit(void*, const UnknownAutomaton& automaton) const; void Visit(void*, const EpsilonNFA& automaton) const; void Visit(void*, const NFA& automaton) const; diff --git a/alib2data/src/automaton/FSM/NFA.h b/alib2data/src/automaton/FSM/NFA.h index 55cc8c1969a97ef24a822fa610da7998246e344b..9d44edf441b994b6b16c6f35c294a51f54c99a5b 100644 --- a/alib2data/src/automaton/FSM/NFA.h +++ b/alib2data/src/automaton/FSM/NFA.h @@ -21,7 +21,7 @@ namespace automaton { * Represents Finite Automaton. * Can store nondeterministic finite automaton without epsilon transitions. */ -class NFA : public std::element<NFA, AutomatonBase>, public MultiInitialStates, public InputAlphabet { +class NFA : public std::acceptor<NFA, VisitableAutomatonBase, std::acceptor<NFA, alib::VisitableObjectBase, AutomatonBase> >, public MultiInitialStates, public InputAlphabet { protected: std::map<std::pair<State, alphabet::Symbol>, std::set<State> > transitions; public: @@ -89,9 +89,9 @@ public: */ bool isTotal() const; - virtual bool operator<(const ObjectBase& other) const; - virtual bool operator==(const ObjectBase& other) const; - virtual bool operator>(const ObjectBase& other) const; + virtual bool operator<(const alib::ObjectBase& other) const; + virtual bool operator==(const alib::ObjectBase& other) const; + virtual bool operator>(const alib::ObjectBase& other) const; virtual bool operator==(const NFA& other) const; virtual bool operator<(const NFA& other) const; diff --git a/alib2data/src/automaton/PDA/NPDA.h b/alib2data/src/automaton/PDA/NPDA.h index ff66f883b33cf9576d216c76dde46816265084ea..1b9bb906fa7f24e95ff92a8dcec14f9359803dbd 100644 --- a/alib2data/src/automaton/PDA/NPDA.h +++ b/alib2data/src/automaton/PDA/NPDA.h @@ -24,7 +24,7 @@ namespace automaton { /** * Push Down Automaton */ -class NPDA : public std::element<NPDA, AutomatonBase>, public MultiInitialSymbolsPushdownStoreAlphabet, public MultiInitialStates, public InputAlphabet { +class NPDA : public std::acceptor<NPDA, VisitableAutomatonBase, std::acceptor<NPDA, alib::VisitableObjectBase, AutomatonBase> >, public MultiInitialSymbolsPushdownStoreAlphabet, public MultiInitialStates, public InputAlphabet { protected: 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; public: @@ -75,9 +75,9 @@ public: */ const std::map<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::set<std::pair<State, std::vector<alphabet::Symbol> > > >& getTransitions() const; - virtual bool operator<(const ObjectBase& other) const; - virtual bool operator==(const ObjectBase& other) const; - virtual bool operator>(const ObjectBase& other) const; + virtual bool operator<(const alib::ObjectBase& other) const; + virtual bool operator==(const alib::ObjectBase& other) const; + virtual bool operator>(const alib::ObjectBase& other) const; virtual bool operator==(const NPDA& other) const; diff --git a/alib2data/src/automaton/PDA/SinglePopNPDA.h b/alib2data/src/automaton/PDA/SinglePopNPDA.h index cf721bd17baaa3849d0037eb70d0d8daa6a27794..b3e233af3eb407518a4e252abaaabba95dd31085 100644 --- a/alib2data/src/automaton/PDA/SinglePopNPDA.h +++ b/alib2data/src/automaton/PDA/SinglePopNPDA.h @@ -24,7 +24,7 @@ namespace automaton { /** * Push Down Automaton */ -class SinglePopNPDA: public std::element<SinglePopNPDA, AutomatonBase>, public MultiInitialSymbolsPushdownStoreAlphabet, public MultiInitialStates, public InputAlphabet { +class SinglePopNPDA: public std::acceptor<SinglePopNPDA, VisitableAutomatonBase, std::acceptor<SinglePopNPDA, alib::VisitableObjectBase, AutomatonBase> >, public MultiInitialSymbolsPushdownStoreAlphabet, public MultiInitialStates, public InputAlphabet { protected: std::map<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, std::set<std::pair<State, std::vector<alphabet::Symbol> > > > transitions; public: @@ -75,9 +75,9 @@ public: */ const std::map<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, std::set<std::pair<State, std::vector<alphabet::Symbol> > > >& getTransitions() const; - virtual bool operator<(const ObjectBase& other) const; - virtual bool operator==(const ObjectBase& other) const; - virtual bool operator>(const ObjectBase& other) const; + virtual bool operator<(const alib::ObjectBase& other) const; + virtual bool operator==(const alib::ObjectBase& other) const; + virtual bool operator>(const alib::ObjectBase& other) const; virtual bool operator==(const SinglePopNPDA& other) const; virtual bool operator<(const SinglePopNPDA& other) const; diff --git a/alib2data/src/automaton/TM/OneTapeDTM.h b/alib2data/src/automaton/TM/OneTapeDTM.h index 4537413b0d466d788dc3cc9b7ee2347047d1f83d..a38ddca852f104ae74f6b7f2f9075ed0b90c4a06 100644 --- a/alib2data/src/automaton/TM/OneTapeDTM.h +++ b/alib2data/src/automaton/TM/OneTapeDTM.h @@ -22,7 +22,7 @@ namespace automaton { /** * One tape turing machine */ -class OneTapeDTM : public std::element<OneTapeDTM, AutomatonBase>, public SingleInitialState, public BlankSymbolInputTapeAlphabet { +class OneTapeDTM : public std::acceptor<OneTapeDTM, VisitableAutomatonBase, std::acceptor<OneTapeDTM, alib::VisitableObjectBase, AutomatonBase> >, public SingleInitialState, public BlankSymbolInputTapeAlphabet { protected: std::map<std::pair<State, alphabet::Symbol>, std::tuple<State, alphabet::Symbol, Shift> > transitions; @@ -73,9 +73,9 @@ public: */ const std::map<std::pair<State, alphabet::Symbol>, std::tuple<State, alphabet::Symbol, Shift> >& getTransitions() const; - virtual bool operator<(const ObjectBase& other) const; - virtual bool operator==(const ObjectBase& other) const; - virtual bool operator>(const ObjectBase& other) const; + virtual bool operator<(const alib::ObjectBase& other) const; + virtual bool operator==(const alib::ObjectBase& other) const; + virtual bool operator>(const alib::ObjectBase& other) const; virtual bool operator==(const OneTapeDTM& other) const; diff --git a/alib2data/src/automaton/UnknownAutomaton.h b/alib2data/src/automaton/UnknownAutomaton.h index d816b05ffef49860af25a62eda7bf2ba25fcca33..aeea1d2bcfcf7916dc022c4be9e370795f6066c6 100644 --- a/alib2data/src/automaton/UnknownAutomaton.h +++ b/alib2data/src/automaton/UnknownAutomaton.h @@ -21,7 +21,7 @@ namespace automaton { /** * Class representing unknown automaton parsed from XML. */ -class UnknownAutomaton : public std::element<UnknownAutomaton, AutomatonBase> { +class UnknownAutomaton : public std::acceptor<UnknownAutomaton, VisitableAutomatonBase, std::acceptor<UnknownAutomaton, alib::VisitableObjectBase, AutomatonBase> > { protected: std::set<State> states; std::set<State> initialStates; @@ -271,9 +271,9 @@ public: */ const std::set<UnknownTransition>& getTransitions() const; - virtual bool operator>(const ObjectBase& other) const; - virtual bool operator==(const ObjectBase& other) const; - virtual bool operator<(const ObjectBase& other) const; + virtual bool operator>(const alib::ObjectBase& other) const; + virtual bool operator==(const alib::ObjectBase& other) const; + virtual bool operator<(const alib::ObjectBase& other) const; /** * Compares two instances of UnknownAutomata diff --git a/alib2data/src/container/ContainerBase.h b/alib2data/src/container/ContainerBase.h index d5818e6385fa3ae3bd410318a043ab5be6ec1b42..d3084c1e4be6ea1a00812f29230d4c26d239d6ff 100644 --- a/alib2data/src/container/ContainerBase.h +++ b/alib2data/src/container/ContainerBase.h @@ -13,11 +13,18 @@ namespace container { +typedef std::acceptor_base< + container::ObjectsSet + > VisitableContainerBase; + /** * Represents container in a hierarchy. */ -class ContainerBase : public alib::ObjectBase { +class ContainerBase : public alib::ObjectBase, public VisitableContainerBase { public: + using VisitableContainerBase::Accept; + using alib::VisitableObjectBase::Accept; + virtual ContainerBase* clone() const = 0; virtual ContainerBase* plunder() && = 0; diff --git a/alib2data/src/container/ObjectsSet.h b/alib2data/src/container/ObjectsSet.h index a5a98d46f93acd997cc097eebf164ee0622b2d9d..54a67004d221aba69cc1240f3b78802c3964e5d0 100644 --- a/alib2data/src/container/ObjectsSet.h +++ b/alib2data/src/container/ObjectsSet.h @@ -20,15 +20,15 @@ namespace container { * Basic container from which are derived all other containers. * Contains reason why the container occured. */ -class ObjectsSet : public std::set<alib::Object>, public std::element<ObjectsSet, ContainerBase> { +class ObjectsSet : public std::set<alib::Object>, public std::acceptor<ObjectsSet, VisitableContainerBase, std::acceptor<ObjectsSet, alib::VisitableObjectBase, ContainerBase> > { public: virtual ContainerBase* clone() const; virtual ContainerBase* plunder() &&; - virtual bool operator>(const ObjectBase& other) const; - virtual bool operator==(const ObjectBase& other) const; - virtual bool operator<(const ObjectBase& other) const; + virtual bool operator>(const alib::ObjectBase& other) const; + virtual bool operator==(const alib::ObjectBase& other) const; + virtual bool operator<(const alib::ObjectBase& other) const; virtual bool operator==(const ObjectsSet& other) const; virtual bool operator<(const ObjectsSet& other) const; diff --git a/alib2data/src/exception/AlibException.h b/alib2data/src/exception/AlibException.h index 99c8aacee3c8ee5246aaeddde2c616fe0bf7ccc6..9de47eb039f506a7536f1e0a8f27d8e2b31ae9a2 100644 --- a/alib2data/src/exception/AlibException.h +++ b/alib2data/src/exception/AlibException.h @@ -19,7 +19,7 @@ namespace exception { * Basic exception from which are derived all other exceptions. * Contains reason why the exception occured. */ -class AlibException : public std::exception, public std::element<AlibException, alib::ObjectBase> { +class AlibException : public std::exception, public std::acceptor<AlibException, alib::VisitableObjectBase, alib::ObjectBase> { protected: std::string cause; @@ -50,9 +50,9 @@ public: */ const std::string & getBacktrace ( ) const; - virtual bool operator>(const ObjectBase& other) const; - virtual bool operator==(const ObjectBase& other) const; - virtual bool operator<(const ObjectBase& other) const; + virtual bool operator>(const alib::ObjectBase& other) const; + virtual bool operator==(const alib::ObjectBase& other) const; + virtual bool operator<(const alib::ObjectBase& other) const; virtual bool operator==(const AlibException& other) const; virtual bool operator<(const AlibException& other) const; diff --git a/alib2data/src/grammar/ContextFree/CFG.h b/alib2data/src/grammar/ContextFree/CFG.h index 25a8eb82a6626651b96a4c4b9c439be99c3fe9e6..069cefbeab7cab8b1e5b7d91c96df22bddc7bade 100644 --- a/alib2data/src/grammar/ContextFree/CFG.h +++ b/alib2data/src/grammar/ContextFree/CFG.h @@ -19,7 +19,7 @@ namespace grammar { /** * Context free grammar. Type 2 in Chomsky hierarchy. Produces context free language. */ -class CFG : public std::element<CFG, GrammarBase>, public TerminalNonterminalAlphabetInitialSymbol { +class CFG : public std::acceptor<CFG, VisitableGrammarBase, std::acceptor<CFG, alib::VisitableObjectBase, GrammarBase> >, public TerminalNonterminalAlphabetInitialSymbol { std::map<alphabet::Symbol, std::set<std::vector<alphabet::Symbol>>> rules; public: CFG(const alphabet::Symbol& initialSymbol); @@ -40,9 +40,9 @@ public: bool removeNonterminalSymbol(const alphabet::Symbol& symbol); - virtual bool operator <(const ObjectBase& other) const; - virtual bool operator ==(const ObjectBase& other) const; - virtual bool operator >(const ObjectBase& other) const; + virtual bool operator <(const alib::ObjectBase& other) const; + virtual bool operator ==(const alib::ObjectBase& other) const; + virtual bool operator >(const alib::ObjectBase& other) const; virtual bool operator==(const CFG& other) const; diff --git a/alib2data/src/grammar/ContextFree/CNF.h b/alib2data/src/grammar/ContextFree/CNF.h index 4dfd5ad9464b37021b5f9834cee131b6308198e2..c3f33a27efd3ea0ae23deb9fe09eff850d7c74a8 100644 --- a/alib2data/src/grammar/ContextFree/CNF.h +++ b/alib2data/src/grammar/ContextFree/CNF.h @@ -20,7 +20,7 @@ namespace grammar { /** * Context free grammar in chomsky normal form. Type 2 in Chomsky hierarchy. Produces context free languages. */ -class CNF : public std::element<CNF, GrammarBase>, public TerminalNonterminalAlphabetInitialSymbol { +class CNF : public std::acceptor<CNF, VisitableGrammarBase, std::acceptor<CNF, alib::VisitableObjectBase, GrammarBase> >, public TerminalNonterminalAlphabetInitialSymbol { std::map<alphabet::Symbol, std::set<std::variant<alphabet::Symbol, std::pair<alphabet::Symbol, alphabet::Symbol>>>> rules; bool generatesEpsilon; public: @@ -49,9 +49,9 @@ public: void setGeneratesEpsilon(bool genEps); bool getGeneratesEpsilon() const; - virtual bool operator <(const ObjectBase& other) const; - virtual bool operator ==(const ObjectBase& other) const; - virtual bool operator >(const ObjectBase& other) const; + virtual bool operator <(const alib::ObjectBase& other) const; + virtual bool operator ==(const alib::ObjectBase& other) const; + virtual bool operator >(const alib::ObjectBase& other) const; virtual bool operator==(const CNF& other) const; diff --git a/alib2data/src/grammar/ContextFree/EpsilonFreeCFG.h b/alib2data/src/grammar/ContextFree/EpsilonFreeCFG.h index 38e1a250b1d6e5b5d5bd105fdede22ff7a5c2b67..e96e89f4d2f90ac37a4cce233a91bec001eca215 100644 --- a/alib2data/src/grammar/ContextFree/EpsilonFreeCFG.h +++ b/alib2data/src/grammar/ContextFree/EpsilonFreeCFG.h @@ -19,7 +19,7 @@ namespace grammar { /** * Epsilon free context free grammar. Type 2 in Chomsky hierarchy. Produces context free languages. */ -class EpsilonFreeCFG : public std::element<EpsilonFreeCFG, GrammarBase>, public TerminalNonterminalAlphabetInitialSymbol { +class EpsilonFreeCFG : public std::acceptor<EpsilonFreeCFG, VisitableGrammarBase, std::acceptor<EpsilonFreeCFG, alib::VisitableObjectBase, GrammarBase> >, public TerminalNonterminalAlphabetInitialSymbol { std::map<alphabet::Symbol, std::set<std::vector<alphabet::Symbol>>> rules; bool generatesEpsilon; public: @@ -44,9 +44,9 @@ public: void setGeneratesEpsilon(bool genEps); bool getGeneratesEpsilon() const; - virtual bool operator <(const ObjectBase& other) const; - virtual bool operator ==(const ObjectBase& other) const; - virtual bool operator >(const ObjectBase& other) const; + virtual bool operator <(const alib::ObjectBase& other) const; + virtual bool operator ==(const alib::ObjectBase& other) const; + virtual bool operator >(const alib::ObjectBase& other) const; virtual bool operator==(const EpsilonFreeCFG& other) const; diff --git a/alib2data/src/grammar/ContextFree/GNF.h b/alib2data/src/grammar/ContextFree/GNF.h index 655479de24f5b60bd8cae4bb29d236fb9d9dd6b2..cb63da3a7d4efc41867f9cd14ba7f1fdc6353f0d 100644 --- a/alib2data/src/grammar/ContextFree/GNF.h +++ b/alib2data/src/grammar/ContextFree/GNF.h @@ -19,7 +19,7 @@ namespace grammar { /** * Context free grammar in greibach normal form. Type 2 in Chomsky hierarchy. Produces context free languages. */ -class GNF : public std::element<GNF, GrammarBase>, public TerminalNonterminalAlphabetInitialSymbol { +class GNF : public std::acceptor<GNF, VisitableGrammarBase, std::acceptor<GNF, alib::VisitableObjectBase, GrammarBase> >, public TerminalNonterminalAlphabetInitialSymbol { std::map<alphabet::Symbol, std::set<std::pair<alphabet::Symbol, std::vector<alphabet::Symbol> >> > rules; bool generatesEpsilon; public: @@ -44,9 +44,9 @@ public: void setGeneratesEpsilon(bool genEps); bool getGeneratesEpsilon() const; - virtual bool operator <(const ObjectBase& other) const; - virtual bool operator ==(const ObjectBase& other) const; - virtual bool operator >(const ObjectBase& other) const; + virtual bool operator <(const alib::ObjectBase& other) const; + virtual bool operator ==(const alib::ObjectBase& other) const; + virtual bool operator >(const alib::ObjectBase& other) const; virtual bool operator==(const GNF& other) const; diff --git a/alib2data/src/grammar/ContextFree/LG.h b/alib2data/src/grammar/ContextFree/LG.h index c1b42b8cbda0abcbf5a87ce6e6abb34f9468fcd3..7660ea0dc7303e7e807d8e54b12230d01f829018 100644 --- a/alib2data/src/grammar/ContextFree/LG.h +++ b/alib2data/src/grammar/ContextFree/LG.h @@ -21,7 +21,7 @@ namespace grammar { /** * Linear grammar in chomsky normal form. Type 3 in Chomsky hierarchy. Produces regular languages. */ -class LG : public std::element<LG, GrammarBase>, public TerminalNonterminalAlphabetInitialSymbol { +class LG : public std::acceptor<LG, VisitableGrammarBase, std::acceptor<LG, alib::VisitableObjectBase, GrammarBase> >, public TerminalNonterminalAlphabetInitialSymbol { std::map<alphabet::Symbol, std::set<std::variant<std::vector<alphabet::Symbol>, std::tuple<std::vector<alphabet::Symbol>, alphabet::Symbol, std::vector<alphabet::Symbol>> >> > rules; public: LG(const alphabet::Symbol& initialSymbol); @@ -48,9 +48,9 @@ public: bool removeNonterminalSymbol(const alphabet::Symbol& symbol); - virtual bool operator <(const ObjectBase& other) const; - virtual bool operator ==(const ObjectBase& other) const; - virtual bool operator >(const ObjectBase& other) const; + virtual bool operator <(const alib::ObjectBase& other) const; + virtual bool operator ==(const alib::ObjectBase& other) const; + virtual bool operator >(const alib::ObjectBase& other) const; virtual bool operator==(const LG& other) const; diff --git a/alib2data/src/grammar/ContextSensitive/CSG.h b/alib2data/src/grammar/ContextSensitive/CSG.h index f8c73faee70401f46679a833f013abee66964d51..34a12e508feec4702cd7fad981d157370903dfd4 100644 --- a/alib2data/src/grammar/ContextSensitive/CSG.h +++ b/alib2data/src/grammar/ContextSensitive/CSG.h @@ -18,7 +18,7 @@ namespace grammar { /** * Epsilon free context free grammar. Type 2 in Chomsky hierarchy. Produces context free languages. */ -class CSG : public std::element<CSG, GrammarBase>, public TerminalNonterminalAlphabetInitialSymbol { +class CSG : public std::acceptor<CSG, VisitableGrammarBase, std::acceptor<CSG, alib::VisitableObjectBase, GrammarBase> >, public TerminalNonterminalAlphabetInitialSymbol { std::map<std::tuple<std::vector<alphabet::Symbol>, alphabet::Symbol, std::vector<alphabet::Symbol>>, std::set<std::vector<alphabet::Symbol>>> rules; bool generatesEpsilon; public: diff --git a/alib2data/src/grammar/ContextSensitive/NonContractingGrammar.h b/alib2data/src/grammar/ContextSensitive/NonContractingGrammar.h index a4be4b1a7583c7dc56cfbaa9d8c24d73e45942aa..5cf1851fdd6cd96356b5b0485ec33a897229713a 100644 --- a/alib2data/src/grammar/ContextSensitive/NonContractingGrammar.h +++ b/alib2data/src/grammar/ContextSensitive/NonContractingGrammar.h @@ -18,7 +18,7 @@ namespace grammar { /** * Non contracting grammar. Type 1 in Chomsky hierarchy. Produces context sensitive language. */ -class NonContractingGrammar : public std::element<NonContractingGrammar, GrammarBase>, public TerminalNonterminalAlphabetInitialSymbol { +class NonContractingGrammar : public std::acceptor<NonContractingGrammar, VisitableGrammarBase, std::acceptor<NonContractingGrammar, alib::VisitableObjectBase, GrammarBase> >, public TerminalNonterminalAlphabetInitialSymbol { std::map<std::vector<alphabet::Symbol>, std::set<std::vector<alphabet::Symbol>>> rules; bool generatesEpsilon; public: @@ -43,9 +43,9 @@ public: void setGeneratesEpsilon(bool genEps); bool getGeneratesEpsilon() const; - virtual bool operator <(const ObjectBase& other) const; - virtual bool operator ==(const ObjectBase& other) const; - virtual bool operator >(const ObjectBase& other) const; + virtual bool operator <(const alib::ObjectBase& other) const; + virtual bool operator ==(const alib::ObjectBase& other) const; + virtual bool operator >(const alib::ObjectBase& other) const; virtual bool operator==(const NonContractingGrammar& other) const; diff --git a/alib2data/src/grammar/GrammarBase.h b/alib2data/src/grammar/GrammarBase.h index 89e0d590adc53cd570cf7bacc20ab44980640f87..775368ff1e51a83edb611e20e94f7ea8f66ac9e7 100644 --- a/alib2data/src/grammar/GrammarBase.h +++ b/alib2data/src/grammar/GrammarBase.h @@ -13,11 +13,18 @@ namespace grammar { +typedef std::acceptor_base< + grammar::UnknownGrammar, grammar::LeftLG, grammar::LeftRG, grammar::RightLG, grammar::RightRG, grammar::LG, grammar::CFG, grammar::EpsilonFreeCFG, grammar::CNF, grammar::GNF, grammar::CSG, grammar::NonContractingGrammar, grammar::ContextPreservingUnrestrictedGrammar, grammar::UnrestrictedGrammar + > VisitableGrammarBase; + /** - * Abstract base class for all automata. + * Abstract base class for all grammars. */ -class GrammarBase : public alib::ObjectBase { +class GrammarBase : public alib::ObjectBase, public VisitableGrammarBase { public: + using VisitableGrammarBase::Accept; + using alib::VisitableObjectBase::Accept; + virtual GrammarBase* clone() const = 0; virtual GrammarBase* plunder() && = 0; diff --git a/alib2data/src/grammar/Regular/LeftLG.h b/alib2data/src/grammar/Regular/LeftLG.h index 0d922212372674ec216dd84f673e20c523d57be3..cf5db657e97feef8a92682e5629756d00bc9b3b6 100644 --- a/alib2data/src/grammar/Regular/LeftLG.h +++ b/alib2data/src/grammar/Regular/LeftLG.h @@ -19,7 +19,7 @@ namespace grammar { /** * Left linear grammar in chomsky normal form. Type 3 in Chomsky hierarchy. Produces regular languages. */ -class LeftLG : public std::element<LeftLG, GrammarBase>, public TerminalNonterminalAlphabetInitialSymbol { +class LeftLG : public std::acceptor<LeftLG, VisitableGrammarBase, std::acceptor<LeftLG, alib::VisitableObjectBase, GrammarBase> >, public TerminalNonterminalAlphabetInitialSymbol { std::map<alphabet::Symbol, std::set<std::variant<std::vector<alphabet::Symbol>, std::pair<alphabet::Symbol, std::vector<alphabet::Symbol>> >> > rules; public: LeftLG(const alphabet::Symbol& initialSymbol); @@ -46,9 +46,9 @@ public: bool removeNonterminalSymbol(const alphabet::Symbol& symbol); - virtual bool operator <(const ObjectBase& other) const; - virtual bool operator ==(const ObjectBase& other) const; - virtual bool operator >(const ObjectBase& other) const; + virtual bool operator <(const alib::ObjectBase& other) const; + virtual bool operator ==(const alib::ObjectBase& other) const; + virtual bool operator >(const alib::ObjectBase& other) const; virtual bool operator==(const LeftLG& other) const; diff --git a/alib2data/src/grammar/Regular/LeftRG.h b/alib2data/src/grammar/Regular/LeftRG.h index a763cbd2ad70a8e24bc265d69afd806fb6c290e3..409b6aaf9756643937febd424dc3cf91e848842e 100644 --- a/alib2data/src/grammar/Regular/LeftRG.h +++ b/alib2data/src/grammar/Regular/LeftRG.h @@ -27,7 +27,7 @@ namespace grammar { * * This definition has simplier handling of empty string generation and it is compatible with common definitions where the transformation from this definition to the common definition and backwards is trivial */ -class LeftRG : public std::element<LeftRG, GrammarBase>, public TerminalNonterminalAlphabetInitialSymbol { +class LeftRG : public std::acceptor<LeftRG, VisitableGrammarBase, std::acceptor<LeftRG, alib::VisitableObjectBase, GrammarBase> >, public TerminalNonterminalAlphabetInitialSymbol { /** * Transition function as mapping from nonterminal symbol on the left hand side to set of either terminal symbols or doublets of terminal symbol and nonterminal symbol */ @@ -116,17 +116,17 @@ public: /** * double dispatch operator helper */ - virtual bool operator <(const ObjectBase& other) const; + virtual bool operator <(const alib::ObjectBase& other) const; /** * double dispatch operator helper */ - virtual bool operator ==(const ObjectBase& other) const; + virtual bool operator ==(const alib::ObjectBase& other) const; /** * double dispatch operator helper */ - virtual bool operator >(const ObjectBase& other) const; + virtual bool operator >(const alib::ObjectBase& other) const; /** * equals operator diff --git a/alib2data/src/grammar/Regular/RightLG.h b/alib2data/src/grammar/Regular/RightLG.h index 0de454e89e60ec5499068f7dacee3adf4fa05ebc..1cadeeba5788abc57efb916b056dd3a22f408952 100644 --- a/alib2data/src/grammar/Regular/RightLG.h +++ b/alib2data/src/grammar/Regular/RightLG.h @@ -19,7 +19,7 @@ namespace grammar { /** * Right linear grammar in chomsky normal form. Type 3 in Chomsky hierarchy. Produces regular languages. */ -class RightLG : public std::element<RightLG, GrammarBase>, public TerminalNonterminalAlphabetInitialSymbol { +class RightLG : public std::acceptor<RightLG, VisitableGrammarBase, std::acceptor<RightLG, alib::VisitableObjectBase, GrammarBase> >, public TerminalNonterminalAlphabetInitialSymbol { std::map<alphabet::Symbol, std::set<std::variant<std::vector<alphabet::Symbol>, std::pair<std::vector<alphabet::Symbol>, alphabet::Symbol> >> > rules; public: RightLG(const alphabet::Symbol& initialSymbol); @@ -46,9 +46,9 @@ public: bool removeNonterminalSymbol(const alphabet::Symbol& symbol); - virtual bool operator <(const ObjectBase& other) const; - virtual bool operator ==(const ObjectBase& other) const; - virtual bool operator >(const ObjectBase& other) const; + virtual bool operator <(const alib::ObjectBase& other) const; + virtual bool operator ==(const alib::ObjectBase& other) const; + virtual bool operator >(const alib::ObjectBase& other) const; virtual bool operator==(const RightLG& other) const; diff --git a/alib2data/src/grammar/Regular/RightRG.h b/alib2data/src/grammar/Regular/RightRG.h index 4bc493ed149d050d9a496962219bbbf85acb32b4..4073501e4e3bdf4cbb438275bfef6db36d6d712a 100644 --- a/alib2data/src/grammar/Regular/RightRG.h +++ b/alib2data/src/grammar/Regular/RightRG.h @@ -27,7 +27,7 @@ namespace grammar { * * This definition has simplier handling of empty string generation and it is compatible with common definitions where the transformation from this definition to the common definition and backwards is trivial */ -class RightRG : public std::element<RightRG, GrammarBase>, public TerminalNonterminalAlphabetInitialSymbol { +class RightRG : public std::acceptor<RightRG, VisitableGrammarBase, std::acceptor<RightRG, alib::VisitableObjectBase, GrammarBase> >, public TerminalNonterminalAlphabetInitialSymbol { /** * Transition function as mapping from nonterminal symbol on the left hand side to set of either terminal symbols or doublets of terminal symbol and nonterminal symbol */ @@ -63,9 +63,9 @@ public: void setGeneratesEpsilon(bool genEps); bool getGeneratesEpsilon() const; - virtual bool operator <(const ObjectBase& other) const; - virtual bool operator ==(const ObjectBase& other) const; - virtual bool operator >(const ObjectBase& other) const; + virtual bool operator <(const alib::ObjectBase& other) const; + virtual bool operator ==(const alib::ObjectBase& other) const; + virtual bool operator >(const alib::ObjectBase& other) const; virtual bool operator==(const RightRG& other) const; diff --git a/alib2data/src/grammar/UnknownGrammar.h b/alib2data/src/grammar/UnknownGrammar.h index b2352804faedb766fa8560bef6569224fb29396f..6b33248dfae7278e88acf035ce2b3cceef035ef3 100644 --- a/alib2data/src/grammar/UnknownGrammar.h +++ b/alib2data/src/grammar/UnknownGrammar.h @@ -17,7 +17,7 @@ namespace grammar { /** * Class representing unknown grammar which was parsed from the XML. */ -class UnknownGrammar : public std::element<UnknownGrammar, GrammarBase> { +class UnknownGrammar : public std::acceptor<UnknownGrammar, VisitableGrammarBase, std::acceptor<UnknownGrammar, alib::VisitableObjectBase, GrammarBase> > { std::set<alphabet::Symbol> terminalAlphabet; std::set<alphabet::Symbol> nonterminalAlphabet; std::set<UnknownRule> rules; @@ -59,9 +59,9 @@ public: const std::set<UnknownRule>& getRules() const; - virtual bool operator <(const ObjectBase& other) const; - virtual bool operator ==(const ObjectBase& other) const; - virtual bool operator >(const ObjectBase& other) const; + virtual bool operator <(const alib::ObjectBase& other) const; + virtual bool operator ==(const alib::ObjectBase& other) const; + virtual bool operator >(const alib::ObjectBase& other) const; virtual bool operator==(const UnknownGrammar& other) const; diff --git a/alib2data/src/grammar/Unrestricted/ContextPreservingUnrestrictedGrammar.h b/alib2data/src/grammar/Unrestricted/ContextPreservingUnrestrictedGrammar.h index eaf3ae63b50107d6864aa0e5bfe18a7781155dcc..f35bfa3d989e91e8d2811012bacc4e05a810ebb5 100644 --- a/alib2data/src/grammar/Unrestricted/ContextPreservingUnrestrictedGrammar.h +++ b/alib2data/src/grammar/Unrestricted/ContextPreservingUnrestrictedGrammar.h @@ -18,7 +18,7 @@ namespace grammar { /** * Epsilon free context free grammar. Type 2 in Chomsky hierarchy. Produces context free languages. */ -class ContextPreservingUnrestrictedGrammar : public std::element<ContextPreservingUnrestrictedGrammar, GrammarBase>, public TerminalNonterminalAlphabetInitialSymbol { +class ContextPreservingUnrestrictedGrammar : public std::acceptor<ContextPreservingUnrestrictedGrammar, VisitableGrammarBase, std::acceptor<ContextPreservingUnrestrictedGrammar, alib::VisitableObjectBase, GrammarBase> >, public TerminalNonterminalAlphabetInitialSymbol { std::map<std::tuple<std::vector<alphabet::Symbol>, alphabet::Symbol, std::vector<alphabet::Symbol>>, std::set<std::vector<alphabet::Symbol>>> rules; public: ContextPreservingUnrestrictedGrammar(const alphabet::Symbol& initialSymbol); @@ -39,9 +39,9 @@ public: bool removeNonterminalSymbol(const alphabet::Symbol& symbol); - virtual bool operator <(const ObjectBase& other) const; - virtual bool operator ==(const ObjectBase& other) const; - virtual bool operator >(const ObjectBase& other) const; + virtual bool operator <(const alib::ObjectBase& other) const; + virtual bool operator ==(const alib::ObjectBase& other) const; + virtual bool operator >(const alib::ObjectBase& other) const; virtual bool operator==(const ContextPreservingUnrestrictedGrammar& other) const; diff --git a/alib2data/src/grammar/Unrestricted/UnrestrictedGrammar.h b/alib2data/src/grammar/Unrestricted/UnrestrictedGrammar.h index f38892998a1b2ef78e246e534f3a7f269d228316..9b15d7c84e38205ebb2e35fc629106ea2b716d75 100644 --- a/alib2data/src/grammar/Unrestricted/UnrestrictedGrammar.h +++ b/alib2data/src/grammar/Unrestricted/UnrestrictedGrammar.h @@ -18,7 +18,7 @@ namespace grammar { /** * Unrestricted grammar. Type 0 in Chomsky hierarchy. Produces recursively enumerable language. */ -class UnrestrictedGrammar : public std::element<UnrestrictedGrammar, GrammarBase>, public TerminalNonterminalAlphabetInitialSymbol { +class UnrestrictedGrammar : public std::acceptor<UnrestrictedGrammar, VisitableGrammarBase, std::acceptor<UnrestrictedGrammar, alib::VisitableObjectBase, GrammarBase> >, public TerminalNonterminalAlphabetInitialSymbol { std::map<std::vector<alphabet::Symbol>, std::set<std::vector<alphabet::Symbol>>> rules; public: @@ -40,9 +40,9 @@ public: bool removeNonterminalSymbol(const alphabet::Symbol& symbol); - virtual bool operator <(const ObjectBase& other) const; - virtual bool operator ==(const ObjectBase& other) const; - virtual bool operator >(const ObjectBase& other) const; + virtual bool operator <(const alib::ObjectBase& other) const; + virtual bool operator ==(const alib::ObjectBase& other) const; + virtual bool operator >(const alib::ObjectBase& other) const; virtual bool operator==(const UnrestrictedGrammar& other) const; diff --git a/alib2data/src/label/CharacterLabel.cpp b/alib2data/src/label/CharacterLabel.cpp index 1b08bc182b397dc5a7aca55bc8a331cd6e0ad507..cb5a585ea178e52b4c2f1b7121bd39bfb9ac0425 100644 --- a/alib2data/src/label/CharacterLabel.cpp +++ b/alib2data/src/label/CharacterLabel.cpp @@ -25,15 +25,15 @@ char CharacterLabel::getData() const { return label; } -bool CharacterLabel::operator<(const ObjectBase& other) const { +bool CharacterLabel::operator<(const alib::ObjectBase& other) const { return other > *this; } -bool CharacterLabel::operator==(const ObjectBase& other) const { +bool CharacterLabel::operator==(const alib::ObjectBase& other) const { return other == *this; } -bool CharacterLabel::operator >(const ObjectBase& other) const { +bool CharacterLabel::operator >(const alib::ObjectBase& other) const { return other < *this; } diff --git a/alib2data/src/label/CharacterLabel.h b/alib2data/src/label/CharacterLabel.h index b46773ad259941e0b0fd8fb13756da41204a3642..29f11b5845e22baec433261716491650c9c0af12 100644 --- a/alib2data/src/label/CharacterLabel.h +++ b/alib2data/src/label/CharacterLabel.h @@ -18,7 +18,7 @@ namespace label { /** * Represents symbol in an alphabet. */ -class CharacterLabel : public std::element<CharacterLabel, LabelBase> { +class CharacterLabel : public std::acceptor<CharacterLabel, VisitableLabelBase, std::acceptor<CharacterLabel, alib::VisitableObjectBase, LabelBase> > { protected: char label; public: @@ -32,11 +32,11 @@ public: */ explicit CharacterLabel(char label); - virtual bool operator<(const ObjectBase& other) const; + virtual bool operator<(const alib::ObjectBase& other) const; - virtual bool operator>(const ObjectBase& other) const; + virtual bool operator>(const alib::ObjectBase& other) const; - virtual bool operator==(const ObjectBase& other) const; + virtual bool operator==(const alib::ObjectBase& other) const; /** * @return name of the symbol diff --git a/alib2data/src/label/IntegerLabel.cpp b/alib2data/src/label/IntegerLabel.cpp index 0fee9f5e01c5a299b7754846ce235010b488c4e4..7dee237370aa9b933a410d92a99161e2b6af64c1 100644 --- a/alib2data/src/label/IntegerLabel.cpp +++ b/alib2data/src/label/IntegerLabel.cpp @@ -25,15 +25,15 @@ int IntegerLabel::getData() const { return label; } -bool IntegerLabel::operator <(const ObjectBase& other) const { +bool IntegerLabel::operator <(const alib::ObjectBase& other) const { return other > *this; } -bool IntegerLabel::operator ==(const ObjectBase& other) const { +bool IntegerLabel::operator ==(const alib::ObjectBase& other) const { return other == *this; } -bool IntegerLabel::operator >(const ObjectBase& other) const { +bool IntegerLabel::operator >(const alib::ObjectBase& other) const { return other < *this; } diff --git a/alib2data/src/label/IntegerLabel.h b/alib2data/src/label/IntegerLabel.h index 6a192146fa24e3a93b650f8d080dee48dfa7d2bc..673543926a7c0fe4f6d163b3559a95a823a9fe05 100644 --- a/alib2data/src/label/IntegerLabel.h +++ b/alib2data/src/label/IntegerLabel.h @@ -17,7 +17,7 @@ namespace label { /** * Represents symbol in an alphabet. */ -class IntegerLabel : public std::element<IntegerLabel, LabelBase> { +class IntegerLabel : public std::acceptor<IntegerLabel, VisitableLabelBase, std::acceptor<IntegerLabel, alib::VisitableObjectBase, LabelBase> > { protected: int label; public: @@ -31,11 +31,11 @@ public: */ explicit IntegerLabel(int label); - virtual bool operator<(const ObjectBase& other) const; + virtual bool operator<(const alib::ObjectBase& other) const; - virtual bool operator>(const ObjectBase& other) const; + virtual bool operator>(const alib::ObjectBase& other) const; - virtual bool operator==(const ObjectBase& other) const; + virtual bool operator==(const alib::ObjectBase& other) const; /** * @return name of the symbol diff --git a/alib2data/src/label/LabelBase.h b/alib2data/src/label/LabelBase.h index 6e152e5bb0b65a1b854e9d5ce653917a9ea48b66..4e63facceff03d4b20bfd4acf3340dd0151344a1 100644 --- a/alib2data/src/label/LabelBase.h +++ b/alib2data/src/label/LabelBase.h @@ -13,11 +13,18 @@ namespace label { +typedef std::acceptor_base< + label::StringLabel, label::IntegerLabel, label::CharacterLabel + > VisitableLabelBase; + /** * Abstract base class for all automata. */ -class LabelBase : public alib:: ObjectBase { +class LabelBase : public alib::ObjectBase, public VisitableLabelBase { public: + using VisitableLabelBase::Accept; + using alib::VisitableObjectBase::Accept; + virtual LabelBase* clone() const = 0; virtual LabelBase* plunder() && = 0; diff --git a/alib2data/src/label/LabelToStringComposer.cpp b/alib2data/src/label/LabelToStringComposer.cpp index 722bf0a182c46365b5198e585758f717393811fe..5bf82877498190d691285e62b40b9f7cc60c372f 100644 --- a/alib2data/src/label/LabelToStringComposer.cpp +++ b/alib2data/src/label/LabelToStringComposer.cpp @@ -29,26 +29,21 @@ void LabelToStringComposer::Visit(void* userData, const label::StringLabel& labe out << '\'' << tmp << '\''; } -void LabelToStringComposer::Visit(void* userData, const CharacterLabel& symbol) { +void LabelToStringComposer::Visit(void* userData, const CharacterLabel& label) { std::stringstream &out = *((std::stringstream*) userData); - out << symbol.getData(); + out << label.getData(); } -void LabelToStringComposer::Visit(void* userData, const IntegerLabel& symbol) { +void LabelToStringComposer::Visit(void* userData, const IntegerLabel& label) { std::stringstream &out = *((std::stringstream*) userData); - out << symbol.getData(); + out << label.getData(); } -void LabelToStringComposer::Visit(void* userData, const Label& symbol) { - symbol.getData().Accept(userData, *this); - -} - -std::string LabelToStringComposer::compose(const Label& symbol) { +std::string LabelToStringComposer::compose(const Label& label) { std::stringstream out; - Visit((void*) &out, symbol); + label.getData().Accept((void*) &out, *this); return std::move(out).str(); } diff --git a/alib2data/src/label/LabelToStringComposer.h b/alib2data/src/label/LabelToStringComposer.h index c3883e0d772227700dfaa958d546948428d2605c..5fbbfe8458a4ea83a78fe3cd56bf55045bdea1f6 100644 --- a/alib2data/src/label/LabelToStringComposer.h +++ b/alib2data/src/label/LabelToStringComposer.h @@ -18,8 +18,7 @@ namespace label { /** * This class contains methods to print XML representation of string to the output stream. */ -class LabelToStringComposer : public LabelBase::visitor_type { - void Visit(void*, const Label& label); +class LabelToStringComposer : public VisitableLabelBase::visitor_type { void Visit(void*, const IntegerLabel& label); void Visit(void*, const StringLabel& label); void Visit(void*, const CharacterLabel& label); diff --git a/alib2data/src/label/NextLabel.cpp b/alib2data/src/label/NextLabel.cpp index 51e60c336379ef45cd14560218e97a4c3fd59ae6..c272f6103c9f7ae5ebab468854775e1b8573c0f7 100644 --- a/alib2data/src/label/NextLabel.cpp +++ b/alib2data/src/label/NextLabel.cpp @@ -31,14 +31,9 @@ void NextLabel::Visit(void* userData, const StringLabel& label) { out = new Label(StringLabel(label.getData() + '\'')); } -void NextLabel::Visit(void* userData, const Label& label) { - label.getData().Accept(userData, *this); - -} - Label NextLabel::nextLabel(const Label& label) { Label* out; - Visit((void*) &out, label); + label.getData().Accept((void*) &out, *this); Label nextLabel(std::move(*out)); delete out; diff --git a/alib2data/src/label/NextLabel.h b/alib2data/src/label/NextLabel.h index 62e07d67087fd6a96d20b1cf073e1afa782ba1fe..c5657ebb3587039c03c62477956825ad3f973ee0 100644 --- a/alib2data/src/label/NextLabel.h +++ b/alib2data/src/label/NextLabel.h @@ -17,8 +17,7 @@ namespace label { /** * This class contains methods to print XML representation of string to the output stream. */ -class NextLabel : public LabelBase::visitor_type { - void Visit(void*, const Label& label); +class NextLabel : public VisitableLabelBase::visitor_type { void Visit(void*, const StringLabel& label); void Visit(void*, const IntegerLabel& label); void Visit(void*, const CharacterLabel& label); diff --git a/alib2data/src/label/StringLabel.cpp b/alib2data/src/label/StringLabel.cpp index 6fe963c55e442eab4ab73cfa2acc1ca79f5989ee..4f3c98ffe63261f3752d40fd5acb12aff58188ea 100644 --- a/alib2data/src/label/StringLabel.cpp +++ b/alib2data/src/label/StringLabel.cpp @@ -29,15 +29,15 @@ const std::string& StringLabel::getData() const { return label; } -bool StringLabel::operator<(const ObjectBase& other) const { +bool StringLabel::operator<(const alib::ObjectBase& other) const { return other > *this; } -bool StringLabel::operator==(const ObjectBase& other) const { +bool StringLabel::operator==(const alib::ObjectBase& other) const { return other == *this; } -bool StringLabel::operator >(const ObjectBase& other) const { +bool StringLabel::operator >(const alib::ObjectBase& other) const { return other < *this; } diff --git a/alib2data/src/label/StringLabel.h b/alib2data/src/label/StringLabel.h index 019264459026f90bd0947580c323e9adb7c245fa..286a840cedaa9c6d9cad717fff120c147a4d502f 100644 --- a/alib2data/src/label/StringLabel.h +++ b/alib2data/src/label/StringLabel.h @@ -18,7 +18,7 @@ namespace label { /** * Represents symbol in an alphabet. */ -class StringLabel : public std::element<StringLabel, LabelBase> { +class StringLabel : public std::acceptor<StringLabel, VisitableLabelBase, std::acceptor<StringLabel, alib::VisitableObjectBase, LabelBase> > { protected: std::string label; public: @@ -33,11 +33,11 @@ public: explicit StringLabel(const std::string& label); explicit StringLabel(std::string&& label); - virtual bool operator<(const ObjectBase& other) const; + virtual bool operator<(const alib::ObjectBase& other) const; - virtual bool operator>(const ObjectBase& other) const; + virtual bool operator>(const alib::ObjectBase& other) const; - virtual bool operator==(const ObjectBase& other) const; + virtual bool operator==(const alib::ObjectBase& other) const; /** * @return name of the symbol diff --git a/alib2data/src/object/ObjectBase.h b/alib2data/src/object/ObjectBase.h index c888b34f8ce6db7298bc72f256ff9cc73dbcf823..a03acaf9d3889ec70d7edc8e54ee3f9e366dd9db 100644 --- a/alib2data/src/object/ObjectBase.h +++ b/alib2data/src/object/ObjectBase.h @@ -90,9 +90,7 @@ class ObjectsSet; namespace alib { -class ObjectBase : - public alib::base< - ObjectBase, +typedef std::acceptor_base< exception::AlibException, automaton::UnknownAutomaton, automaton::DFA, automaton::NFA, automaton::EpsilonNFA, automaton::CompactNFA, automaton::ExtendedNFA, automaton::NPDA, automaton::SinglePopNPDA, automaton::OneTapeDTM, grammar::UnknownGrammar, grammar::LeftLG, grammar::LeftRG, grammar::RightLG, grammar::RightRG, grammar::LG, grammar::CFG, grammar::EpsilonFreeCFG, grammar::CNF, grammar::GNF, grammar::CSG, grammar::NonContractingGrammar, grammar::ContextPreservingUnrestrictedGrammar, grammar::UnrestrictedGrammar, @@ -101,8 +99,11 @@ class ObjectBase : string::Epsilon, string::LinearString, string::CyclicString, alphabet::LabeledSymbol, alphabet::BlankSymbol, alphabet::BottomOfTheStackSymbol, alphabet::EndSymbol, container::ObjectsSet - >, - public std::elementBase< + > VisitableObjectBase; + +class ObjectBase : + public alib::base< + ObjectBase, exception::AlibException, automaton::UnknownAutomaton, automaton::DFA, automaton::NFA, automaton::EpsilonNFA, automaton::CompactNFA, automaton::ExtendedNFA, automaton::NPDA, automaton::SinglePopNPDA, automaton::OneTapeDTM, grammar::UnknownGrammar, grammar::LeftLG, grammar::LeftRG, grammar::RightLG, grammar::RightRG, grammar::LG, grammar::CFG, grammar::EpsilonFreeCFG, grammar::CNF, grammar::GNF, grammar::CSG, grammar::NonContractingGrammar, grammar::ContextPreservingUnrestrictedGrammar, grammar::UnrestrictedGrammar, @@ -111,7 +112,7 @@ class ObjectBase : string::Epsilon, string::LinearString, string::CyclicString, alphabet::LabeledSymbol, alphabet::BlankSymbol, alphabet::BottomOfTheStackSymbol, alphabet::EndSymbol, container::ObjectsSet - > { + >, public VisitableObjectBase { }; } /* namespace alib */ diff --git a/alib2data/src/regexp/RegExpAlphabetGetter.cpp b/alib2data/src/regexp/RegExpAlphabetGetter.cpp index 465492584228a05473b6194da344fe4ca2a34ba9..c34882045187d1c11e8b01bb0a441c8dcb15ea7d 100644 --- a/alib2data/src/regexp/RegExpAlphabetGetter.cpp +++ b/alib2data/src/regexp/RegExpAlphabetGetter.cpp @@ -9,14 +9,6 @@ namespace regexp { -void RegExpAlphabetGetter::Visit(void* userData, const RegExp& regexp) const { - regexp.getData().Accept(userData, *this); -} - -void RegExpAlphabetGetter::Visit(void* userData, const RegExpBase::element_type& element) const { - element.Accept(userData, *this); -} - void RegExpAlphabetGetter::Visit(void* userData, const UnboundedRegExp& regexp) const { std::set<alphabet::Symbol> &res = *((std::set<alphabet::Symbol>*) userData); res = regexp.getAlphabet(); @@ -29,7 +21,7 @@ void RegExpAlphabetGetter::Visit(void* userData, const FormalRegExp& regexp) con std::set<alphabet::Symbol> RegExpAlphabetGetter::getAlphabet(const RegExp& regexp) const { std::set<alphabet::Symbol> res; - Visit((void*) &res, regexp); + regexp.getData().Accept((void*) &res, *this); return std::move(res); } diff --git a/alib2data/src/regexp/RegExpAlphabetGetter.h b/alib2data/src/regexp/RegExpAlphabetGetter.h index 3dded28b2d9da29c6ed8a78287509fed5ef1bc24..d278c1153f30724d736d658a002ffb4f3aacc72a 100644 --- a/alib2data/src/regexp/RegExpAlphabetGetter.h +++ b/alib2data/src/regexp/RegExpAlphabetGetter.h @@ -16,14 +16,10 @@ namespace regexp { -class RegExpAlphabetGetter : public RegExpBase::const_visitor_type { +class RegExpAlphabetGetter : public VisitableRegExpBase::const_visitor_type { void Visit(void*, const UnboundedRegExp& empty) const; void Visit(void*, const FormalRegExp& empty) const; - void Visit(void*, const RegExpBase::element_type& element) const; - - void Visit(void*, const RegExp& empty) const; - public: /** * Composes string representation of RegExp. diff --git a/alib2data/src/regexp/RegExpBase.h b/alib2data/src/regexp/RegExpBase.h index 27579143a177dd3a17935a2ec378711abac3d8eb..db3ae48d4f0ff45ab4641c96e3c62c4d6facc4ed 100644 --- a/alib2data/src/regexp/RegExpBase.h +++ b/alib2data/src/regexp/RegExpBase.h @@ -13,11 +13,18 @@ namespace regexp { +typedef std::acceptor_base< + UnboundedRegExp, FormalRegExp + > VisitableRegExpBase; + /** * Abstract base class for all automata. */ -class RegExpBase : public alib::ObjectBase { +class RegExpBase : public alib::ObjectBase, public VisitableRegExpBase { public: + using VisitableRegExpBase::Accept; + using alib::VisitableObjectBase::Accept; + virtual RegExpBase* clone() const = 0; virtual RegExpBase* plunder() && = 0; }; diff --git a/alib2data/src/regexp/RegExpToStringComposer.cpp b/alib2data/src/regexp/RegExpToStringComposer.cpp index 9bd0d703bf40b71fa59f8550351d5cd597c57a78..b0327c6414a540e15f696da3da23a9e7414d0081 100644 --- a/alib2data/src/regexp/RegExpToStringComposer.cpp +++ b/alib2data/src/regexp/RegExpToStringComposer.cpp @@ -12,10 +12,6 @@ namespace regexp { -void RegExpToStringComposer::Visit(void* userData, const RegExp& regexp) { - regexp.getData().Accept(userData, *this); -} - void RegExpToStringComposer::Visit(void* userData, const UnboundedRegExp& regexp) { regexp.getRegExp().Accept(userData, *this); } @@ -31,7 +27,7 @@ void RegExpToStringComposer::Visit(void* userData, const UnboundedRegExpAlternat out.second << "#0"; } else if(alternation.getElements().size() == 1) { const auto& element = alternation.getElements()[0]; - const UnboundedRegExpElement::element_type& object = static_cast<const UnboundedRegExpElement::element_type&>(*element); + const UnboundedRegExpElement& object = static_cast<const UnboundedRegExpElement&>(*element); object.Accept(userData, *this); } else { Priority outerPriorityMinimum = out.first; @@ -43,7 +39,7 @@ void RegExpToStringComposer::Visit(void* userData, const UnboundedRegExpAlternat } else { out.second << '+'; } - const UnboundedRegExpElement::element_type& object = static_cast<const UnboundedRegExpElement::element_type&>(*element); + const UnboundedRegExpElement& object = static_cast<const UnboundedRegExpElement&>(*element); out.first = Priority::ALTERNATION; object.Accept(userData, *this); } @@ -59,7 +55,7 @@ void RegExpToStringComposer::Visit(void* userData, const UnboundedRegExpConcaten out.second << "#E"; } else if(concatenation.getElements().size() == 1) { const auto& element = concatenation.getElements()[0]; - const UnboundedRegExpElement::element_type& object = static_cast<const UnboundedRegExpElement::element_type&>(*element); + const UnboundedRegExpElement& object = static_cast<const UnboundedRegExpElement&>(*element); object.Accept(userData, *this); } else { if(outerPriorityMinimum == Priority::FACTOR) out.second << '('; @@ -69,7 +65,7 @@ void RegExpToStringComposer::Visit(void* userData, const UnboundedRegExpConcaten first = false; else out.second << ' '; - const UnboundedRegExpElement::element_type& object = static_cast<const UnboundedRegExpElement::element_type&>(*element); + const UnboundedRegExpElement& object = static_cast<const UnboundedRegExpElement&>(*element); out.first = Priority::CONCATENATION; object.Accept(userData, *this); } @@ -80,7 +76,7 @@ void RegExpToStringComposer::Visit(void* userData, const UnboundedRegExpConcaten void RegExpToStringComposer::Visit(void* userData, const UnboundedRegExpIteration& iteration) { std::pair<Priority, std::stringstream> &out = *((std::pair<Priority, std::stringstream>*) userData); - const UnboundedRegExpElement::element_type& object = static_cast<const UnboundedRegExpElement::element_type&>(iteration.getElement()); + const UnboundedRegExpElement& object = static_cast<const UnboundedRegExpElement&>(iteration.getElement()); out.first = Priority::FACTOR; object.Accept(userData, *this); out.second << "*"; @@ -113,7 +109,7 @@ void RegExpToStringComposer::Visit(void* userData, const FormalRegExpAlternation { const auto& element = alternation.getLeftElement(); - const FormalRegExpElement::element_type& object = static_cast<const FormalRegExpElement::element_type&>(element); + const FormalRegExpElement& object = static_cast<const FormalRegExpElement&>(element); object.Accept(userData, *this); } @@ -121,7 +117,7 @@ void RegExpToStringComposer::Visit(void* userData, const FormalRegExpAlternation { const auto& element = alternation.getRightElement(); - const FormalRegExpElement::element_type& object = static_cast<const FormalRegExpElement::element_type&>(element); + const FormalRegExpElement& object = static_cast<const FormalRegExpElement&>(element); object.Accept(userData, *this); } @@ -138,7 +134,7 @@ void RegExpToStringComposer::Visit(void* userData, const FormalRegExpConcatenati { const auto& element = concatenation.getLeftElement(); - const FormalRegExpElement::element_type& object = static_cast<const FormalRegExpElement::element_type&>(element); + const FormalRegExpElement& object = static_cast<const FormalRegExpElement&>(element); object.Accept(userData, *this); } @@ -146,7 +142,7 @@ void RegExpToStringComposer::Visit(void* userData, const FormalRegExpConcatenati { const auto& element = concatenation.getRightElement(); - const FormalRegExpElement::element_type& object = static_cast<const FormalRegExpElement::element_type&>(element); + const FormalRegExpElement& object = static_cast<const FormalRegExpElement&>(element); object.Accept(userData, *this); } @@ -156,7 +152,7 @@ void RegExpToStringComposer::Visit(void* userData, const FormalRegExpConcatenati void RegExpToStringComposer::Visit(void* userData, const FormalRegExpIteration& iteration) { std::pair<Priority, std::stringstream> &out = *((std::pair<Priority, std::stringstream>*) userData); - const FormalRegExpElement::element_type& object = static_cast<const FormalRegExpElement::element_type&>(iteration.getElement()); + const FormalRegExpElement& object = static_cast<const FormalRegExpElement&>(iteration.getElement()); out.first = Priority::FACTOR; object.Accept(userData, *this); out.second << "*"; @@ -182,7 +178,7 @@ void RegExpToStringComposer::Visit(void* userData, const FormalRegExpEmpty&) { std::string RegExpToStringComposer::compose(const RegExp& regexp) { std::pair<Priority, std::stringstream> out; out.first = Priority::ALTERNATION; - Visit((void*) &out, regexp); + regexp.getData().Accept((void*) &out, *this); return std::move(out.second).str(); } diff --git a/alib2data/src/regexp/RegExpToStringComposer.h b/alib2data/src/regexp/RegExpToStringComposer.h index 00c57fe42bbe42b10a110772f32b5fd139981f4e..104f049881ef51ad74a8eb074357093bef7b1a6b 100644 --- a/alib2data/src/regexp/RegExpToStringComposer.h +++ b/alib2data/src/regexp/RegExpToStringComposer.h @@ -15,7 +15,7 @@ namespace regexp { -class RegExpToStringComposer : public RegExpBase::visitor_type, UnboundedRegExpElement::visitor_type, FormalRegExpElement::visitor_type { +class RegExpToStringComposer : public VisitableRegExpBase::visitor_type, UnboundedRegExpElement::visitor_type, FormalRegExpElement::visitor_type { void Visit(void*, const UnboundedRegExpAlternation& alternation); void Visit(void*, const UnboundedRegExpConcatenation& concatenation); void Visit(void*, const UnboundedRegExpIteration& iteration); @@ -36,8 +36,6 @@ class RegExpToStringComposer : public RegExpBase::visitor_type, UnboundedRegExpE void Visit(void*, const FormalRegExp& empty); - void Visit(void*, const RegExp& empty); - enum class Priority { ALTERNATION, CONCATENATION, diff --git a/alib2data/src/regexp/RegExpToXMLComposer.cpp b/alib2data/src/regexp/RegExpToXMLComposer.cpp index d7514d4c2b2ca20ae6072a9a8d2001b9724f24e8..4142f82e835ec5763485c79a6a7bf67aece0f8b6 100644 --- a/alib2data/src/regexp/RegExpToXMLComposer.cpp +++ b/alib2data/src/regexp/RegExpToXMLComposer.cpp @@ -16,7 +16,7 @@ void RegExpToXMLComposer::Visit(void* userData, const UnboundedRegExpAlternation out.push_back(sax::Token("alternation", sax::Token::TokenType::START_ELEMENT)); for (const auto& element : alternation.getElements()) { - const UnboundedRegExpElement::element_type& object = static_cast<const UnboundedRegExpElement::element_type&>(*element); + const UnboundedRegExpElement& object = static_cast<const UnboundedRegExpElement&>(*element); object.Accept(userData, *this); } out.push_back(sax::Token("alternation", sax::Token::TokenType::END_ELEMENT)); @@ -27,7 +27,7 @@ void RegExpToXMLComposer::Visit(void* userData, const UnboundedRegExpConcatenati out.push_back(sax::Token("concatenation", sax::Token::TokenType::START_ELEMENT)); for (auto element : concatenation.getElements()) { - const UnboundedRegExpElement::element_type& object = static_cast<const UnboundedRegExpElement::element_type&>(*element); + const UnboundedRegExpElement& object = static_cast<const UnboundedRegExpElement&>(*element); object.Accept(userData, *this); } out.push_back(sax::Token("concatenation", sax::Token::TokenType::END_ELEMENT)); @@ -38,7 +38,7 @@ void RegExpToXMLComposer::Visit(void* userData, const UnboundedRegExpIteration& std::list<sax::Token> &out = *((std::list<sax::Token>*) userData); out.push_back(sax::Token("iteration", sax::Token::TokenType::START_ELEMENT)); - const UnboundedRegExpElement::element_type& object = static_cast<const UnboundedRegExpElement::element_type&>(iteration.getElement()); + const UnboundedRegExpElement& object = static_cast<const UnboundedRegExpElement&>(iteration.getElement()); object.Accept(userData, *this); out.push_back(sax::Token("iteration", sax::Token::TokenType::END_ELEMENT)); } @@ -69,12 +69,12 @@ void RegExpToXMLComposer::Visit(void* userData, const FormalRegExpAlternation& a out.push_back(sax::Token("alternation", sax::Token::TokenType::START_ELEMENT)); { const auto& element = alternation.getLeftElement(); - const FormalRegExpElement::element_type& object = static_cast<const FormalRegExpElement::element_type&>(element); + const FormalRegExpElement& object = static_cast<const FormalRegExpElement&>(element); object.Accept(userData, *this); } { const auto& element = alternation.getRightElement(); - const FormalRegExpElement::element_type& object = static_cast<const FormalRegExpElement::element_type&>(element); + const FormalRegExpElement& object = static_cast<const FormalRegExpElement&>(element); object.Accept(userData, *this); } out.push_back(sax::Token("alternation", sax::Token::TokenType::END_ELEMENT)); @@ -86,12 +86,12 @@ void RegExpToXMLComposer::Visit(void* userData, const FormalRegExpConcatenation& out.push_back(sax::Token("concatenation", sax::Token::TokenType::START_ELEMENT)); { const auto& element = concatenation.getLeftElement(); - const FormalRegExpElement::element_type& object = static_cast<const FormalRegExpElement::element_type&>(element); + const FormalRegExpElement& object = static_cast<const FormalRegExpElement&>(element); object.Accept(userData, *this); } { const auto& element = concatenation.getRightElement(); - const FormalRegExpElement::element_type& object = static_cast<const FormalRegExpElement::element_type&>(element); + const FormalRegExpElement& object = static_cast<const FormalRegExpElement&>(element); object.Accept(userData, *this); } out.push_back(sax::Token("concatenation", sax::Token::TokenType::END_ELEMENT)); @@ -102,7 +102,7 @@ void RegExpToXMLComposer::Visit(void* userData, const FormalRegExpIteration& ite std::list<sax::Token> &out = *((std::list<sax::Token>*) userData); out.push_back(sax::Token("iteration", sax::Token::TokenType::START_ELEMENT)); - const FormalRegExpElement::element_type& object = static_cast<const FormalRegExpElement::element_type&>(iteration.getElement()); + const FormalRegExpElement& object = static_cast<const FormalRegExpElement&>(iteration.getElement()); object.Accept(userData, *this); out.push_back(sax::Token("iteration", sax::Token::TokenType::END_ELEMENT)); } diff --git a/alib2data/src/regexp/formal/FormalRegExp.h b/alib2data/src/regexp/formal/FormalRegExp.h index 2be736b626227daeae81170c996ca26f608f7ae4..56e2edbf96cb5a22a31bdf0355152c2c45e1a631 100644 --- a/alib2data/src/regexp/formal/FormalRegExp.h +++ b/alib2data/src/regexp/formal/FormalRegExp.h @@ -24,7 +24,7 @@ class FormalRegExpElement; * Represents regular expression parsed from the XML. Regular expression is stored * as a tree of RegExpElement. */ -class FormalRegExp : public std::element<FormalRegExp, RegExpBase> { +class FormalRegExp : public std::acceptor<FormalRegExp, VisitableRegExpBase, std::acceptor<FormalRegExp, alib::VisitableObjectBase, RegExpBase> > { protected: FormalRegExpElement* regExp; @@ -122,9 +122,9 @@ public: */ virtual void operator>>(std::ostream& out) const; - virtual bool operator <(const ObjectBase& other) const; - virtual bool operator ==(const ObjectBase& other) const; - virtual bool operator >(const ObjectBase& other) const; + virtual bool operator <(const alib::ObjectBase& other) const; + virtual bool operator ==(const alib::ObjectBase& other) const; + virtual bool operator >(const alib::ObjectBase& other) const; virtual bool operator==(const FormalRegExp& other) const; diff --git a/alib2data/src/regexp/formal/FormalRegExpAlternation.h b/alib2data/src/regexp/formal/FormalRegExpAlternation.h index 200a00f5712676b1da097db59f087ded9348eaf0..b162e395350e8ba259f065a491e2c8e76726a6eb 100644 --- a/alib2data/src/regexp/formal/FormalRegExpAlternation.h +++ b/alib2data/src/regexp/formal/FormalRegExpAlternation.h @@ -17,7 +17,7 @@ namespace regexp { * Represents alternation operator in the regular expression. Contains list of FormalRegExpElement * as operands of the operator. */ -class FormalRegExpAlternation: public std::element<FormalRegExpAlternation, FormalRegExpElement> { +class FormalRegExpAlternation: public std::acceptor<FormalRegExpAlternation, FormalRegExpElement, FormalRegExpElement> { protected: /** * @copydoc FormalRegExpElement::clone() const diff --git a/alib2data/src/regexp/formal/FormalRegExpConcatenation.h b/alib2data/src/regexp/formal/FormalRegExpConcatenation.h index c5cf985af0af750a9546e911bc4df45ec8fbdaaf..760671bd97cc933972d621c251a31c81c18bad6a 100644 --- a/alib2data/src/regexp/formal/FormalRegExpConcatenation.h +++ b/alib2data/src/regexp/formal/FormalRegExpConcatenation.h @@ -17,7 +17,7 @@ namespace regexp { * Represents concatenation operator in the regular expression. Contains list of FormalRegExpElement * as operands of the operator. */ -class FormalRegExpConcatenation: public std::element<FormalRegExpConcatenation, FormalRegExpElement> { +class FormalRegExpConcatenation: public std::acceptor<FormalRegExpConcatenation, FormalRegExpElement, FormalRegExpElement> { protected: /** * @copydoc FormalRegExpElement::clone() const diff --git a/alib2data/src/regexp/formal/FormalRegExpElement.h b/alib2data/src/regexp/formal/FormalRegExpElement.h index a5d6240fffd90c173837ecdd2226009108b1fdfb..a8c83b1522d0e33bcbf3304e6ad6c8d970c31587 100644 --- a/alib2data/src/regexp/formal/FormalRegExpElement.h +++ b/alib2data/src/regexp/formal/FormalRegExpElement.h @@ -29,7 +29,7 @@ class UnboundedRegExpElement; /** * Abstract class representing element in the regular expression. Can be operator or symbol. */ -class FormalRegExpElement : public std::elementBase<FormalRegExpAlternation, FormalRegExpConcatenation, FormalRegExpIteration, FormalRegExpSymbol, FormalRegExpEmpty, FormalRegExpEpsilon> { +class FormalRegExpElement : public std::acceptor_base<FormalRegExpAlternation, FormalRegExpConcatenation, FormalRegExpIteration, FormalRegExpSymbol, FormalRegExpEmpty, FormalRegExpEpsilon> { protected: /* * Parent regexp contanining this instance of RegExpElement diff --git a/alib2data/src/regexp/formal/FormalRegExpEmpty.h b/alib2data/src/regexp/formal/FormalRegExpEmpty.h index 2416ac97b99ba3b01561657b2b2c42389893d238..66e39df1ba3785ceb7a212041f9092b55c8d856c 100644 --- a/alib2data/src/regexp/formal/FormalRegExpEmpty.h +++ b/alib2data/src/regexp/formal/FormalRegExpEmpty.h @@ -15,7 +15,7 @@ namespace regexp { /** * Represents empty regular expression in the regular expression. */ -class FormalRegExpEmpty: public std::element<FormalRegExpEmpty, FormalRegExpElement> { +class FormalRegExpEmpty: public std::acceptor<FormalRegExpEmpty, FormalRegExpElement, FormalRegExpElement> { protected: /** * @copydoc FormalRegExpElement::clone() const diff --git a/alib2data/src/regexp/formal/FormalRegExpEpsilon.h b/alib2data/src/regexp/formal/FormalRegExpEpsilon.h index 9c510aaf5878ca2ee8840b228be407be6e2f7545..1f184cea3479c67082f25b33f45b3a24af848ea4 100644 --- a/alib2data/src/regexp/formal/FormalRegExpEpsilon.h +++ b/alib2data/src/regexp/formal/FormalRegExpEpsilon.h @@ -15,7 +15,7 @@ namespace regexp { /** * Represents epsilon in the regular expression. */ -class FormalRegExpEpsilon: public std::element<FormalRegExpEpsilon, FormalRegExpElement> { +class FormalRegExpEpsilon: public std::acceptor<FormalRegExpEpsilon, FormalRegExpElement, FormalRegExpElement> { protected: /** * @copydoc FormalRegExpElement::clone() const diff --git a/alib2data/src/regexp/formal/FormalRegExpIteration.h b/alib2data/src/regexp/formal/FormalRegExpIteration.h index 1d3a4110f25a63658dfa675e5ded2d97399a9769..3c41b35a71de7a4767a4deeaa700c378958573e5 100644 --- a/alib2data/src/regexp/formal/FormalRegExpIteration.h +++ b/alib2data/src/regexp/formal/FormalRegExpIteration.h @@ -17,7 +17,7 @@ namespace regexp { * Represents iteration operator in the regular expression. Contains one FormalRegExpElement * as operand. */ -class FormalRegExpIteration: public std::element<FormalRegExpIteration, FormalRegExpElement> { +class FormalRegExpIteration: public std::acceptor<FormalRegExpIteration, FormalRegExpElement, FormalRegExpElement> { protected: FormalRegExpElement* element; diff --git a/alib2data/src/regexp/formal/FormalRegExpSymbol.h b/alib2data/src/regexp/formal/FormalRegExpSymbol.h index f7c4615e991893a5dd5bc3fe422ee801fd7e7f86..04afb7c3bd6a3cf1106b3ccbfc1b17576a620c9d 100644 --- a/alib2data/src/regexp/formal/FormalRegExpSymbol.h +++ b/alib2data/src/regexp/formal/FormalRegExpSymbol.h @@ -17,7 +17,7 @@ namespace regexp { /** * Represents symbol in the regular expression. Contains name of the symbol. */ -class FormalRegExpSymbol : public std::element<FormalRegExpSymbol, FormalRegExpElement> { +class FormalRegExpSymbol : public std::acceptor<FormalRegExpSymbol, FormalRegExpElement, FormalRegExpElement> { protected: alphabet::Symbol symbol; diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExp.h b/alib2data/src/regexp/unbounded/UnboundedRegExp.h index 80162652f7b3bd90fee0e061e73205c0d13a466b..9d2d0462131c04e9c6d4daffd98b8c517b3187eb 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExp.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExp.h @@ -24,7 +24,7 @@ class UnboundedRegExpElement; * Represents regular expression parsed from the XML. Regular expression is stored * as a tree of RegExpElement. */ -class UnboundedRegExp : public std::element<UnboundedRegExp, RegExpBase> { +class UnboundedRegExp : public std::acceptor<UnboundedRegExp, VisitableRegExpBase, std::acceptor<UnboundedRegExp, alib::VisitableObjectBase, RegExpBase> > { protected: UnboundedRegExpElement* regExp; @@ -122,9 +122,9 @@ public: */ virtual void operator>>(std::ostream& out) const; - virtual bool operator <(const ObjectBase& other) const; - virtual bool operator ==(const ObjectBase& other) const; - virtual bool operator >(const ObjectBase& other) const; + virtual bool operator <(const alib::ObjectBase& other) const; + virtual bool operator ==(const alib::ObjectBase& other) const; + virtual bool operator >(const alib::ObjectBase& other) const; virtual bool operator==(const UnboundedRegExp& other) const; diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h b/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h index e6a2fb21a386075ab0bd9d6e22eb8a18c61ec52d..924befb9d479cd9d5bbb13eee804cb2cbd025ef6 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h @@ -17,7 +17,7 @@ namespace regexp { * Represents alternation operator in the regular expression. Contains list of UnboundedRegExpElement * as operands of the operator. */ -class UnboundedRegExpAlternation: public std::element<UnboundedRegExpAlternation, UnboundedRegExpElement> { +class UnboundedRegExpAlternation: public std::acceptor<UnboundedRegExpAlternation, UnboundedRegExpElement, UnboundedRegExpElement> { protected: /** * @copydoc UnboundedRegExpElement::clone() const diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.h b/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.h index aee2fe4d21aa3f5c6df8c4abb9a8ff1d4a764d7b..e2d4ed6dbb072633033ee85bdaa7feef57349426 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.h @@ -17,7 +17,7 @@ namespace regexp { * Represents concatenation operator in the regular expression. Contains list of UnboundedRegExpElement * as operands of the operator. */ -class UnboundedRegExpConcatenation: public std::element<UnboundedRegExpConcatenation, UnboundedRegExpElement> { +class UnboundedRegExpConcatenation: public std::acceptor<UnboundedRegExpConcatenation, UnboundedRegExpElement, UnboundedRegExpElement> { protected: /** * @copydoc UnboundedRegExpElement::clone() const diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpElement.h b/alib2data/src/regexp/unbounded/UnboundedRegExpElement.h index 160f3ca5ccb53f33b2e44d1515466a8d0d53dc51..8874186afe80ff7325a76588a3590be9a0f6bd57 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpElement.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpElement.h @@ -29,7 +29,7 @@ class FormalRegExpElement; /** * Abstract class representing element in the regular expression. Can be operator or symbol. */ -class UnboundedRegExpElement : public std::elementBase<UnboundedRegExpAlternation, UnboundedRegExpConcatenation, UnboundedRegExpIteration, UnboundedRegExpSymbol, UnboundedRegExpEmpty, UnboundedRegExpEpsilon> { +class UnboundedRegExpElement : public std::acceptor_base<UnboundedRegExpAlternation, UnboundedRegExpConcatenation, UnboundedRegExpIteration, UnboundedRegExpSymbol, UnboundedRegExpEmpty, UnboundedRegExpEpsilon> { protected: /** * Parent regexp contanining this instance of RegExpElement diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpEmpty.h b/alib2data/src/regexp/unbounded/UnboundedRegExpEmpty.h index e5466db10d8124c04a857374b172f499ac2482f3..f095259c1a30f3292fe0098d6a5c7964b4e13df6 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpEmpty.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpEmpty.h @@ -15,7 +15,7 @@ namespace regexp { /** * Represents empty regular expression in the regular expression. */ -class UnboundedRegExpEmpty: public std::element<UnboundedRegExpEmpty, UnboundedRegExpElement> { +class UnboundedRegExpEmpty: public std::acceptor<UnboundedRegExpEmpty, UnboundedRegExpElement, UnboundedRegExpElement> { protected: /** * @copydoc UnboundedRegExpElement::clone() const diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpEpsilon.h b/alib2data/src/regexp/unbounded/UnboundedRegExpEpsilon.h index 61f6f5ef77a2fbc34d334f70507c72e14549a0aa..8fe4ab5f742bd07dd0a6990a7af39ede268ea4e7 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpEpsilon.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpEpsilon.h @@ -15,7 +15,7 @@ namespace regexp { /** * Represents epsilon in the regular expression. */ -class UnboundedRegExpEpsilon: public std::element<UnboundedRegExpEpsilon, UnboundedRegExpElement> { +class UnboundedRegExpEpsilon: public std::acceptor<UnboundedRegExpEpsilon, UnboundedRegExpElement, UnboundedRegExpElement> { protected: /** * @copydoc UnboundedRegExpElement::clone() const diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpIteration.h b/alib2data/src/regexp/unbounded/UnboundedRegExpIteration.h index b16ddbbc222f35f713c09dccb966d806be19e23c..634ba809858de87cb18c77b4296e3a5870a0793a 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpIteration.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpIteration.h @@ -17,7 +17,7 @@ namespace regexp { * Represents iteration operator in the regular expression. Contains one UnboundedRegExpElement * as operand. */ -class UnboundedRegExpIteration: public std::element<UnboundedRegExpIteration, UnboundedRegExpElement> { +class UnboundedRegExpIteration: public std::acceptor<UnboundedRegExpIteration, UnboundedRegExpElement, UnboundedRegExpElement> { protected: UnboundedRegExpElement* element; diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpSymbol.h b/alib2data/src/regexp/unbounded/UnboundedRegExpSymbol.h index fd30fd2447b381ded96532c8766bb7eb6de54b09..75f7a0f3b4f497a5275701b2d86022041a44fe18 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpSymbol.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpSymbol.h @@ -17,7 +17,7 @@ namespace regexp { /** * Represents symbol in the regular expression. Contains name of the symbol. */ -class UnboundedRegExpSymbol : public std::element<UnboundedRegExpSymbol, UnboundedRegExpElement> { +class UnboundedRegExpSymbol : public std::acceptor<UnboundedRegExpSymbol, UnboundedRegExpElement, UnboundedRegExpElement> { protected: alphabet::Symbol symbol; diff --git a/alib2data/src/std/visitor.hpp b/alib2data/src/std/visitor.hpp index e3f9552610e5cef3a7825ea9686bc60cdddb02f1..e70671a1fc2fac16064feca4a5ba84503852cd53 100644 --- a/alib2data/src/std/visitor.hpp +++ b/alib2data/src/std/visitor.hpp @@ -21,9 +21,7 @@ class visitor; template<typename T> class visitor<T> { public: - virtual void Visit(void*, const T &) { - throw logic_error("unimplemented"); //TODO revert pure virtual methods - } + virtual void Visit(void*, const T &) = 0; }; // specialization for multiple types @@ -33,9 +31,7 @@ public: // promote the function(s) from the base class using visitor<Types...>::Visit; - virtual void Visit(void*, const T &) { - throw logic_error("unimplemented"); - } + virtual void Visit(void*, const T &) = 0; }; // Visitor template declaration @@ -46,9 +42,7 @@ class const_visitor; template<typename T> class const_visitor<T> { public: - virtual void Visit(void*, const T &) const { - throw logic_error("unimplemented"); - } + virtual void Visit(void*, const T &) const = 0; }; // specialization for multiple types @@ -58,29 +52,26 @@ public: // promote the function(s) from the base class using const_visitor<Types...>::Visit; - virtual void Visit(void*, const T &) const { - throw logic_error("unimplemented"); - } + virtual void Visit(void*, const T &) const = 0; }; template<typename... Types> -class elementBase { +class acceptor_base { public: typedef visitor<Types...> visitor_type; typedef const_visitor<Types...> const_visitor_type; - typedef elementBase element_type; virtual void Accept(void* userData, visitor<Types...>& visitor) const = 0; virtual void Accept(void* userData, const const_visitor<Types...>& visitor) const = 0; }; -template<typename Derived, typename Base> -class element : public Base { +template<typename Derived, typename Visitor, typename Base> +class acceptor : public Base { public: - virtual void Accept(void* userData, typename Base::visitor_type& visitor) const { + virtual void Accept(void* userData, typename Visitor::visitor_type& visitor) const { visitor.Visit(userData, static_cast<const Derived&>(*this)); } - virtual void Accept(void* userData, const typename Base::const_visitor_type& visitor) const { + virtual void Accept(void* userData, const typename Visitor::const_visitor_type& visitor) const { visitor.Visit(userData, static_cast<const Derived&>(*this)); } }; diff --git a/alib2data/src/string/CyclicString.h b/alib2data/src/string/CyclicString.h index bcd52430a2567390bef4a94127b01583d3e0d953..c1b4aef3442a7e339045c909b57b75bbd271ce3e 100644 --- a/alib2data/src/string/CyclicString.h +++ b/alib2data/src/string/CyclicString.h @@ -23,7 +23,7 @@ namespace string { * Represents regular expression parsed from the XML. Regular expression is stored * as a tree of CyclicStringElement. */ -class CyclicString : public std::element<CyclicString, StringBase>, public StringAlphabet { +class CyclicString : public std::acceptor<CyclicString, VisitableStringBase, std::acceptor<CyclicString, alib::VisitableObjectBase, StringBase> >, public StringAlphabet { std::vector<alphabet::Symbol> m_Data; public: CyclicString(); @@ -37,9 +37,9 @@ public: virtual bool removeSymbolFromAlphabet(const alphabet::Symbol & symbol); - virtual bool operator <(const ObjectBase& other) const; - virtual bool operator ==(const ObjectBase& other) const; - virtual bool operator >(const ObjectBase& other) const; + virtual bool operator <(const alib::ObjectBase& other) const; + virtual bool operator ==(const alib::ObjectBase& other) const; + virtual bool operator >(const alib::ObjectBase& other) const; /** * @return List of symbols forming string (const version). diff --git a/alib2data/src/string/Epsilon.h b/alib2data/src/string/Epsilon.h index 12839d61da6e116d748259d1794e9f739a338167..10d2395eddb8f7f4a6b107ce0ace4c4c4a655de1 100644 --- a/alib2data/src/string/Epsilon.h +++ b/alib2data/src/string/Epsilon.h @@ -23,7 +23,7 @@ namespace string { * Represents epsilon. Regular expression is stored * as a tree of EpsilonElement. */ -class Epsilon : public std::element<Epsilon, StringBase>, public StringAlphabet { +class Epsilon : public std::acceptor<Epsilon, VisitableStringBase, std::acceptor<Epsilon, alib::VisitableObjectBase, StringBase> >, public StringAlphabet { public: Epsilon(); @@ -32,9 +32,9 @@ public: virtual bool removeSymbolFromAlphabet(const alphabet::Symbol & symbol); - virtual bool operator <(const ObjectBase& other) const; - virtual bool operator ==(const ObjectBase& other) const; - virtual bool operator >(const ObjectBase& other) const; + virtual bool operator <(const alib::ObjectBase& other) const; + virtual bool operator ==(const alib::ObjectBase& other) const; + virtual bool operator >(const alib::ObjectBase& other) const; /** * @return List of symbols forming string (const version). diff --git a/alib2data/src/string/LinearString.h b/alib2data/src/string/LinearString.h index e9d7082bbfc9e5307f24d1c2176c3300ba7fa73c..875ca997a2a74b7e87b7ccc6e6f655550ca3cd32 100644 --- a/alib2data/src/string/LinearString.h +++ b/alib2data/src/string/LinearString.h @@ -23,7 +23,7 @@ namespace string { * Represents regular expression parsed from the XML. Regular expression is stored * as a tree of LinearStringElement. */ -class LinearString : public std::element<LinearString, StringBase>, public StringAlphabet { +class LinearString : public std::acceptor<LinearString, VisitableStringBase, std::acceptor<LinearString, alib::VisitableObjectBase, StringBase> >, public StringAlphabet { std::vector<alphabet::Symbol> m_Data; public: @@ -45,9 +45,9 @@ public: void appendSymbol(alphabet::Symbol&& symbol); - virtual bool operator <(const ObjectBase& other) const; - virtual bool operator ==(const ObjectBase& other) const; - virtual bool operator >(const ObjectBase& other) const; + virtual bool operator <(const alib::ObjectBase& other) const; + virtual bool operator ==(const alib::ObjectBase& other) const; + virtual bool operator >(const alib::ObjectBase& other) const; /** * @return List of symbols forming string (const version). diff --git a/alib2data/src/string/StringAlphabetGetter.cpp b/alib2data/src/string/StringAlphabetGetter.cpp index e22b8d916cbba54fd908b81415e8b538543666fe..68a0b72cd2b97b419bdb1cf22562acfd36d57c2a 100644 --- a/alib2data/src/string/StringAlphabetGetter.cpp +++ b/alib2data/src/string/StringAlphabetGetter.cpp @@ -9,14 +9,6 @@ namespace string { -void StringAlphabetGetter::Visit(void* userData, const String& string) const { - string.getData().Accept(userData, *this); -} - -void StringAlphabetGetter::Visit(void* userData, const StringBase::element_type& element) const { - element.Accept(userData, *this); -} - void StringAlphabetGetter::Visit(void* userData, const CyclicString& string) const { std::set<alphabet::Symbol> &res = *((std::set<alphabet::Symbol>*) userData); res = string.getAlphabet(); @@ -34,7 +26,7 @@ void StringAlphabetGetter::Visit(void* userData, const LinearString& string) con std::set<alphabet::Symbol> StringAlphabetGetter::getAlphabet(const String& string) const { std::set<alphabet::Symbol> res; - Visit((void*) &res, string); + string.getData().Accept((void*) &res, *this); return std::move(res); } diff --git a/alib2data/src/string/StringAlphabetGetter.h b/alib2data/src/string/StringAlphabetGetter.h index 21b72c9274159656705af57a71c913e34a28591d..c3f84c738a4d4e89967d6e81e3f87bf13a903a2d 100644 --- a/alib2data/src/string/StringAlphabetGetter.h +++ b/alib2data/src/string/StringAlphabetGetter.h @@ -17,15 +17,11 @@ namespace string { -class StringAlphabetGetter : public StringBase::const_visitor_type { +class StringAlphabetGetter : public VisitableStringBase::const_visitor_type { void Visit(void*, const CyclicString& empty) const; void Visit(void*, const Epsilon& empty) const; void Visit(void*, const LinearString& empty) const; - void Visit(void*, const StringBase::element_type& element) const; - - void Visit(void*, const String& empty) const; - public: /** * Composes string representation of String. diff --git a/alib2data/src/string/StringBase.h b/alib2data/src/string/StringBase.h index f257a8f7e179f6ed00ff0186cd05451d7414336f..2ac457525e1a95b6d5018142c2b83bf9fa403787 100644 --- a/alib2data/src/string/StringBase.h +++ b/alib2data/src/string/StringBase.h @@ -13,11 +13,18 @@ namespace string { +typedef std::acceptor_base< + string::Epsilon, string::LinearString, string::CyclicString + > VisitableStringBase; + /** * Represents string in an alphabet. */ -class StringBase : public alib::ObjectBase { +class StringBase : public VisitableStringBase, public alib::ObjectBase { public: + using VisitableStringBase::Accept; + using alib::VisitableObjectBase::Accept; + virtual StringBase* clone() const = 0; virtual StringBase* plunder() && = 0; diff --git a/alib2data/src/string/StringToStringComposer.cpp b/alib2data/src/string/StringToStringComposer.cpp index 76d17ce8f2cf3ec8b2242b2ba50a8534557913b7..0d16950c4fda06685eaf262b000c6aa869ddba64 100644 --- a/alib2data/src/string/StringToStringComposer.cpp +++ b/alib2data/src/string/StringToStringComposer.cpp @@ -42,14 +42,9 @@ void StringToStringComposer::Visit(void* userData, const Epsilon&) { out << "#E"; } -void StringToStringComposer::Visit(void* userData, const String& string) { - string.getData().Accept(userData, *this); - -} - std::string StringToStringComposer::compose(const String& string) { std::stringstream out; - Visit((void*) &out, string); + string.getData().Accept((void*) &out, *this); return std::move(out).str(); } diff --git a/alib2data/src/string/StringToStringComposer.h b/alib2data/src/string/StringToStringComposer.h index 46a3543741d43ab04d196a38531ee3713d3ed944..41c1b9e081274fce0b84365aaf9607cb534713c1 100644 --- a/alib2data/src/string/StringToStringComposer.h +++ b/alib2data/src/string/StringToStringComposer.h @@ -18,8 +18,7 @@ namespace string { /** * This class contains methods to print XML representation of string to the output stream. */ -class StringToStringComposer : public StringBase::visitor_type { - void Visit(void*, const String& string); +class StringToStringComposer : public VisitableStringBase::visitor_type { void Visit(void*, const LinearString& string); void Visit(void*, const CyclicString& string); void Visit(void*, const Epsilon& string);