00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00026
00042
00043
00044 #ifndef _CTTL_XTLBASE_H_INCLUDED_
00045 #define _CTTL_XTLBASE_H_INCLUDED_
00046
00047 #include "coreutils.h"
00048 #include "policy_state.h"
00049
00050 namespace cttl_impl {
00051
00053 typedef int ( *iswhat_T )( int );
00054
00056 typedef int ( *iswwhat_T )( wint_t );
00057
00058 }
00059
00060 #include "xtl_trace.h"
00061
00062 namespace cttl_impl {
00063
00073 template< typename ExprT >
00074 struct xtl_wrap {
00075
00076
00077
00079 ExprT m_expr;
00080
00082 xtl_wrap()
00083 : m_expr( ExprT() )
00084 {
00085
00086 }
00087
00089 template< typename GenericT >
00090 xtl_wrap( GenericT const& x_ )
00091 : m_expr( ExprT( x_ ) )
00092 {
00093
00094 }
00095
00097 xtl_wrap( xtl_wrap< ExprT > const& other_ )
00098 : m_expr( other_.m_expr )
00099 {
00100 }
00101
00117 template< typename SubstrT >
00118 size_t match( SubstrT& edge_ )
00119 {
00120 return m_expr.match( edge_ );
00121 }
00122
00138 template< typename SubstrT >
00139 size_t find( SubstrT& edge_ )
00140 {
00141 return m_expr.find( edge_ );
00142 }
00143
00159 template< typename SubstrT >
00160 size_t bang_find( SubstrT& edge_ )
00161 {
00162 return m_expr.bang_find( edge_ );
00163 }
00164
00165 #ifdef CTTL_STATEFUL_RUNTIME_MATCH
00166
00181 template< typename SubstrT >
00182 size_t runtime_match( SubstrT& edge_ )
00183 {
00184 assert( &edge_.space_policy() != NULL || !"Stateful policy must be provided by the user." );
00185 if ( edge_.space_policy().m_flags.test( cttl::policy_default::xtl_flag_runtime_bang_find ) ) {
00186 edge_.space_policy().m_flags.clear( cttl::policy_default::xtl_flag_runtime_bang_find );
00187 return m_expr.bang_find( edge_ );
00188
00189 } else if ( edge_.space_policy().m_flags.test( cttl::policy_default::xtl_flag_runtime_find ) ) {
00190 edge_.space_policy().m_flags.clear( cttl::policy_default::xtl_flag_runtime_find );
00191 return m_expr.find( edge_ );
00192 }
00193
00194 return m_expr.match( edge_ );
00195 }
00196 #endif //CTTL_STATEFUL_RUNTIME_MATCH
00197
00198 private:
00200 xtl_wrap< ExprT >& operator=( xtl_wrap< ExprT > const& );
00201
00202 };
00203
00204
00221 template< typename EdgeT, typename ExprT >
00222 class xtl_edge {
00223
00224 private:
00226 EdgeT& m_edge;
00227
00229 ExprT m_expr;
00230
00231 public:
00232
00233
00235 xtl_edge( EdgeT& edge_, ExprT const& expr_ )
00236 :
00237 m_edge( edge_ ),
00238 m_expr( expr_ )
00239 {
00240 }
00241
00242
00243
00263 template< typename SubstrT >
00264 size_t match( SubstrT& edge_ )
00265 {
00266 CTTL_TRACE_LEVEL_MATCH( 'e' );
00267 CTTL_TRACE_JUSTIFY();
00268 CTTL_TRACE_NODE_IDENTITY( m_edge.first.identity( edge_.first ) );
00269 CTTL_TRACE_NODE_IDENTITY( m_edge.second.identity( edge_.first ) );
00270 CTTL_TRACE_NODE_IDENTITY( 0 );
00271 size_t match_offset = m_expr.match( edge_ );
00272 if ( match_offset != SubstrT::string_T::npos ) {
00273 m_edge.first.offset( match_offset );
00274 m_edge.second.offset( edge_.first.offset() );
00275 CTTL_TRACE_EDGE_RESULT_TRUE( 'e' );
00276 return match_offset;
00277 }
00278
00279 CTTL_TRACE_EDGE_RESULT_FALSE( 'e', m_edge.first.identity( edge_.first ) );
00280 return SubstrT::string_T::npos;
00281 }
00282
00302 template< typename SubstrT >
00303 size_t find( SubstrT& edge_ )
00304 {
00305 CTTL_TRACE_LEVEL_FIND( 'e' );
00306 CTTL_TRACE_JUSTIFY();
00307 CTTL_TRACE_NODE_IDENTITY( m_edge.first.identity( edge_.first ) );
00308 CTTL_TRACE_NODE_IDENTITY( m_edge.second.identity( edge_.first ) );
00309 CTTL_TRACE_NODE_IDENTITY( 0 );
00310 size_t match_offset = m_expr.find( edge_ );
00311 if ( match_offset != SubstrT::string_T::npos ) {
00312 m_edge.first.offset( match_offset );
00313 m_edge.second.offset( edge_.first.offset() );
00314 CTTL_TRACE_EDGE_RESULT_TRUE( 'e' );
00315 return match_offset;
00316 }
00317
00318 CTTL_TRACE_EDGE_RESULT_FALSE( 'e', m_edge.first.identity( edge_.first ) );
00319 return SubstrT::string_T::npos;
00320 }
00321
00341 template< typename SubstrT >
00342 size_t bang_find( SubstrT& edge_ )
00343 {
00344 CTTL_TRACE_LEVEL_BANG( 'e' );
00345 CTTL_TRACE_JUSTIFY();
00346 CTTL_TRACE_NODE_IDENTITY( m_edge.first.identity( edge_.first ) );
00347 CTTL_TRACE_NODE_IDENTITY( m_edge.second.identity( edge_.first ) );
00348 CTTL_TRACE_NODE_IDENTITY( 0 );
00349 size_t match_offset = m_expr.bang_find( edge_ );
00350 if ( match_offset != SubstrT::string_T::npos ) {
00351 m_edge.first.offset( match_offset );
00352 m_edge.second.offset( edge_.first.offset() );
00353 CTTL_TRACE_EDGE_RESULT_TRUE( 'e' );
00354 return match_offset;
00355 }
00356
00357 CTTL_TRACE_EDGE_RESULT_FALSE( 'e', m_edge.first.identity( edge_.first ) );
00358 return SubstrT::string_T::npos;
00359 }
00360
00361 private:
00363 xtl_edge< EdgeT, ExprT >& operator=( xtl_edge< EdgeT, ExprT > const& );
00364
00365 };
00366
00367
00381 template< typename NodeT, typename ExprT >
00382 class xtl_node {
00383
00384 private:
00386 NodeT& m_node;
00387
00389 ExprT m_expr;
00390
00391 public:
00392
00393
00395 xtl_node( NodeT& node_, ExprT const& expr_ )
00396 :
00397 m_node( node_ ),
00398 m_expr( expr_ )
00399 {
00400 }
00401
00402
00403
00423 template< typename SubstrT >
00424 size_t match( SubstrT& edge_ )
00425 {
00426 typedef typename SubstrT::strict_edge_T strict_universe_T;
00427
00428 CTTL_TRACE_LEVEL_MATCH( 'n' );
00429 CTTL_TRACE_JUSTIFY();
00430 CTTL_TRACE_NODE_IDENTITY( m_node.identity( edge_.first ) );
00431 CTTL_TRACE_NODE_IDENTITY( 0 );
00432 size_t match_offset = m_expr.match( edge_ );
00433 if ( match_offset != SubstrT::string_T::npos ) {
00434 m_node.offset( match_offset );
00435
00436
00437 CTTL_TRACE_NODE_RESULT_TRUE( 'n', strict_universe_T( m_node, edge_.first ) );
00438 return match_offset;
00439 }
00440
00441 CTTL_TRACE_NODE_RESULT_FALSE( 'n', m_node.identity( edge_.first ) );
00442 return SubstrT::string_T::npos;
00443 }
00444
00464 template< typename SubstrT >
00465 size_t find( SubstrT& edge_ )
00466 {
00467 typedef typename SubstrT::strict_edge_T strict_universe_T;
00468
00469 CTTL_TRACE_LEVEL_FIND( 'n' );
00470 CTTL_TRACE_JUSTIFY();
00471 CTTL_TRACE_NODE_IDENTITY( m_node.identity( edge_.first ) );
00472 CTTL_TRACE_NODE_IDENTITY( 0 );
00473 size_t match_offset = m_expr.find( edge_ );
00474 if ( match_offset != SubstrT::string_T::npos ) {
00475 m_node.offset( match_offset );
00476
00477
00478 CTTL_TRACE_NODE_RESULT_TRUE( 'n', strict_universe_T( m_node, edge_.first ) );
00479 return match_offset;
00480 }
00481
00482 CTTL_TRACE_NODE_RESULT_FALSE( 'n', m_node.identity( edge_.first ) );
00483 return SubstrT::string_T::npos;
00484 }
00485
00505 template< typename SubstrT >
00506 size_t bang_find( SubstrT& edge_ )
00507 {
00508 typedef typename SubstrT::strict_edge_T strict_universe_T;
00509
00510 CTTL_TRACE_LEVEL_BANG( 'n' );
00511 CTTL_TRACE_JUSTIFY();
00512 CTTL_TRACE_NODE_IDENTITY( m_node.identity( edge_.first ) );
00513 CTTL_TRACE_NODE_IDENTITY( 0 );
00514 size_t match_offset = m_expr.bang_find( edge_ );
00515 if ( match_offset != SubstrT::string_T::npos ) {
00516 m_node.offset( match_offset );
00517
00518
00519 CTTL_TRACE_NODE_RESULT_TRUE( 'n', strict_universe_T( m_node, edge_.first ) );
00520 return match_offset;
00521 }
00522
00523 CTTL_TRACE_NODE_RESULT_FALSE( 'n', m_node.identity( edge_.first ) );
00524 return SubstrT::string_T::npos;
00525 }
00526
00527 private:
00529 xtl_node< NodeT, ExprT >& operator=( xtl_node< NodeT, ExprT > const& );
00530
00531 };
00532
00533
00534 }
00535
00536 #endif // _CTTL_XTLBASE_H_INCLUDED_