00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00023
00032
00033
00034 #ifndef _CTTL_CONST_EDGE_H_INCLUDED_
00035 #define _CTTL_CONST_EDGE_H_INCLUDED_
00036
00037 #include "node.h"
00038 #include "xtl_edge_trait.h"
00039
00040 namespace cttl {
00041
00054 struct policy_default
00055 {
00066 typedef policy_default strict_policy_T;
00067
00108 template< typename UniverseT >
00109 static inline size_t match( UniverseT& universe_ )
00110 {
00111 return universe_.first.offset();
00112 }
00113
00136 template< typename UniverseT >
00137 static inline bool lower_bound( size_t, UniverseT& )
00138 {
00139 return false;
00140 }
00141
00157 static inline size_t lower_bound( size_t offset_, size_t )
00158 {
00159 return offset_;
00160 }
00161
00163 static inline void region_adjust( size_t, int )
00164 {
00165 }
00166
00168 static inline void region_insert( size_t, size_t )
00169 {
00170 }
00171
00173 static inline void region_erase( size_t, size_t )
00174 {
00175 }
00176
00178 template< typename StringT >
00179 StringT region_difference( StringT const& str_, size_t first_offset_, size_t second_offset_ )
00180 {
00181 return str_.substr(
00182 first_offset_,
00183 second_offset_ - first_offset_
00184 );
00185 }
00186
00187 };
00188
00189
00209 template< typename PolicyT = policy_default, typename StringT = CTTL_STD_STRING >
00210 class const_edge
00211 {
00212 public:
00214 typedef xtl_const_offset_manager offset_manager_T;
00215
00217 typedef StringT string_T;
00218
00220 typedef typename StringT::value_type char_T;
00221
00223 typedef StringT value_type;
00224
00226 typedef PolicyT policy_T;
00227
00236 typedef typename PolicyT::strict_policy_T strict_policy_T;
00237
00242 typedef const_edge< strict_policy_T, StringT > strict_edge_T;
00243
00245 typedef node< StringT > node_T;
00246
00247
00249 node< StringT > first;
00250
00252 node< StringT > second;
00253
00254 protected:
00259 PolicyT& m_space_policy;
00260
00273 static inline PolicyT& default_policy()
00274 {
00275
00276
00277 static PolicyT policy;
00278 return policy;
00279 }
00280
00281 public:
00282
00288 PolicyT& space_policy()
00289 {
00290 return m_space_policy;
00291 }
00292
00298 PolicyT const& space_policy() const
00299 {
00300 return m_space_policy;
00301 }
00302
00304
00306
00319 const_edge( input< StringT >& inp_, int start_, int finish_ )
00320 :
00321 first( inp_, start_ ),
00322 second( inp_, finish_ ),
00323 m_space_policy( default_policy() )
00324 {
00325 }
00326
00336 const_edge( node< StringT >& node_first_, node< StringT >& node_second_ )
00337 :
00338 first( node_first_ ),
00339 second( node_second_ ),
00340 m_space_policy( default_policy() )
00341 {
00342 assert( &node_first_.parent().container() == &node_second_.parent().container() );
00343 }
00344
00360 template< typename Other_policyT >
00361 const_edge( const_edge< Other_policyT, StringT > const& other_ )
00362 :
00363 first( other_.first ),
00364 second( other_.second ),
00365 m_space_policy( default_policy() )
00366 {
00367 }
00368
00370 const_edge( const_edge< PolicyT, StringT > const& other_ )
00371 :
00372 first( other_.first ),
00373 second( other_.second ),
00374 m_space_policy( other_.m_space_policy )
00375 {
00376 }
00377
00399 template< typename Other_policyT >
00400 const_edge( const_edge< Other_policyT, StringT > const& other_, PolicyT& policy_ )
00401 :
00402 first( other_.first ),
00403 second( other_.second ),
00404 m_space_policy( policy_ )
00405 {
00406 }
00407
00419 const_edge< PolicyT, StringT >& operator= ( const_edge< PolicyT, StringT > const& other_ )
00420 {
00421 if ( this != &other_ ) {
00422 first = other_.first;
00423 second = other_.second;
00424 }
00425 return *this;
00426 }
00427
00428
00437 operator StringT() const
00438 {
00439 return text();
00440 }
00441
00443 input< StringT >& parent()
00444 {
00445 return first.parent();
00446 }
00447
00449 input< StringT > const& parent() const
00450 {
00451 return first.parent();
00452 }
00453
00454 public:
00456 StringT text() const
00457 {
00458 return parent().container().text_substring( first.identity(), second.identity() );
00459 }
00460
00470 int length() const
00471 {
00472 return int( parent().container().identity_offset( second.identity() ) - parent().container().identity_offset( first.identity() ) );
00473 }
00474
00479 void push()
00480 {
00481 first.push();
00482 second.push();
00483 }
00484
00489 void pop()
00490 {
00491 second.pop();
00492 first.pop();
00493 }
00494
00499 void pop_discard()
00500 {
00501 parent().container().pop_offset();
00502 parent().container().pop_offset();
00503 }
00504
00516 void region_insert()
00517 {
00518 space_policy().region_insert(
00519 first.offset(),
00520 second.offset()
00521 );
00522 }
00523
00535 void region_erase()
00536 {
00537 space_policy().region_erase(
00538 first.offset(),
00539 second.offset()
00540 );
00541 }
00542
00553 StringT region_difference()
00554 {
00555 return space_policy().region_difference(
00556 parent().container().text(),
00557 first.offset(),
00558 second.offset()
00559 );
00560 }
00561
00563 void text_tolower()
00564 {
00565 parent().container().text_tolower( first.identity(), second.identity() );
00566 }
00567
00569 void text_toupper()
00570 {
00571 parent().container().text_toupper( first.identity(), second.identity() );
00572 }
00573
00587 template< typename ExprT >
00588 xtl_wrap<
00589 xtl_edge<
00590 const_edge< PolicyT, StringT >,
00591 xtl_wrap< ExprT >
00592 >
00593 >
00594 operator() ( xtl_wrap< ExprT > const& expr_ )
00595 {
00596 typedef
00597 xtl_edge<
00598 const_edge< PolicyT, StringT >,
00599 xtl_wrap< ExprT >
00600 > xtl_edge_T;
00601
00602 return xtl_wrap< xtl_edge_T >( xtl_edge_T( *this, expr_ ) );
00603 }
00604
00605 };
00606
00608 template< typename StringT >
00609 inline const_edge< policy_default, StringT >
00610 operator- ( node< StringT >& one_, node< StringT >& another_ )
00611 {
00612 return const_edge< policy_default, StringT >( another_, one_ );
00613 }
00614
00616 template< typename StringT >
00617 inline const_edge< policy_default, StringT >
00618 operator+ ( node< StringT >& one_, node< StringT >& another_ )
00619 {
00620 return const_edge< policy_default, StringT >( one_, another_ );
00621 }
00622
00635 template< typename PolicyT, typename StringT >
00636 inline const_edge< PolicyT, StringT >
00637 new_edge( const_edge< PolicyT, StringT >& other_ )
00638 {
00639 size_t start = other_.parent().container().identity_vector_push_back( other_.first.offset() );
00640 size_t finish = other_.parent().container().identity_vector_push_back( other_.second.offset() );
00641 return const_edge< PolicyT, StringT >( other_.parent(), start, finish );
00642 }
00643
00656 template< typename StringT >
00657 inline const_edge< policy_default, StringT >
00658 new_edge( input< StringT >& inp_ )
00659 {
00660 int start = inp_.container().identity_vector_push_back( 0 );
00661 int finish = inp_.container().identity_vector_push_back( inp_.length() );
00662 return const_edge< policy_default, StringT >( inp_, start, finish );
00663 }
00664
00683 template< typename StringT >
00684 inline const_edge< policy_default, StringT >
00685 new_edge( input< StringT >& inp_, size_t lhs_offset_, size_t rhs_offset_ )
00686 {
00687 int start = inp_.container().identity_vector_push_back( lhs_offset_ );
00688 int finish = inp_.container().identity_vector_push_back( rhs_offset_ );
00689 return const_edge< policy_default, StringT >( inp_, start, finish );
00690 }
00691
00692
00693
00694
00706 template< typename PolicyT, typename StringT >
00707 bool operator< ( const_edge< PolicyT, StringT > const& one_, const_edge< PolicyT, StringT > const& another_ )
00708 {
00709 return one_.text() < another_.text();
00710 }
00711
00723 template< typename PolicyT, typename StringT >
00724 bool operator> ( const_edge< PolicyT, StringT > const& one_, const_edge< PolicyT, StringT > const& another_ )
00725 {
00726 return one_.text() > another_.text();
00727 }
00728
00740 template< typename PolicyT, typename StringT >
00741 bool operator>= ( const_edge< PolicyT, StringT > const& one_, const_edge< PolicyT, StringT > const& another_ )
00742 {
00743 return one_.text() >= another_.text();
00744 }
00745
00757 template< typename PolicyT, typename StringT >
00758 bool operator<= ( const_edge< PolicyT, StringT > const& one_, const_edge< PolicyT, StringT > const& another_ )
00759 {
00760 return one_.text() <= another_.text();
00761 }
00762
00774 template< typename PolicyT, typename StringT >
00775 bool operator== ( const_edge< PolicyT, StringT > const& one_, const_edge< PolicyT, StringT > const& another_ )
00776 {
00777 return one_.text() == another_.text();
00778 }
00779
00791 template< typename PolicyT, typename StringT >
00792 bool operator!= ( const_edge< PolicyT, StringT > const& one_, const_edge< PolicyT, StringT > const& another_ )
00793 {
00794 return one_.text() != another_.text();
00795 }
00796
00797
00798 }
00799
00800 #endif // _CTTL_CONST_EDGE_H_INCLUDED_