cttl::node< StringT > Class Template Reference

Implements placeholder of the logical position inside parseable substring. More...

#include <node.h>

Inheritance diagram for cttl::node< StringT >:

cttl_impl::xtl_circular_node< node< StringT > >

List of all members.

Public Types

typedef StringT::value_type char_T
 Defines type of referenced character.
typedef StringT::size_type size_type
 Defines node size type.
typedef StringT string_T
 Defines type of referenced string.
typedef StringT::value_type value_type
 Defines node value type.

Public Member Functions

template<typename AdjusterT >
void adjust (AdjusterT const &adjuster_)
 Generic function accepting an adjuster object that updates positions of all nodes found in a circularly-linked list.
template<typename PredicateT >
bool find_class (PredicateT(*iswhat_)(PredicateT))
 Moves node position forward to the lower boundary of the specified character class.
size_type go_bof ()
 Moves node position to the beginning of the referenced string.
size_type go_eof ()
 Moves node position to the ending of the referenced string.
size_type go_line (size_type line_)
 Moves node position to the beginning of the specified line.
size_type go_line_end (size_type line_)
 Moves node position to the ending of the specified line.
size_type go_line_end ()
 Moves node position to the ending of the current line.
size_type go_line_home (size_type line_)
 Moves node position to the beginning of the specified line.
size_type go_line_home ()
 Moves node position to the beginning of the current line.
size_type go_line_next ()
 Moves node position to the beginning of the next line.
size_type go_line_previous ()
 Moves node position to the beginning of the previous line.
int identity (node< StringT > const &root_) const
 Identifies node position relative to another node.
void insert_go (StringT const &str_, size_type source_from_offset_, size_type source_to_offset_)
 Inserts absolute substring at the position specified by the current node.
size_type insert_go (StringT const &str_)
 Inserts text at the current position of the node.
void insert_stay (StringT const &str_, size_type source_from_offset_, size_type source_to_offset_)
 Inserts absolute substring at the position specified by the current node.
void insert_stay (StringT const &str_)
 Inserts text at the current position of the node.
size_type line () const
 Returns line number corresponding to the current position of the node.
node< StringT > & link (node< StringT > &other_)
 Inserts other node in front of the current, forming a circularly-linked list.
 node (node< StringT > const &other_, size_type offset_)
 Copy constructor with custom offset.
 node (node< StringT > const &other_)
 Copy constructor manufactures exact copy of the node.
 node (StringT &inp_, size_type offset_)
 Constructor taking reference to a string and initial node position.
 node (StringT &inp_)
 Constructor taking reference to a string.
size_type offset (size_type offset_)
 Changes node position.
size_type offset () const
 Returns node position.
template<typename ExprT >
cttl_impl::xtl_wrap< xtl_node
< node< StringT >, xtl_wrap
< ExprT > > > 
operator() (xtl_wrap< ExprT > const &expr_)
 Grammar rule adaptor of the node object.
node< StringT > & operator+= (StringT const &str_)
 Addition-assignment of string matches behavior of cttl::node::insert_go().
node< StringT > & operator-= (StringT const &str_)
 Subtraction-assignment of string matches behavior of cttl::node::insert_stay().
node< StringT > & operator= (size_type offset_)
 Assignment of types convertible to size_type updates node position.
node< StringT > & operator= (node< StringT > const &other_)
 Assignment operator.
char_Toperator[] (int subscript_)
 Returns mutable reference to the character of referenced string at the offset relative to the current position of the node.
char_T const & operator[] (int subscript_) const
 Returns character from referenced string at the offset relative to the current position of the node.
StringT const & parent () const
 Returns constant reference to the referenced string.
StringT & parent ()
 Returns mutable reference to the referenced string.
template<typename PredicateT >
bool rfind_class (PredicateT(*iswhat_)(PredicateT))
 Moves node position backward to the upper boundary of the specified character class.

Protected Attributes

size_type m_offset
 Stores node position.
StringT * m_pstr
 Stores pointer to the string.


Detailed Description

template<typename StringT = CTTL_STD_STRING>
class cttl::node< StringT >

Implements placeholder of the logical position inside parseable substring.

Template Parameters:
StringT specifies type of the referenced string. The default is std::string

Definition at line 64 of file node.h.


Member Typedef Documentation

template<typename StringT = CTTL_STD_STRING>
typedef StringT::value_type cttl::node< StringT >::char_T

Defines type of referenced character.

