From 1c37916900114e1e98bc6ef2ed65ce4bfb982247 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Sun, 30 Oct 2016 11:27:59 +0100 Subject: [PATCH] split visitors to separate classes II --- alib2data/src/rte/common/RTEToXMLComposer.cpp | 14 +++++----- alib2data/src/rte/common/RTEToXMLComposer.h | 26 ++++++++++--------- .../src/rte/formal/FormalRTEAlternation.h | 2 +- alib2data/src/rte/formal/FormalRTEElement.h | 22 ++++++++-------- alib2data/src/rte/formal/FormalRTEEmpty.h | 2 +- alib2data/src/rte/formal/FormalRTEIteration.h | 2 +- .../src/rte/formal/FormalRTEStructure.cpp | 2 +- .../src/rte/formal/FormalRTESubstitution.h | 2 +- .../src/rte/formal/FormalRTESymbolAlphabet.h | 2 +- .../src/rte/formal/FormalRTESymbolSubst.h | 2 +- 10 files changed, 39 insertions(+), 37 deletions(-) diff --git a/alib2data/src/rte/common/RTEToXMLComposer.cpp b/alib2data/src/rte/common/RTEToXMLComposer.cpp index a743c030f3..5cc08d09b8 100644 --- a/alib2data/src/rte/common/RTEToXMLComposer.cpp +++ b/alib2data/src/rte/common/RTEToXMLComposer.cpp @@ -9,7 +9,7 @@ namespace rte { -void RTEToXMLComposer::Visit ( void * userData, const FormalRTEAlternation & alternation ) const { +void RTEToXMLComposer::Formal::Visit ( void * userData, const FormalRTEAlternation & alternation ) const { std::deque < sax::Token > & out = * ( ( std::deque < sax::Token > * )userData ); out.emplace_back ( "alternation", sax::Token::TokenType::START_ELEMENT ); @@ -18,7 +18,7 @@ void RTEToXMLComposer::Visit ( void * userData, const FormalRTEAlternation & alt out.emplace_back ( "alternation", sax::Token::TokenType::END_ELEMENT ); } -void RTEToXMLComposer::Visit ( void * userData, const FormalRTESubstitution & substitution ) const { +void RTEToXMLComposer::Formal::Visit ( void * userData, const FormalRTESubstitution & substitution ) const { std::deque < sax::Token > & out = * ( ( std::deque < sax::Token > * )userData ); out.emplace_back ( "substitution", sax::Token::TokenType::START_ELEMENT ); @@ -30,7 +30,7 @@ void RTEToXMLComposer::Visit ( void * userData, const FormalRTESubstitution & su out.emplace_back ( "substitution", sax::Token::TokenType::END_ELEMENT ); } -void RTEToXMLComposer::Visit ( void * userData, const FormalRTEIteration & iteration ) const { +void RTEToXMLComposer::Formal::Visit ( void * userData, const FormalRTEIteration & iteration ) const { std::deque < sax::Token > & out = * ( ( std::deque < sax::Token > * )userData ); out.emplace_back ( "iteration", sax::Token::TokenType::START_ELEMENT ); @@ -41,7 +41,7 @@ void RTEToXMLComposer::Visit ( void * userData, const FormalRTEIteration & itera out.emplace_back ( "iteration", sax::Token::TokenType::END_ELEMENT ); } -void RTEToXMLComposer::Visit ( void * userData, const FormalRTESymbolAlphabet & symbol ) const { +void RTEToXMLComposer::Formal::Visit ( void * userData, const FormalRTESymbolAlphabet & symbol ) const { std::deque < sax::Token > & out = * ( ( std::deque < sax::Token > * )userData ); out.emplace_back ( sax::Token ( "symbol", sax::Token::TokenType::START_ELEMENT ) ); @@ -53,7 +53,7 @@ void RTEToXMLComposer::Visit ( void * userData, const FormalRTESymbolAlphabet & out.emplace_back ( sax::Token ( "symbol", sax::Token::TokenType::END_ELEMENT ) ); } -void RTEToXMLComposer::Visit ( void * userData, const FormalRTESymbolSubst & symbol ) const { +void RTEToXMLComposer::Formal::Visit ( void * userData, const FormalRTESymbolSubst & symbol ) const { std::deque < sax::Token > & out = * ( ( std::deque < sax::Token > * )userData ); out.emplace_back ( sax::Token ( "substSymbol", sax::Token::TokenType::START_ELEMENT ) ); @@ -62,7 +62,7 @@ void RTEToXMLComposer::Visit ( void * userData, const FormalRTESymbolSubst & sym out.emplace_back ( sax::Token ( "substSymbol", sax::Token::TokenType::END_ELEMENT ) ); } -void RTEToXMLComposer::Visit ( void * userData, const FormalRTEEmpty & ) const { +void RTEToXMLComposer::Formal::Visit ( void * userData, const FormalRTEEmpty & ) const { std::deque < sax::Token > & out = * ( ( std::deque < sax::Token > * )userData ); out.emplace_back ( "empty", sax::Token::TokenType::START_ELEMENT ); @@ -85,6 +85,6 @@ void RTEToXMLComposer::composeAlphabet ( std::deque < sax::Token > & out, const out.emplace_back ( "substSymbolAlphabet", sax::Token::TokenType::END_ELEMENT ); } -RTEToXMLComposer RTEToXMLComposer::RTE_TO_XML_COMPOSER; +const RTEToXMLComposer::Formal RTEToXMLComposer::Formal::FORMAL; } /* namespace rte */ diff --git a/alib2data/src/rte/common/RTEToXMLComposer.h b/alib2data/src/rte/common/RTEToXMLComposer.h index 0765149343..344bf55322 100644 --- a/alib2data/src/rte/common/RTEToXMLComposer.h +++ b/alib2data/src/rte/common/RTEToXMLComposer.h @@ -13,21 +13,23 @@ namespace rte { /** * This class contains methods to print XML representation of regular tree expression to the output stream. */ -class RTEToXMLComposer : public FormalRTEElementVisitor { +class RTEToXMLComposer { public: - RTEToXMLComposer ( ) { } - - static RTEToXMLComposer RTE_TO_XML_COMPOSER; - static void composeAlphabet ( std::deque < sax::Token > & out, const std::set < std::ranked_symbol < > > & alphabetF, const std::set < std::ranked_symbol < > > & alphabetK ); -private: - void Visit ( void *, const FormalRTEAlternation & alternation ) const; - void Visit ( void *, const FormalRTEIteration & iteration ) const; - void Visit ( void *, const FormalRTESubstitution & concatenation ) const; - void Visit ( void *, const FormalRTESymbolAlphabet & symbol ) const; - void Visit ( void *, const FormalRTESymbolSubst & symbol ) const; - void Visit ( void *, const FormalRTEEmpty & empty ) const; + class Formal : public FormalRTEElement::Visitor { + public: + Formal ( ) { } + + static const Formal FORMAL; + private: + void Visit ( void *, const FormalRTEAlternation & alternation ) const; + void Visit ( void *, const FormalRTEIteration & iteration ) const; + void Visit ( void *, const FormalRTESubstitution & concatenation ) const; + void Visit ( void *, const FormalRTESymbolAlphabet & symbol ) const; + void Visit ( void *, const FormalRTESymbolSubst & symbol ) const; + void Visit ( void *, const FormalRTEEmpty & empty ) const; + }; }; } /* namespace rte */ diff --git a/alib2data/src/rte/formal/FormalRTEAlternation.h b/alib2data/src/rte/formal/FormalRTEAlternation.h index 4c60d35a41..1dcbcdf880 100644 --- a/alib2data/src/rte/formal/FormalRTEAlternation.h +++ b/alib2data/src/rte/formal/FormalRTEAlternation.h @@ -11,7 +11,7 @@ namespace rte { */ class FormalRTEAlternation : public FormalRTEElement, public std::BinaryNode < std::smart_ptr < FormalRTEElement >, std::smart_ptr < FormalRTEElement >, FormalRTEAlternation > { public: - void Accept ( void * userData, const FormalRTEElementVisitor & visitor ) const { + void Accept ( void * userData, const FormalRTEElement::Visitor & visitor ) const { visitor.Visit ( userData, * this ); } diff --git a/alib2data/src/rte/formal/FormalRTEElement.h b/alib2data/src/rte/formal/FormalRTEElement.h index 7a86a1e7eb..1e46b25a5d 100644 --- a/alib2data/src/rte/formal/FormalRTEElement.h +++ b/alib2data/src/rte/formal/FormalRTEElement.h @@ -19,19 +19,19 @@ class FormalRTEEmpty; class FormalRTEElement; -class FormalRTEElementVisitor { -public: - virtual void Visit ( void *, const FormalRTEAlternation & alternation ) const = 0; - virtual void Visit ( void *, const FormalRTEIteration & iteration ) const = 0; - virtual void Visit ( void *, const FormalRTESubstitution & substitution ) const = 0; - virtual void Visit ( void *, const FormalRTESymbolAlphabet & symbol ) const = 0; - virtual void Visit ( void *, const FormalRTESymbolSubst & symbol ) const = 0; - virtual void Visit ( void *, const FormalRTEEmpty & empty ) const = 0; -}; - class FormalRTEElement : public alib::CommonBase < FormalRTEElement >, public std::BaseNode < FormalRTEElement > { public: - virtual void Accept ( void * userData, const FormalRTEElementVisitor & visitor ) const = 0; + class Visitor { + public: + virtual void Visit ( void *, const FormalRTEAlternation & alternation ) const = 0; + virtual void Visit ( void *, const FormalRTEIteration & iteration ) const = 0; + virtual void Visit ( void *, const FormalRTESubstitution & substitution ) const = 0; + virtual void Visit ( void *, const FormalRTESymbolAlphabet & symbol ) const = 0; + virtual void Visit ( void *, const FormalRTESymbolSubst & symbol ) const = 0; + virtual void Visit ( void *, const FormalRTEEmpty & empty ) const = 0; + }; + + virtual void Accept ( void * userData, const FormalRTEElement::Visitor & visitor ) const = 0; /** * Traverses the regexp tree looking if particular Symbol is used in the regexp. diff --git a/alib2data/src/rte/formal/FormalRTEEmpty.h b/alib2data/src/rte/formal/FormalRTEEmpty.h index 1fe60defba..1d6135de79 100644 --- a/alib2data/src/rte/formal/FormalRTEEmpty.h +++ b/alib2data/src/rte/formal/FormalRTEEmpty.h @@ -11,7 +11,7 @@ namespace rte { */ class FormalRTEEmpty : public FormalRTEElement { public: - void Accept ( void * userData, const FormalRTEElementVisitor & visitor ) const { + void Accept ( void * userData, const FormalRTEElement::Visitor & visitor ) const { visitor.Visit ( userData, * this ); } diff --git a/alib2data/src/rte/formal/FormalRTEIteration.h b/alib2data/src/rte/formal/FormalRTEIteration.h index 18c95d1e2c..d0d79b54fb 100644 --- a/alib2data/src/rte/formal/FormalRTEIteration.h +++ b/alib2data/src/rte/formal/FormalRTEIteration.h @@ -22,7 +22,7 @@ protected: std::smart_ptr < FormalRTESymbolSubst > substitutionSymbol; public: - void Accept ( void * userData, const FormalRTEElementVisitor & visitor ) const { + void Accept ( void * userData, const FormalRTEElement::Visitor & visitor ) const { visitor.Visit ( userData, * this ); } diff --git a/alib2data/src/rte/formal/FormalRTEStructure.cpp b/alib2data/src/rte/formal/FormalRTEStructure.cpp index fd234379b5..5dea6d2b6f 100644 --- a/alib2data/src/rte/formal/FormalRTEStructure.cpp +++ b/alib2data/src/rte/formal/FormalRTEStructure.cpp @@ -53,7 +53,7 @@ bool xmlApi < rte::FormalRTEStructure >::first ( const std::deque < sax::Token > } void xmlApi < rte::FormalRTEStructure >::compose ( std::deque < sax::Token > & output, const rte::FormalRTEStructure & data ) { - data.getStructure ( ).Accept ( ( void * ) & output, rte::RTEToXMLComposer::RTE_TO_XML_COMPOSER ); + data.getStructure ( ).Accept ( ( void * ) & output, rte::RTEToXMLComposer::Formal::FORMAL ); } } /* namespace alib */ diff --git a/alib2data/src/rte/formal/FormalRTESubstitution.h b/alib2data/src/rte/formal/FormalRTESubstitution.h index 7f7a5986b1..3bc956dda1 100644 --- a/alib2data/src/rte/formal/FormalRTESubstitution.h +++ b/alib2data/src/rte/formal/FormalRTESubstitution.h @@ -16,7 +16,7 @@ protected: std::smart_ptr < FormalRTESymbolSubst > substitutionSymbol; // substite this in left by right public: - void Accept ( void * userData, const FormalRTEElementVisitor & visitor ) const { + void Accept ( void * userData, const FormalRTEElement::Visitor & visitor ) const { visitor.Visit ( userData, * this ); } diff --git a/alib2data/src/rte/formal/FormalRTESymbolAlphabet.h b/alib2data/src/rte/formal/FormalRTESymbolAlphabet.h index 12e5991bf2..24599ab104 100644 --- a/alib2data/src/rte/formal/FormalRTESymbolAlphabet.h +++ b/alib2data/src/rte/formal/FormalRTESymbolAlphabet.h @@ -11,7 +11,7 @@ namespace rte { */ class FormalRTESymbolAlphabet : public FormalRTESymbol, public std::VararyNode < std::smart_ptr < FormalRTESymbol >, std::smart_ptr < const FormalRTESymbol >, FormalRTESymbolAlphabet > { public: - void Accept ( void * userData, const FormalRTEElementVisitor & visitor ) const { + void Accept ( void * userData, const FormalRTEElement::Visitor & visitor ) const { visitor.Visit ( userData, * this ); } diff --git a/alib2data/src/rte/formal/FormalRTESymbolSubst.h b/alib2data/src/rte/formal/FormalRTESymbolSubst.h index cf9de9389a..4be5896ba2 100644 --- a/alib2data/src/rte/formal/FormalRTESymbolSubst.h +++ b/alib2data/src/rte/formal/FormalRTESymbolSubst.h @@ -11,7 +11,7 @@ namespace rte { */ class FormalRTESymbolSubst : public FormalRTESymbol, public std::NullaryNode < FormalRTESymbolSubst > { public: - void Accept ( void * userData, const FormalRTEElementVisitor & visitor ) const { + void Accept ( void * userData, const FormalRTEElement::Visitor & visitor ) const { visitor.Visit ( userData, * this ); } -- GitLab