cttl_impl::xtl_opunarstar< ExprT > Class Template Reference

Implements behavior of unary Kleene star operator. More...

#include <xtl_op_impl.h>

Inheritance diagram for cttl_impl::xtl_opunarstar< ExprT >:

cttl_impl::xtl_op_base_unary< ExprT >

List of all members.

Public Member Functions

template<typename SubstrT >
size_t bang_find (SubstrT &edge_)
 Implements repeatable search evaluation for Kleene star repeatable search algorithm, starting at the upper boundary of the parseable substring.
template<typename SubstrT >
size_t find (SubstrT &edge_)
 Implements search evaluation for Kleene star search algorithm, starting at the upper boundary of the parseable substring.
template<typename SubstrT >
size_t match (SubstrT &edge_)
 Implements match evaluation for Kleene star match algorithm, starting at the upper boundary of the parseable substring.
 xtl_opunarstar (ExprT const &expr_, size_t upper_limit_=0)
 Constructs and initializes the object.

Protected Attributes

size_t m_upper_limit
 Stores upper limit for the number of matches.


Detailed Description

template<typename ExprT>
class cttl_impl::xtl_opunarstar< ExprT >

Implements behavior of unary Kleene star operator.

Template Parameters:
ExprT specifies type of grammar expression object, determined by the C++ compiler at compile time.

Definition at line 346 of file xtl_op_impl.h.


Constructor & Destructor Documentation

template<typename ExprT>
cttl_impl::xtl_opunarstar< ExprT >::xtl_opunarstar ( ExprT const &  expr_,
size_t  upper_limit_ = 0 
)

Constructs and initializes the object.

Parameters:
expr_ immutable reference to CTTL grammar expression of the operand.
upper_limit_ If not zero, suggests the upper limit for a number of matches.

Definition at line 365 of file xtl_op_impl.h.

00366     : xtl_op_base_unary< ExprT >( expr_ ), m_upper_limit( upper_limit_ )
00367     {
00368     }


Member Function Documentation

template<typename ExprT>
template<typename SubstrT >
size_t cttl_impl::xtl_opunarstar< ExprT >::bang_find ( SubstrT &  edge_  ) 

Implements repeatable search evaluation for Kleene star repeatable search algorithm, starting at the upper boundary of the parseable substring.

Template Parameters:
SubstrT specifies type of the parseable substring. Can be either cttl::const_edge or cttl::edge.
Parameters:
edge_ reference to the parseable substring.
Postcondition:
If algorithm succeeds, the substring, specified by the edge_ parameter, is consumed according to the size of the matched symbols.
Returns:
evaluation result: if algorithm succeeds, it returns absolute offset corresponding to the upper boundary of the matched symbols. Otherwise, it returns SubstrT::string_T::npos, indicating that the evaluation algorithm has failed.

Definition at line 554 of file xtl_op_impl.h.

00555     {
00556         // [!!R,R,R,...]_ kleene star
00557         CTTL_TRACE_LEVEL_BANG( '*' );
00558         typename SubstrT::offset_guard_T saved_first_offset( edge_.first );
00559         // statically captured offset to watch mutablility of the substring.
00560         // substring is considered mutated if saved_end_offset no
00561         // longer matches the end of the substring.
00562         size_t saved_end_offset = edge_.second.offset();
00563         typename SubstrT::offset_guard_T match_offset( edge_.first, this->m_expr.bang_find( edge_ ) );
00564 
00565         if ( match_offset != SubstrT::string_T::npos ) {
00566             // If substring is mutable and the user deleted matched fragment,
00567             // edge_.first.offset() is brought back, therefore, it will appear here
00568             // as an empty (epsilon) match. In such case, if substring has mutated,
00569             // the search should go on.
00570             
00571             // Check if the substring mutated:
00572             if ( saved_end_offset == edge_.second.offset() ) {
00573                 if ( saved_first_offset == edge_.first.offset() ) {
00574                     // one match aleady found, no substring progress was made.
00575                     // No more match attemts necessary, we are done:
00576                     return match_offset;
00577                 }
00578             }
00579 
00580             if ( m_upper_limit ) {
00581                 // user wants to use upper limit on the number of matches
00582                 // minus one accounts for the expression already found
00583 
00584                 if ( m_upper_limit == 1 ) {
00585                     // one is a special case: if upper limit is one, then
00586                     // there is no need to search for more instances
00587                     return match_offset;
00588                 }
00589 
00590                 // it is sufficient to find
00591                 // zero to (m_upper_limit - 1) more matches:
00592                 kleene_list( edge_, m_upper_limit - 1 );
00593 
00594             } else
00595                 // user doesn't care how many matches are found:
00596                 kleene_list( edge_ );
00597 
00598         } else {
00599             // success offset is at the current position
00600             //assert( saved_first_offset == edge_.first.offset() );
00601             return saved_first_offset;
00602         }
00603 
00604         return match_offset;
00605     }

template<typename ExprT>
template<typename SubstrT >
size_t cttl_impl::xtl_opunarstar< ExprT >::find ( SubstrT &  edge_  ) 

Implements search evaluation for Kleene star search algorithm, starting at the upper boundary of the parseable substring.

Template Parameters:
SubstrT specifies type of the parseable substring. Can be either cttl::const_edge or cttl::edge.
Parameters:
edge_ reference to the parseable substring.
Postcondition:
If algorithm succeeds, the substring, specified by the edge_ parameter, is consumed according to the size of the matched symbols.
Returns:
evaluation result: if algorithm succeeds, it returns absolute offset corresponding to the upper boundary of the matched symbols. Otherwise, it returns SubstrT::string_T::npos, indicating that the evaluation algorithm has failed.