Definition at line 75 of file node.h.

template<typename StringT = CTTL_STD_STRING>
typedef StringT::size_type cttl::node< StringT >::size_type

Defines node size type.

Definition at line 81 of file node.h.

template<typename StringT = CTTL_STD_STRING>
typedef StringT cttl::node< StringT >::string_T

Defines type of referenced string.

Definition at line 72 of file node.h.

template<typename StringT = CTTL_STD_STRING>
typedef StringT::value_type cttl::node< StringT >::value_type

Defines node value type.

Definition at line 78 of file node.h.


Constructor & Destructor Documentation

template<typename StringT = CTTL_STD_STRING>
cttl::node< StringT >::node ( StringT &  inp_  ) 

Constructor taking reference to a string.

Postcondition:
The node is positioned at the end of the string.

Definition at line 97 of file node.h.

00098             :
00099         m_offset( inp_.length() ),
00100             m_pstr( &inp_ )
00101         {
00102         }

template<typename StringT = CTTL_STD_STRING>
cttl::node< StringT >::node ( StringT &  inp_,
size_type  offset_ 
)

Constructor taking reference to a string and initial node position.

Parameters:
inp_ Mutable reference to a string.
offset_ Initial offset of the node.

Definition at line 114 of file node.h.

00115             :
00116         m_offset( offset_ ),
00117             m_pstr( &inp_ )
00118         {
00119         }

template<typename StringT = CTTL_STD_STRING>
cttl::node< StringT >::node ( node< StringT > const &  other_  ) 

Copy constructor manufactures exact copy of the node.

Postcondition:
The other_ node is inserted in front of this node, forming a circularly-linked list.

Definition at line 127 of file node.h.

00128             :
00129         xtl_circular_node< node< StringT > >( other_ ),
00130             m_offset( other_.m_offset ),
00131             m_pstr( other_.m_pstr )
00132         {
00133         }

template<typename StringT = CTTL_STD_STRING>
cttl::node< StringT >::node ( node< StringT > const &  other_,
size_type  offset_ 
)

Copy constructor with custom offset.

Postcondition:
The other_ node is inserted in front of this node, forming a circularly-linked list.

Definition at line 141 of file node.h.

00142             :
00143         xtl_circular_node< node< StringT > >( other_ ),
00144             m_offset( offset_ ),
00145             m_pstr( other_.m_pstr )
00146         {
00147         }


Member Function Documentation

template<typename StringT = CTTL_STD_STRING>
template<typename AdjusterT >
void cttl::node< StringT >::adjust ( AdjusterT const &  adjuster_  ) 

Generic function accepting an adjuster object that updates positions of all nodes found in a circularly-linked list.

Definition at line 633 of file node.h.

00634         {
00635             node< StringT >* iter = this;
00636             do {
00637                 adjuster_.adjust( iter->m_offset );
00638                 iter = static_cast< node< StringT >* >( iter->m_pnext );
00639 
00640             } while ( iter != this );
00641         }

template<typename StringT = CTTL_STD_STRING>
template<typename PredicateT >
bool cttl::node< StringT >::find_class ( PredicateT(*)(PredicateT)  iswhat_  ) 

Moves node position forward to the lower boundary of the specified character class.

Returns:
true if node offset was adjusted; false otherwise.

Definition at line 270 of file node.h.

00271         {
00272             StringT const& str = parent();
00273             if ( iswhat_( str[ offset() ] ) ) {
00274                 // successful match found for the specified character class,
00275                 // find ending position
00276                 typename StringT::const_iterator it = str.begin() + offset();
00277                 it = std::find_if( it, str.end(), std::not1( std::ptr_fun( iswhat_ ) ) );
00278                 if ( it != str.end() )
00279                     offset( std::distance( str.begin(), it ) ); // set ending position
00280                 else
00281                     offset( str.length() ); // set ending position
00282 
00283                 return true;
00284             }
00285             return false;
00286         }

template<typename StringT = CTTL_STD_STRING>
size_type cttl::node< StringT >::go_bof (  ) 

Moves node position to the beginning of the referenced string.

Returns:
new position of the node.

Definition at line 366 of file node.h.

00367         {
00368             return m_offset = 0;
00369         }

template<typename StringT = CTTL_STD_STRING>
size_type cttl::node< StringT >::go_eof (  ) 

Moves node position to the ending of the referenced string.

Returns:
new position of the node.

Definition at line 377 of file node.h.

