diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h b/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h index 86e4a112c3facf4a874397e261f9fb28d2c84e64..1362e3619a549c10248a2202a8859e02710dc545 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h @@ -1,6 +1,22 @@ /* * UnboundedRegExpAlternation.h * + * This file is part of Algorithms library toolkit. + * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz) + + * Algorithms library toolkit is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * Algorithms library toolkit is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>. + * * Created on: Nov 23, 2013 * Author: Martin Zak */ @@ -18,16 +34,25 @@ namespace regexp { /** - * Represents alternation operator in the regular expression. Contains list of UnboundedRegExpElement - * as operands of the operator. + * \brief Represents the alternation operator in the regular expression. The node can have 0 to n children in list of UnboundedRegExpElement as operands of the alternation. + * + * The structure is derived from VararyNode that provides the children list and its accessors. + * + * The node can be visited by the UnboundedRegExpElement < SymbolType >::Visitor */ template < class SymbolType > class UnboundedRegExpAlternation : public UnboundedRegExpElement < SymbolType >, public ext::VararyNode < ext::smart_ptr < UnboundedRegExpElement < SymbolType > >, ext::smart_ptr < const UnboundedRegExpElement < SymbolType > >, UnboundedRegExpAlternation < SymbolType > > { -public: + /** + * @copydoc regexp::UnboundedRegExpElement < SymbolType >::accept ( ) const + */ void accept ( typename UnboundedRegExpElement < SymbolType >::Visitor & visitor ) const override { visitor.visit ( * this ); } +public: + /** + * \brief Creates a new instance of the alternation node. By default it is semantically equivalent to empty regular expression. + */ explicit UnboundedRegExpAlternation ( ); /** @@ -61,36 +86,64 @@ public: bool checkAlphabet ( const ext::set < SymbolType > & alphabet ) const override; /** - * @return elements + * Getter of child nodes of the regexp node + * + * \return child nodes */ const ext::vector < ext::smart_ptr < const UnboundedRegExpElement < SymbolType > > > & getElements ( ) const; /** - * @return elements + * Getter of child nodes of the regexp node + * + * \return child nodes */ const ext::vector < ext::smart_ptr < UnboundedRegExpElement < SymbolType > > > & getElements ( ); /** - * @param element to append + * Node appending method. The node is added to the current list of nodes. + * + * \param appended node */ void appendElement ( UnboundedRegExpElement < SymbolType > && element ); + + /** + * Node appending method. The node is added to the current list of nodes. + * + * \param appended node + */ void appendElement ( const UnboundedRegExpElement < SymbolType > & element ); - int compare ( const UnboundedRegExpElement < SymbolType > & other ) const override { + /** + * @copydoc alib::CommonBase < UnboundedRegExpElement < SymbolType > >::compare ( const UnboundedRegExpElement < SymbolType > & ) + */ + virtual int compare ( const UnboundedRegExpElement < SymbolType > & other ) const override { if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return this->compare ( ( decltype ( * this ) )other ); return ext::type_index ( typeid ( * this ) ) - ext::type_index ( typeid ( other ) ); } + /** + * The actual compare method + * + * \param other the other instance + * + * \returns the actual relation between two by type same node instances + */ int compare ( const UnboundedRegExpAlternation < SymbolType > & ) const; /** - * @copydoc UnboundedRegExpElement::operator>>() const + * @copydoc alib::CommonBase < UnboundedRegExpElement < SymbolType > >::operator >> ( std::ostream & ) */ - void operator >>( std::ostream & out ) const override; + virtual void operator >>( std::ostream & out ) const override; - explicit operator std::string ( ) const override; + /** + * @copydoc alib::CommonBase < UnboundedRegExpElement < SymbolType > >::operator std::string ( ) + */ + virtual explicit operator std::string ( ) const override; + /** + * @copydoc regexp::UnboundedRegExpElement < SymbolType >::normalize ( ) && + */ virtual ext::smart_ptr < UnboundedRegExpElement < DefaultSymbolType > > normalize ( ) && override { UnboundedRegExpAlternation < DefaultSymbolType > * res = new UnboundedRegExpAlternation < DefaultSymbolType > ( ); diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpElement.h b/alib2data/src/regexp/unbounded/UnboundedRegExpElement.h index 03cf11b4c1ead8970a2ef8abdebade9651865993..03e27729dbbc9fca7f7e4b2de473c6c0d0063ebb 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpElement.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpElement.h @@ -1,6 +1,22 @@ /* * UnboundedRegExpElement.h * + * This file is part of Algorithms library toolkit. + * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz) + + * Algorithms library toolkit is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * Algorithms library toolkit is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>. + * * Created on: Nov 23, 2013 * Author: Jan Travnicek */ @@ -16,11 +32,16 @@ namespace regexp { /** - * Abstract class representing element in the regular expression. Can be operator or symbol. + * Abstract class representing element in the regular expression. Can be an operator or a symbol. + * + * \tparam SymbolType used for the terminal alphabet */ template < class SymbolType > class UnboundedRegExpElement : public base::CommonBaseMiddle < UnboundedRegExpElement < SymbolType > >, public ext::BaseNode < UnboundedRegExpElement < SymbolType > > { -public: +protected: + /** + * Visitor interface of the expression + */ class Visitor { public: virtual void visit ( const UnboundedRegExpAlternation < SymbolType > & ) = 0; @@ -31,36 +52,83 @@ public: virtual void visit ( const UnboundedRegExpEpsilon < SymbolType > & ) = 0; }; + /** + * Helper class interconnecting the visitor interface and visitor core logic. + * + * \tparam ReturnType the return type of the result of the visit + * \tparam Visitorr the type of the actuall visitor + * \tparam Params ... types of data passed with the visitor call + */ template < class ReturnType, class Visitorr, class ... Params > class VisitorContext : public core::VisitorContextAux < ReturnType, Visitorr, Params ... >, public UnboundedRegExpElement::Visitor { public: + /** + * Inherited constructor. + */ using core::VisitorContextAux < ReturnType, Visitorr, Params ... >::VisitorContextAux; + /** + * Method passing the visit call to the visitor core logic. + */ void visit ( const UnboundedRegExpAlternation < SymbolType > & inherit ) override { this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } ); } + /** + * Method passing the visit call to the visitor core logic. + */ void visit ( const UnboundedRegExpConcatenation < SymbolType > & inherit ) override { this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } ); } + /** + * Method passing the visit call to the visitor core logic. + */ void visit ( const UnboundedRegExpIteration < SymbolType > & inherit ) override { this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } ); } + /** + * Method passing the visit call to the visitor core logic. + */ void visit ( const UnboundedRegExpSymbol < SymbolType > & inherit ) override { this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } ); } + /** + * Method passing the visit call to the visitor core logic. + */ void visit ( const UnboundedRegExpEmpty < SymbolType > & inherit ) override { this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } ); } + /** + * Method passing the visit call to the visitor core logic. + */ void visit ( const UnboundedRegExpEpsilon < SymbolType > & inherit ) override { this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } ); } }; + /** + * \brief Accept method of the visitor pattern + * + * \param visitor the accepted visitor. + */ + virtual void accept ( UnboundedRegExpElement::Visitor & visitor ) const = 0; + +public: + /** + * Visitor interface method. + * + * \tparam ReturnType the return type of the result of the visit + * \tparam Visitorr the type of the actuall visitor + * \tparam Params ... types of data passed with the visitor call + * + * \params params ... Additional params passed to visited nodes + * + * \return result of the visit + */ template < class ReturnType, class Visitorr, class ... Params > ReturnType accept ( Params && ... params ) const { VisitorContext < ReturnType, Visitorr, Params ... > context ( std::forward < Params > ( params ) ... ); @@ -68,8 +136,6 @@ public: return context.getResult ( ); } - virtual void accept ( UnboundedRegExpElement::Visitor & visitor ) const = 0; - /** * Creates copy of the element. * @return copy of the element @@ -79,33 +145,38 @@ public: /** * Traverses the regexp tree looking if particular Symbol is used in the regexp. * - * @param symbol to test if used in regexp element - * @return true if symbol is used by the element and its successor + * \param symbol to test if used in regexp element + * \return true if symbol is used by the element and its successor */ virtual bool testSymbol ( const SymbolType & symbol ) const = 0; /** * Traverses the regexp tree computing minimal alphabet needed by regexp * - * @param alphabet All alphabet symbols encountered are added into this set - * @return true if symbol is used by the element and its successor + * \param alphabet All alphabet symbols encountered are added into this set + * \return true if symbol is used by the element and its successor */ virtual void computeMinimalAlphabet ( ext::set < SymbolType > & alphabet ) const = 0; /** * Traverses the regexp tree and checks whether all symbols in the regexp tree are in the alphabet * - * @param alphabet - * @return true if symbols in the regexp are in the alphabet, false otherwise + * \param alphabet alphabet to check against + * \return true if symbols in the regexp are in the alphabet, false otherwise */ virtual bool checkAlphabet ( const ext::set < SymbolType > & alphabet ) const = 0; /** - * @copydoc RankedNode::computeMinimalAlphabet() + * Traverses the regexp tree and constructs the minimal alphabet of symbols used in the expression + * + * \return the minimal alphabet */ ext::set < SymbolType > computeMinimalAlphabet ( ) const; - /** Traverses the regexp tree and normalizes the symbols to DefaultSymbolType + /** + * \brief Traverses the regexp tree and normalizes the symbols to DefaultSymbolType + * + * \return the cloned node including children representing the same content but with type of symbols normalized to DefaultSymbolType */ virtual ext::smart_ptr < UnboundedRegExpElement < DefaultSymbolType > > normalize ( ) && = 0; };