Definition at line 475 of file xtl_op_impl.h.

00476     {
00477         // [!R,R,R,...]_ kleene star
00478         CTTL_TRACE_LEVEL_FIND( '*' );
00479         typename SubstrT::offset_guard_T saved_first_offset( edge_.first );
00480 
00481         // statically captured offset to watch mutablility of the substring.
00482         // substring is considered mutated if saved_end_offset no
00483         // longer matches the end of the substring.
00484         size_t saved_end_offset = edge_.second.offset();
00485         typename SubstrT::offset_guard_T match_offset( edge_.first, this->m_expr.find( edge_ ) );
00486 
00487         if ( match_offset != SubstrT::string_T::npos ) {
00488             // If substring is mutable and the user deleted matched fragment,
00489             // edge_.first.offset() is brought back, therefore, it will appear here
00490             // as an empty (epsilon) match. In such case, if substring has mutated,
00491             // the search should go on.
00492             // Check if the substring mutated:
00493             if ( saved_end_offset == edge_.second.offset() ) {
00494                 if ( saved_first_offset == edge_.first.offset() ) {
00495                     // one match aleady found, no substring progress was made.
00496                     // No more match attemts necessary, we are done:
00497                     return match_offset;
00498                 }
00499             }
00500 
00501             if ( m_upper_limit ) {
00502                 // user wants to use upper limit on the number of matches
00503                 // minus one accounts for the expression already found
00504 
00505                 if ( m_upper_limit == 1 ) {
00506                     // one is a special case: if upper limit is one, then
00507                     // there is no need to search for more instances
00508                     return match_offset;
00509                 }
00510 
00511                 // it is sufficient to find
00512                 // zero to (m_upper_limit - 1) more matches:
00513                 kleene_list( edge_, m_upper_limit - 1 );
00514 
00515             } else
00516                 // user doesn't care how many matches are found:
00517                 kleene_list( edge_ );
00518 
00519         } else {
00520             // success offset is at the current position
00521             //assert( saved_first_offset == edge_.first.offset() );
00522             return saved_first_offset;
00523         }
00524 
00525         return match_offset;
00526     }

template<typename ExprT>
template<typename SubstrT >
size_t cttl_impl::xtl_opunarstar< ExprT >::match ( SubstrT &  edge_  ) 

Implements match evaluation for Kleene star match algorithm, starting at the upper boundary of the parseable substring.

Template Parameters:
SubstrT specifies type of the parseable substring. Can be either cttl::const_edge or cttl::edge.
Parameters:
edge_ reference to the parseable substring.
Postcondition:
If algorithm succeeds, the substring, specified by the edge_ parameter, is consumed according to the size of the matched symbols.
Returns:
evaluation result: if algorithm succeeds, it returns absolute offset corresponding to the upper boundary of the matched symbols. Otherwise, it returns SubstrT::string_T::npos, indicating that the evaluation algorithm has failed.

Definition at line 397 of file xtl_op_impl.h.

00398     {
00399         // [R,R,R,...]_ kleene star
00400         CTTL_TRACE_LEVEL_MATCH( '*' );
00401         typename SubstrT::offset_guard_T saved_first_offset( edge_.first );
00402 
00403         // statically captured offset to watch mutablility of the substring.
00404         // substring is considered mutated if saved_end_offset no longer matches the end of the substring.
00405         size_t saved_end_offset = edge_.second.offset();
00406         typename SubstrT::offset_guard_T match_offset( edge_.first, this->m_expr.match( edge_ ) );
00407 
00408         if ( match_offset != SubstrT::string_T::npos ) {
00409             // If substring is mutable and the user deleted matched fragment,
00410             // edge_.first.offset() is brought back, therefore, it will appear here
00411             // as an empty (epsilon) match. In such case, if substring has mutated,
00412             // the search should continue.
00413 
00414             // Check if the substring has mutated:
00415             if ( saved_end_offset == edge_.second.offset() ) {
00416                 if ( saved_first_offset == edge_.first.offset() ) {
00417                     // one match aleady found, no substring progress was made.
00418                     // No more match attemts necessary, we are done:
00419                     return match_offset;
00420                 }
00421             }
00422 
00423             if ( m_upper_limit ) {
00424                 // user wants to use upper limit on the number of matches
00425                 // minus one accounts for the expression already found
00426 
00427                 if ( m_upper_limit == 1 ) {
00428                     // one is a special case: if upper limit is one, then
00429                     // there is no need to search for more instances
00430                     return match_offset;
00431                 }
00432 
00433                 // it is sufficient to find only
00434                 // zero to (m_upper_limit - 1) matches:
00435                 kleene_list( edge_, m_upper_limit - 1 );
00436 
00437             } else
00438                 // user doesn't care how many matches are found:
00439                 kleene_list( edge_ );
00440 
00441         } else {
00442             // success offset is at the current position
00443             //assert( saved_first_offset == edge_.first.offset() );
00444             return saved_first_offset;
00445         }
00446 
00447         return match_offset;
00448     }


Member Data Documentation

template<typename ExprT>
size_t cttl_impl::xtl_opunarstar< ExprT >::m_upper_limit [protected]

Stores upper limit for the number of matches.

Definition at line 351 of file xtl_op_impl.h.


The documentation for this class was generated from the following file:

Generated on Sun Aug 23 13:43:47 2009 for Common Text Transformation Library by  doxygen 1.5.9