00378         {
00379             return m_offset = m_pstr->length();
00380         }

template<typename StringT = CTTL_STD_STRING>
size_type cttl::node< StringT >::go_line ( size_type  line_  ) 

Moves node position to the beginning of the specified line.

Returns:
new position of the node.

Definition at line 344 of file node.h.

00345         {
00346             m_offset = 0;
00347             while ( --line_ ) {
00348                 m_offset = m_pstr->find( char_T( '\n' ), m_offset );   // find lf
00349                 if ( m_offset == StringT::npos )
00350                     return m_offset = m_pstr->length();
00351                 ++m_offset;   // position next to lf
00352             }
00353             return m_offset;
00354         }

template<typename StringT = CTTL_STD_STRING>
size_type cttl::node< StringT >::go_line_end ( size_type  line_  ) 

Moves node position to the ending of the specified line.

Parameters:
line_ target line number.
Returns:
new position of the node.

Definition at line 469 of file node.h.

00470         {
00471             go_line( line_ );
00472             return go_line_end();
00473         }

template<typename StringT = CTTL_STD_STRING>
size_type cttl::node< StringT >::go_line_end (  ) 

Moves node position to the ending of the current line.

Returns:
new position of the node.

Definition at line 450 of file node.h.

00451         {
00452             static const char_T end_of_line[] = { char_T( '\r' ), char_T( '\n' ), 0x00 };
00453             m_offset = m_pstr->find_first_of( end_of_line, m_offset );
00454             if ( m_offset == StringT::npos )
00455                 return m_offset = m_pstr->length();
00456 
00457             return m_offset;
00458         }

template<typename StringT = CTTL_STD_STRING>
size_type cttl::node< StringT >::go_line_home ( size_type  line_  ) 

Moves node position to the beginning of the specified line.

Parameters:
line_ target line number.
Returns:
new position of the node.

Definition at line 438 of file node.h.

00439         {
00440             go_line( line_ );
00441             return go_line_home();
00442         }

template<typename StringT = CTTL_STD_STRING>
size_type cttl::node< StringT >::go_line_home (  ) 

Moves node position to the beginning of the current line.

Returns:
new position of the node.

Definition at line 417 of file node.h.

00418         {
00419             if ( (*m_pstr)[ m_offset ] == char_T( '\n' ) )
00420                 return m_offset; // stay where you are
00421 
00422             m_offset = m_pstr->rfind( char_T( '\n' ), m_offset );    // find previous lf
00423             if ( m_offset == StringT::npos )
00424                 return m_offset = 0;
00425 
00426             return ++m_offset;   // position next to lf
00427         }

template<typename StringT = CTTL_STD_STRING>
size_type cttl::node< StringT >::go_line_next (  ) 

Moves node position to the beginning of the next line.

Returns:
new position of the node.

Definition at line 388 of file node.h.

00389         {
00390             m_offset = m_pstr->find( char_T( '\n' ), m_offset ); // find next lf
00391             if ( m_offset == StringT::npos )
00392                 return m_offset = m_pstr->length();
00393 
00394             return ++m_offset;   // position next to lf
00395         }

template<typename StringT = CTTL_STD_STRING>
size_type cttl::node< StringT >::go_line_previous (  ) 

Moves node position to the beginning of the previous line.

Returns:
new position of the node.

Definition at line 403 of file node.h.

00404         {
00405             size_type current_line = line();
00406             if ( --current_line )
00407                 return go_line( current_line );
00408             return offset();
00409         }

template<typename StringT = CTTL_STD_STRING>
int cttl::node< StringT >::identity ( node< StringT > const &  root_  )  const

Identifies node position relative to another node.

Parameters:
root_ Reference to the relative node to measure the distance.
Returns:
The function returns distance between the two nodes.
The unit of measurement is the number of hops required to reach the other node.
In addition, the function may return the following values:
  • Minus one: indicates that two nodes are not on the same list. Its meaning is that the distance cannot be measured.

  • Zero: indicates that the node is single; no other nodes are present on the list.

Definition at line 254 of file node.h.

00255         {
00256             return list_distance( root_ );
00257         }

template<typename StringT = CTTL_STD_STRING>
void cttl::node< StringT >::insert_go ( StringT const &  str_,
size_type  source_from_offset_,
size_type  source_to_offset_ 
)

Inserts absolute substring at the position specified by the current node.

Definition at line 512 of file node.h.

00517         {
00518             size_type str_length = source_to_offset_ - source_from_offset_;
00519 
00520             if ( !str_.length() )
00521                 return; // nothing to do
00522 
00523             size_type insertion_offset = offset();
00524 
00525             m_pstr->insert(
00526                 insertion_offset,
00527                 str_,
00528                 source_from_offset_,
00529                 str_length
00530                 );
00531 
00532             xtl_identity_insert_go< StringT > insert_go(
00533                 insertion_offset,
00534                 int( str_length )
00535                 );
00536 
00537             adjust( insert_go );
00538         }

template<typename StringT = CTTL_STD_STRING>
size_type cttl::node< StringT >::insert_go ( StringT const &  str_  ) 

Inserts text at the current position of the node.

Parameters:
str_ reference to the source string.
Postcondition:
node position is adjusted to the end of the inserted text. Logical positions of all nodes at the same position and at higher offsets are also adjusted.
Returns:
new position of the node.

Definition at line 489 of file node.h.

00490         {
00491             text_insert_go( str_ );
00492             return offset();
00493         }

template<typename StringT = CTTL_STD_STRING>
void cttl::node< StringT >::insert_stay ( StringT const &  str_,
size_type  source_from_offset_,
size_type  source_to_offset_ 
)

Inserts absolute substring at the position specified by the current node.

Definition at line 541 of file node.h.

00546         {
00547             size_type str_length = source_to_offset_ - source_from_offset_;
00548 
00549             if ( !str_length )
00550                 return; // nothing to do
00551 
00552             size_type insertion_offset = offset();
00553 
00554             m_pstr->insert(
00555                 insertion_offset,
00556                 str_,
00557                 source_from_offset_,
00558                 str_length
00559                 );
00560 
00561             xtl_identity_insert_stay< StringT > insert_stay(
00562                 insertion_offset,
00563                 str_length
00564                 );
00565 
00566             adjust( insert_stay );
00567         }

template<typename StringT = CTTL_STD_STRING>
void cttl::node< StringT >::insert_stay ( StringT const &  str_  ) 

Inserts text at the current position of the node.

Parameters:
str_ reference to the source string.
Postcondition:
Logical positions of any node at the same position remain unchanged. Positions of all nodes at higher offset positions are adjusted.

Definition at line 506 of file node.h.

00507         {
00508             text_insert_stay( str_ );
00509         }

template<typename StringT = CTTL_STD_STRING>
size_type cttl::node< StringT >::line (  )  const

Returns line number corresponding to the current position of the node.

Definition at line 331 of file node.h.

00332         {
00333             if ( !m_pstr->length() )   // string is empty
00334                 return 1;
00335             return 1 + std::count( m_pstr->begin(), m_pstr->begin() + m_offset, char_T( '\n' ) );
00336         }

template<typename StringT = CTTL_STD_STRING>
node< StringT >& cttl::node< StringT >::link ( node< StringT > &  other_  ) 

Inserts other node in front of the current, forming a circularly-linked list.

Precondition:
  • (a) The other_ node is expected to have the same parent string, and
  • (b) The other_ node should be single.
Warning:
If the above pre-conditions are not met, the assert will fail on either condition in the debug build.

Definition at line 160 of file node.h.

00161         {
00162             assert( m_pstr == other_.m_pstr );
00163             list_insert( other_ );
00164             return other_;
00165         }

template<typename StringT = CTTL_STD_STRING>
size_type cttl::node< StringT >::offset ( size_type  offset_  ) 

Changes node position.

Returns:
old position of the node.

Definition at line 323 of file node.h.

00324         {
00325             size_type tmp = m_offset;
00326             m_offset = offset_;
00327             return tmp;
00328         }

template<typename StringT = CTTL_STD_STRING>
size_type cttl::node< StringT >::offset (  )  const

Returns node position.

Definition at line 312 of file node.h.

00313         {
00314             return m_offset;
00315         }

template<typename StringT = CTTL_STD_STRING>
template<typename ExprT >
cttl_impl::xtl_wrap< xtl_node< node< StringT >, xtl_wrap< ExprT > > > cttl::node< StringT >::operator() ( xtl_wrap< ExprT > const &  expr_  ) 

Grammar rule adaptor of the node object.

Template Parameters:
ExprT Type of the grammar expression, determined by the C++ compiler at compile time.
Parameters:
expr_ CTTL grammar expression

Definition at line 612 of file node.h.

00613         {
00614             // function-call operator must be a nonstatic member function
00615             typedef
00616                 xtl_node<
00617                 node< StringT >,
00618                 xtl_wrap< ExprT >
00619                 > xtl_node_T;
00620 
00621             return xtl_wrap< xtl_node_T >( xtl_node_T( *this, expr_ ) );
00622         }

template<typename StringT = CTTL_STD_STRING>
node< StringT >& cttl::node< StringT >::operator+= ( StringT const &  str_  ) 

Addition-assignment of string matches behavior of cttl::node::insert_go().

Definition at line 201 of file node.h.

00202         {
00203             insert_go( str_ );
00204             return *this;
00205         }

template<typename StringT = CTTL_STD_STRING>
node< StringT >& cttl::node< StringT >::operator-= ( StringT const &  str_  ) 

Subtraction-assignment of string matches behavior of cttl::node::insert_stay().

Definition at line 210 of file node.h.

00211         {
00212             insert_stay( str_ );
00213             return *this;
00214         }

template<typename StringT = CTTL_STD_STRING>
node< StringT >& cttl::node< StringT >::operator= ( size_type  offset_  ) 

Assignment of types convertible to size_type updates node position.

Definition at line 192 of file node.h.

00193         {
00194             m_offset = offset_;
00195             return *this;
00196         }

template<typename StringT = CTTL_STD_STRING>
node< StringT >& cttl::node< StringT >::operator= ( node< StringT > const &  other_  ) 

Assignment operator.

Remarks:
Node assignment doesn't match the behavior of the node copy constructor. The assignment provides no automatic linkage of nodes.
Instead, the node position is assigned.
To manage list linkage, use node::link() member function.

Definition at line 179 of file node.h.

00180         {
00181             if ( this == &other_ ) {
00182                 return *this;
00183             }
00184 
00185             m_offset = other_.m_offset;
00186             return *this;
00187         }

template<typename StringT = CTTL_STD_STRING>
char_T& cttl::node< StringT >::operator[] ( int  subscript_  ) 

Returns mutable reference to the character of referenced string at the offset relative to the current position of the node.

Parameters:
subscript_ relative offset adjustment value.

Definition at line 588 of file node.h.

00589         {
00590             return (*m_pstr)[ offset() + subscript_ ];
00591         }

template<typename StringT = CTTL_STD_STRING>
char_T const& cttl::node< StringT >::operator[] ( int  subscript_  )  const

Returns character from referenced string at the offset relative to the current position of the node.

Parameters:
subscript_ relative offset adjustment value.

Definition at line 576 of file node.h.

00577         {
00578             return (*m_pstr)[ offset() + subscript_ ];
00579         }

template<typename StringT = CTTL_STD_STRING>
StringT const& cttl::node< StringT >::parent (  )  const

Returns constant reference to the referenced string.

Definition at line 227 of file node.h.

00228         {
00229             return *m_pstr;
00230         }

template<typename StringT = CTTL_STD_STRING>
StringT& cttl::node< StringT >::parent (  ) 

Returns mutable reference to the referenced string.

Definition at line 221 of file node.h.

00222         {
00223             return *m_pstr;
00224         }

template<typename StringT = CTTL_STD_STRING>
template<typename PredicateT >
bool cttl::node< StringT >::rfind_class ( PredicateT(*)(PredicateT)  iswhat_  ) 

Moves node position backward to the upper boundary of the specified character class.

Returns:
true if node offset was adjusted; false otherwise.

Definition at line 295 of file node.h.

00296         {
00297             StringT const& str = parent();
00298             if ( offset() && iswhat_( str[ offset() - 1 ] ) ) {
00299                 // successful match found for the specified character class,
00300                 // find beginning position for the character class:
00301                 typename StringT::const_reverse_iterator it( str.begin() + offset() );
00302                 typename StringT::const_reverse_iterator it_end( str.begin() );
00303                 it = std::find_if( it, it_end, std::not1( std::ptr_fun( iswhat_ ) ) );
00304                 offset( std::distance( it, it_end ) );  // set beginning position
00305 
00306                 return true;
00307             }
00308             return false;
00309         }


Member Data Documentation

template<typename StringT = CTTL_STD_STRING>
size_type cttl::node< StringT >::m_offset [protected]

Stores node position.

Definition at line 85 of file node.h.

template<typename StringT = CTTL_STD_STRING>
StringT* cttl::node< StringT >::m_pstr [protected]

Stores pointer to the string.

Definition at line 88 of file node.h.


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

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