8template < 
class SymbolType >
 
   14        if( alternationOptimized ) {
 
   15            * alternation = std::move( * alternationOptimized );
 
   21        if( concatenationOptimized ) {
 
   22            * concatenation = std::move( * concatenationOptimized );
 
   28        if( iterationOptimized ) {
 
   29            * iteration = std::move( * iterationOptimized );
 
   38template < 
class SymbolType >
 
   43    while(    A1( elem ) || A2( elem ) || A3( elem ) || A4( elem ) || A10( elem ) || V2( elem ) || V5( elem ) || V6( elem ) || X1( elem )
 
   44           || A5( elem ) || A6( elem ) || A7( elem ) || A8( elem ) || A9( elem ) || V8( elem ) 
 
   45           || A11( elem ) || V1( elem ) || V3( elem ) || V4( elem ) || V10( elem ) || S(elem) );
 
   50template < 
class SymbolType >
 
   52    bool optimized = 
false;
 
   56            alternation->setLeftElement ( * tmp );
 
   61            alternation->setRightElement ( * tmp );
 
   67    if( FormalRegExpConcatenation < SymbolType > * concatenation = 
dynamic_cast<FormalRegExpConcatenation < SymbolType >*
>( 
node ); concatenation ) {
 
   68        if( 
ext::smart_ptr < FormalRegExpElement < SymbolType > > tmp = optimizeInner ( concatenation->getLeftElement ( ) ); * tmp != concatenation->getLeftElement ( ) ) {
 
   70            concatenation->setLeftElement ( * tmp );
 
   73        if( 
ext::smart_ptr < FormalRegExpElement < SymbolType > > tmp = optimizeInner ( concatenation->getRightElement ( ) ); * tmp != concatenation->getRightElement ( ) ) {
 
   75            concatenation->setRightElement ( * tmp );
 
   81    if( FormalRegExpIteration < SymbolType > * iteration = 
dynamic_cast<FormalRegExpIteration < SymbolType >*
>( 
node ); iteration ) {
 
   82        if( 
ext::smart_ptr < FormalRegExpElement < SymbolType > > tmp = optimizeInner ( iteration->getElement() ); * tmp != iteration->getElement ( ) ) {
 
   84            iteration->setElement ( * tmp );
 
   98template < 
class SymbolType >
 
   99bool RegExpOptimize::A1( FormalRegExpElement < SymbolType > * & 
node ) {
 
  100    FormalRegExpAlternation < SymbolType > * n = 
dynamic_cast<FormalRegExpAlternation < SymbolType > *
>( 
node );
 
  101    if( ! n ) 
return false;
 
  103    if( 
dynamic_cast < FormalRegExpAlternation < SymbolType > * 
> ( & n->getLeft ( ) ) ) {
 
  104        FormalRegExpAlternation < SymbolType > leftAlt ( std::move ( 
static_cast < FormalRegExpAlternation < SymbolType > & 
> ( n->getLeft ( ) ) ) );
 
  106        n->setLeft ( std::move ( leftAlt.getLeft ( ) ) );
 
  107        leftAlt.setLeft ( std::move ( leftAlt.getRight ( ) ) );
 
  108        leftAlt.setRight ( std::move ( n->getRight ( ) ) );
 
  109        n->setRight ( std::move ( leftAlt ) );
 
  122template < 
class SymbolType >
 
  123bool RegExpOptimize::A2 ( FormalRegExpElement < SymbolType > * & 
node ) {
 
  124    FormalRegExpAlternation < SymbolType > * n = 
dynamic_cast<FormalRegExpAlternation < SymbolType > *
>( 
node );
 
  125    if( ! n ) 
return false;
 
  127    if ( 
dynamic_cast < FormalRegExpAlternation < SymbolType > * 
> ( & n->getRight ( ) ) ) {
 
  128        FormalRegExpAlternation < SymbolType > & rightAlt = 
static_cast < FormalRegExpAlternation < SymbolType > & 
> ( n->getRight ( ) );
 
  130        if ( n->getLeft ( ) > rightAlt.getLeft ( ) ) {
 
  133            n->setLeft ( std::move ( rightAlt.getLeft ( ) ) );
 
  134            rightAlt.setLeft ( std::move ( tmp ) );
 
  149template < 
class SymbolType >
 
  150bool RegExpOptimize::A3 ( FormalRegExpElement < SymbolType > * & 
node ) {
 
  151    FormalRegExpAlternation < SymbolType > * n = 
dynamic_cast < FormalRegExpAlternation < SymbolType > * 
> ( 
node );
 
  152    if( ! n ) 
return false;
 
  156    if ( 
dynamic_cast < FormalRegExpEmpty < SymbolType > * 
> ( & n->getRight ( ) ) ) {
 
  157        node = std::move ( n->getLeft ( ) ).clone ( );
 
  162    if ( 
dynamic_cast < FormalRegExpEmpty < SymbolType > * 
> ( & n->getLeft ( ) ) ) {
 
  163        node = std::move ( n->getRight ( ) ).clone ( );
 
  176template < 
class SymbolType >
 
  177bool RegExpOptimize::A4( FormalRegExpElement < SymbolType > * & 
node ) {
 
  186    FormalRegExpAlternation < SymbolType > * n = 
dynamic_cast < FormalRegExpAlternation < SymbolType > * 
> ( 
node );
 
  187    if ( ! n ) 
return false;
 
  189    if ( n->getLeftElement() == n->getRightElement() ) {
 
  190        node = std::move ( n->getRight ( ) ).clone ( );
 
  203template < 
class SymbolType >
 
  204bool RegExpOptimize::A5( FormalRegExpElement < SymbolType > * & 
node ) {
 
  205    FormalRegExpConcatenation < SymbolType > * n = 
dynamic_cast<FormalRegExpConcatenation < SymbolType > *
>( 
node );
 
  206    if( ! n ) 
return false;
 
  208    if( 
dynamic_cast < FormalRegExpConcatenation < SymbolType > * 
> ( & n->getLeft ( ) ) ) {
 
  209        FormalRegExpConcatenation < SymbolType > leftCon ( std::move ( 
static_cast < FormalRegExpConcatenation < SymbolType > & 
> ( n->getLeft ( ) ) ) );
 
  211        n->setLeft ( std::move ( leftCon.getLeft ( ) ) );
 
  212        leftCon.setLeft ( std::move ( leftCon.getRight ( ) ) );
 
  213        leftCon.setRight ( std::move ( n->getRight ( ) ) );
 
  214        n->setRight ( std::move ( leftCon ) );
 
  227template < 
class SymbolType >
 
  228bool RegExpOptimize::A6( FormalRegExpElement < SymbolType > * & 
node ) {
 
  229    FormalRegExpConcatenation < SymbolType > * n = 
dynamic_cast<FormalRegExpConcatenation < SymbolType > *
>( 
node );
 
  230    if( ! n ) 
return false;
 
  234    if ( 
dynamic_cast < FormalRegExpEpsilon < SymbolType > * 
> ( & n->getRight ( ) ) ) {
 
  235        node = std::move ( n->getLeft ( ) ).clone ( );
 
  240    if ( 
dynamic_cast < FormalRegExpEpsilon < SymbolType > * 
> ( & n->getLeft ( ) ) ) {
 
  241        node = std::move ( n->getRight ( ) ).clone ( );
 
  254template < 
class SymbolType >
 
  255bool RegExpOptimize::A7( FormalRegExpElement < SymbolType > * & 
node ) {
 
  256    FormalRegExpConcatenation < SymbolType > * n = 
dynamic_cast<FormalRegExpConcatenation < SymbolType > *
>( 
node );
 
  257    if( ! n ) 
return false;
 
  259    if ( 
dynamic_cast < FormalRegExpEmpty < SymbolType > * 
> ( & n->getRight ( ) ) || 
dynamic_cast < FormalRegExpEmpty < SymbolType > * 
> ( & n->getLeft ( ) ) ) {
 
  261        node = 
new FormalRegExpEmpty < SymbolType > { };
 
  273template < 
class SymbolType >
 
  274bool RegExpOptimize::A8( FormalRegExpElement < SymbolType > * & ) {
 
  283template < 
class SymbolType >
 
  284bool RegExpOptimize::A9( FormalRegExpElement < SymbolType > * & ) {
 
  293template < 
class SymbolType >
 
  294bool RegExpOptimize::A10( FormalRegExpElement < SymbolType > * & 
node ) {
 
  301    FormalRegExpAlternation < SymbolType > * n = 
dynamic_cast<FormalRegExpAlternation < SymbolType > * 
> ( 
node );
 
  302    if ( ! n ) 
return false;
 
  304    if ( 
dynamic_cast < FormalRegExpEpsilon < SymbolType > * 
> ( & n->getLeft ( ) ) ) {
 
  305        FormalRegExpConcatenation < SymbolType > * rightCon = 
dynamic_cast < FormalRegExpConcatenation < SymbolType > * 
> ( & n->getRight ( ) );
 
  306        if ( ! rightCon ) 
return false;
 
  308        if ( FormalRegExpIteration < SymbolType > * rightLeftIte = 
dynamic_cast < FormalRegExpIteration < SymbolType > * 
> ( & rightCon->getLeft ( ) ); rightLeftIte && rightLeftIte->getElement ( ) == rightCon->getRightElement ( ) ) {
 
  309            node = std::move ( rightCon->getLeft ( ) ).clone ( );
 
  314        if ( FormalRegExpIteration < SymbolType > * rightRightIte = 
dynamic_cast < FormalRegExpIteration < SymbolType > * 
> ( & rightCon->getRight ( ) ); rightRightIte && rightRightIte->getElement ( ) == rightCon->getLeftElement ( ) ) {
 
  315            node = std::move ( rightCon->getRight ( ) ).clone ( );
 
  321    if ( 
dynamic_cast < FormalRegExpEpsilon < SymbolType > * 
> ( & n->getRight ( ) ) ) {
 
  322        FormalRegExpConcatenation < SymbolType > * leftCon = 
dynamic_cast < FormalRegExpConcatenation < SymbolType > * 
> ( & n->getLeft ( ) );
 
  323        if ( ! leftCon ) 
return false;
 
  325        if ( FormalRegExpIteration < SymbolType > * leftLeftIte = 
dynamic_cast < FormalRegExpIteration < SymbolType > * 
> ( & leftCon->getLeft ( ) ); leftLeftIte && leftLeftIte->getElement ( ) == leftCon->getRightElement ( ) ) {
 
  326            node = std::move ( leftCon->getLeft ( ) ).clone ( );
 
  331        if ( FormalRegExpIteration < SymbolType > * leftRightIte = 
dynamic_cast < FormalRegExpIteration < SymbolType > * 
> ( & leftCon->getRight ( ) ); leftRightIte && leftRightIte->getElement ( ) == leftCon->getLeftElement ( ) ) {
 
  332            node = std::move ( leftCon->getRight ( ) ).clone ( );
 
  346template < 
class SymbolType >
 
  347bool RegExpOptimize::A11( FormalRegExpElement < SymbolType > * & 
node ) {
 
  348    FormalRegExpIteration < SymbolType > * n = 
dynamic_cast<FormalRegExpIteration < SymbolType > *
>( 
node );
 
  349    if( ! n ) 
return false;
 
  351    if ( FormalRegExpAlternation < SymbolType > * childAlt = 
dynamic_cast < FormalRegExpAlternation < SymbolType > * 
> ( & n->getChild ( ) ); childAlt ) {
 
  352        if ( 
dynamic_cast < FormalRegExpEpsilon < SymbolType > * 
> ( & childAlt->getLeft ( ) ) ) {
 
  353            n->setChild ( std::move ( childAlt->getRight ( ) ) );
 
  356        if ( 
dynamic_cast < FormalRegExpEpsilon < SymbolType > * 
> ( & childAlt->getRight ( ) ) ) {
 
  357            n->setChild ( std::move ( childAlt->getLeft ( ) ) );
 
  371template < 
class SymbolType >
 
  372bool RegExpOptimize::V1( FormalRegExpElement < SymbolType > * & 
node ) {
 
  373    FormalRegExpIteration < SymbolType > * n = 
dynamic_cast<FormalRegExpIteration < SymbolType > *
>( 
node );
 
  374    if( ! n ) 
return false;
 
  376    if ( 
dynamic_cast < FormalRegExpEmpty < SymbolType > * 
> ( & n->getChild ( ) ) ) {
 
  378        node = 
new FormalRegExpEpsilon < SymbolType > ( );
 
  381    if ( 
dynamic_cast<FormalRegExpEpsilon < SymbolType > * 
> ( & n->getChild ( ) ) ) {
 
  383        node = 
new FormalRegExpEpsilon < SymbolType > ( );
 
  394template < 
class SymbolType >
 
  395bool RegExpOptimize::V2( FormalRegExpElement < SymbolType > * & 
node ) {
 
  396    FormalRegExpAlternation < SymbolType > * n = 
dynamic_cast<FormalRegExpAlternation < SymbolType > *
>( 
node );
 
  397    if( ! n ) 
return false;
 
  399    if ( FormalRegExpIteration < SymbolType > * leftIte = 
dynamic_cast < FormalRegExpIteration < SymbolType > * 
> ( & n->getLeft ( ) ); leftIte && leftIte->getElement ( ) == n->getRightElement ( ) ) {
 
  400        node = std::move ( n->getLeft ( ) ).clone ( );
 
  405    if ( FormalRegExpIteration < SymbolType > * rightIte = 
dynamic_cast < FormalRegExpIteration < SymbolType > * 
> ( & n->getRight ( ) ); rightIte && rightIte->getElement ( ) == n->getLeftElement ( ) ) {
 
  406        node = std::move ( n->getRight ( ) ).clone ( );
 
  419template < 
class SymbolType >
 
  420bool RegExpOptimize::V3( FormalRegExpElement < SymbolType > * & 
node ) {
 
  421    FormalRegExpIteration < SymbolType > * n = 
dynamic_cast<FormalRegExpIteration < SymbolType > *
>( 
node );
 
  422    if( ! n ) 
return false;
 
  424    if( FormalRegExpIteration < SymbolType > * childIter = 
dynamic_cast < FormalRegExpIteration < SymbolType > * 
> ( & n->getChild ( ) ); childIter ) {
 
  425        n->setChild ( std::move ( childIter->getChild ( ) ) );
 
  437template < 
class SymbolType >
 
  438bool RegExpOptimize::V4( FormalRegExpElement < SymbolType > * & 
node ) {
 
  439    FormalRegExpIteration < SymbolType > * n = 
dynamic_cast < FormalRegExpIteration < SymbolType > *
>( 
node );
 
  440    if( ! n ) 
return false;
 
  442    if( FormalRegExpConcatenation < SymbolType > * child = 
dynamic_cast < FormalRegExpConcatenation < SymbolType > * 
> ( & n->getChild ( ) ); child ) {
 
  443        if( FormalRegExpIteration < SymbolType > * leftIte = 
dynamic_cast < FormalRegExpIteration < SymbolType > * 
> ( & child->getLeft ( ) ); leftIte ) {
 
  444            if( FormalRegExpIteration < SymbolType > * rightIte = 
dynamic_cast < FormalRegExpIteration < SymbolType > * 
> ( & child->getRight ( ) ); rightIte ) {
 
  445                n->setChild ( FormalRegExpAlternation < SymbolType >( std::move ( leftIte->getElement ( ) ), std::move ( rightIte->getElement ( ) ) ) );
 
  458template < 
class SymbolType >
 
  459bool RegExpOptimize::V5( FormalRegExpElement < SymbolType > * & ) {
 
  468template < 
class SymbolType >
 
  469bool RegExpOptimize::V6( FormalRegExpElement < SymbolType > * & ) {
 
  478template < 
class SymbolType >
 
  479bool RegExpOptimize::V8( FormalRegExpElement < SymbolType > * & ) {
 
  488template < 
class SymbolType >
 
  489bool RegExpOptimize::V9( FormalRegExpElement < SymbolType > * & ) {
 
  498template < 
class SymbolType >
 
  499bool RegExpOptimize::V10( FormalRegExpElement < SymbolType > * & 
node ) {
 
  500    FormalRegExpIteration < SymbolType > * n = 
dynamic_cast < FormalRegExpIteration < SymbolType > *
>( 
node );
 
  501    if( ! n ) 
return false;
 
  503    if( FormalRegExpAlternation < SymbolType > * alt = 
dynamic_cast < FormalRegExpAlternation < SymbolType > * 
> ( & n->getChild ( ) ); alt ) {
 
  504        if( FormalRegExpIteration < SymbolType > * leftIte = 
dynamic_cast < FormalRegExpIteration < SymbolType > * 
> ( & alt->getLeft ( ) ); leftIte ) {
 
  505            if( FormalRegExpIteration < SymbolType > * rightIte = 
dynamic_cast < FormalRegExpIteration < SymbolType > * 
> ( & alt->getRight ( ) ); rightIte ) {
 
  506                alt->setLeft ( std::move ( leftIte->getChild ( ) ) );
 
  507                alt->setRight ( std::move ( rightIte->getChild ( ) ) );
 
  520template < 
class SymbolType >
 
  521bool RegExpOptimize::X1( FormalRegExpElement < SymbolType > * & 
node ) {
 
  522    FormalRegExpAlternation < SymbolType > * n = 
dynamic_cast<FormalRegExpAlternation < SymbolType > *
>( 
node );
 
  523    if( ! n ) 
return false;
 
  525    if ( FormalRegExpIteration < SymbolType > * leftIte = 
dynamic_cast < FormalRegExpIteration < SymbolType > * 
> ( & n->getLeft ( ) ); leftIte && 
dynamic_cast < FormalRegExpEpsilon < SymbolType > * 
> ( & n->getRight ( ) ) ) {
 
  526        node = std::move ( n->getLeft ( ) ).clone ( );
 
  531    if ( FormalRegExpIteration < SymbolType > * rightIte = 
dynamic_cast < FormalRegExpIteration < SymbolType > * 
> ( & n->getRight ( ) ); rightIte && 
dynamic_cast < FormalRegExpEpsilon < SymbolType > * 
> ( & n->getLeft ( ) ) ) {
 
  532        node = std::move ( n->getRight ( ) ).clone ( );
 
Class representing wrapper of dynamically allocated object behaving like rvalue reference.
Definition: ptr_value.hpp:40
Managed pointer simulating value like behavior.
Definition: memory.hpp:233
T * get()
Getter of the raw managed pointer.
Definition: memory.hpp:367
static regexp::UnboundedRegExp< SymbolType > optimize(const regexp::UnboundedRegExp< SymbolType > ®exp)
Definition: RegExpOptimize.h:22