Skip to content
Snippets Groups Projects
Commit 63411888 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

make datatype component methods return this object when possible

parent dfd0f3b9
No related branches found
No related tags found
No related merge requests found
Pipeline #28529 passed
......@@ -180,7 +180,7 @@ int main ( int argc, char * argv[] ) {
}
 
if ( operation.getValue ( ) == "add" || operation.getValue ( ) == "remove" )
cliString += " $argument";
cliString += " $argument >";
 
if ( operation.getValue ( ) == "get" ) {
cliString += " >$output";
......
......@@ -12,8 +12,17 @@ namespace regexp {
 
namespace convert {
 
auto ToAutomatonFormalRegExp = registration::AbstractRegister < ToAutomaton, automaton::NFA < DefaultSymbolType, ext::pair < DefaultSymbolType, unsigned > >, const regexp::FormalRegExp < > & > ( ToAutomaton::convert );
auto ToAutomatonUnboundedRegExp = registration::AbstractRegister < ToAutomaton, automaton::NFA < DefaultSymbolType, ext::pair < DefaultSymbolType, unsigned > >, const regexp::UnboundedRegExp < > & > ( ToAutomaton::convert );
auto ToAutomatonFormalRegExp = registration::AbstractRegister < ToAutomaton, automaton::NFA < DefaultSymbolType, ext::pair < DefaultSymbolType, unsigned > >, const regexp::FormalRegExp < > & > ( ToAutomaton::convert, "regexp" ).setDocumentation (
"Converts the regular expression into an automaton (@sa regexp::convert::ToGlushkovAutomaton::convert).\n\
\n\
@param regexp the regular expression\n\
@return finite automaotn equivalent to original regular expression" );
auto ToAutomatonUnboundedRegExp = registration::AbstractRegister < ToAutomaton, automaton::NFA < DefaultSymbolType, ext::pair < DefaultSymbolType, unsigned > >, const regexp::UnboundedRegExp < > & > ( ToAutomaton::convert, "regexp" ).setDocumentation (
"Converts the regular expression into an automaton (@sa regexp::convert::ToGlushkovAutomaton::convert).\n\
\n\
@param regexp the regular expression\n\
@return finite automaotn equivalent to original regular expression" );
 
} /* namespace convert */
 
......
......@@ -19,14 +19,34 @@ namespace regexp {
 
namespace convert {
 
/**
* Conversion of regular expression to finite automata.
* This class serves as a "default wrapper" over the conversion of RE to FA. It delegates to the glushkov conversion algorithm.
* @sa regexp::convert::ToGlushkovAutomaton
*/
class ToAutomaton {
public:
/**
* Performs conversion.
* @return FSM equivalent to original regular expression.
* Converts the regular expression into an automaton (@sa regexp::convert::ToGlushkovAutomaton::convert).
*
* \tparam SymbolType the type of regular expression
*
* \param regexp the regular expression
*
* \return finite automaotn equivalent to original regular expression.
*/
template < class SymbolType >
static automaton::NFA < SymbolType, ext::pair < SymbolType, unsigned > > convert ( const regexp::FormalRegExp < SymbolType > & regexp );
/**
* Converts the regular expression into an automaton (@sa regexp::convert::ToGlushkovAutomaton::convert).
*
* \tparam SymbolType the type of regular expression
*
* \param regexp the regular expression
*
* \return finite automaotn equivalent to original regular expression.
*/
template < class SymbolType >
static automaton::NFA < SymbolType, ext::pair < SymbolType, unsigned > > convert ( const regexp::UnboundedRegExp < SymbolType > & regexp );
 
......
......@@ -137,9 +137,10 @@ public:
* @param elements to add to the set
* @throw CommonException if one of the elements is not available in context of datatype where the set is used
*/
void add ( SetComponentType data ) {
Derived & add ( SetComponentType data ) {
for ( ComponentType element : ext::make_mover ( data ) )
add ( std::move ( element ) );
return static_cast < Derived & > ( * this );
}
 
/**
......@@ -148,10 +149,11 @@ public:
* @throw CommonException if one of the removed elements is used in context of datatype where the set is used
* CommonException if one of the added elements is not available in context of datatype where the set is used
*/
void set ( SetComponentType data ) {
Derived & set ( SetComponentType data ) {
ext::set_symmetric_difference ( m_data.begin ( ), m_data.end ( ), data.begin ( ), data.end ( ), ext::make_callback_iterator < const ComponentType & > ( std::bind ( & SetComponent::checkRemove, this, std::placeholders::_1 ) ), ext::make_callback_iterator < const ComponentType & > ( std::bind ( & SetComponent::checkAdd, this, std::placeholders::_1 ) ) );
 
m_data = std::move ( data );
return static_cast < Derived & > ( * this );
}
 
/**
......@@ -183,9 +185,10 @@ public:
* Removes a set of elements from alphabet if not used.
* @throw CommonException if element is used in context of datatype where the set is used
*/
void remove ( const SetComponentType & data ) {
Derived & remove ( const SetComponentType & data ) {
for ( const ComponentType & element : data )
remove ( element );
return static_cast < Derived & > ( * this );
}
 
/**
......@@ -247,19 +250,19 @@ public:
const ComponentType & ( Derived::* constGetMethod ) ( ) const = & SetComponent < Derived, ComponentType, typename ComponentType::value_type, ComponentName >::get;
abstraction::AlgorithmRegistry::registerMethod < ComponentName > ( constGetMethod, "get", emptyNames );
 
void ( Derived::* setMethod ) ( ComponentType ) = & SetComponent < Derived, ComponentType, typename ComponentType::value_type, ComponentName >::set;
Derived & ( Derived::* setMethod ) ( ComponentType ) = & SetComponent < Derived, ComponentType, typename ComponentType::value_type, ComponentName >::set;
abstraction::AlgorithmRegistry::registerMethod < ComponentName > ( setMethod, "set", dataNames );
 
bool ( Derived::* addElement ) ( typename ComponentType::value_type ) = & SetComponent < Derived, ComponentType, typename ComponentType::value_type, ComponentName >::add;
abstraction::AlgorithmRegistry::registerMethod < ComponentName > ( addElement, "add", elementNames );
 
void ( Derived::* addSet ) ( ComponentType ) = & SetComponent < Derived, ComponentType, typename ComponentType::value_type, ComponentName >::add;
Derived & ( Derived::* addSet ) ( ComponentType ) = & SetComponent < Derived, ComponentType, typename ComponentType::value_type, ComponentName >::add;
abstraction::AlgorithmRegistry::registerMethod < ComponentName > ( addSet, "add", dataNames );
 
bool ( Derived::* removeElement ) ( const typename ComponentType::value_type & ) = & SetComponent < Derived, ComponentType, typename ComponentType::value_type, ComponentName >::remove;
abstraction::AlgorithmRegistry::registerMethod < ComponentName > ( removeElement, "remove", elementNames );
 
void ( Derived::* removeSet ) ( const ComponentType & ) = & SetComponent < Derived, ComponentType, typename ComponentType::value_type, ComponentName >::remove;
Derived & ( Derived::* removeSet ) ( const ComponentType & ) = & SetComponent < Derived, ComponentType, typename ComponentType::value_type, ComponentName >::remove;
abstraction::AlgorithmRegistry::registerMethod < ComponentName > ( removeSet, "remove", dataNames );
 
bool ( Derived::* emptyMethod ) ( ) const = & SetComponent < Derived, ComponentType, typename ComponentType::value_type, ComponentName >::empty;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment