Container Cursor. More...

#include <rcursor.h>

Inheritance diagram for RCursor< C >:
[legend]
Collaboration diagram for RCursor< C >:
[legend]

Public Member Functions

 RCursor (void)
 
 RCursor (const RCursor< C > &src)
 
 RCursor (const iRContainer< C > &c, size_t min=0, size_t max=SIZE_MAX)
 
RCursor< C > & operator= (const RCursor< C > &src)
 
void Set (const iRContainer< C > &c, size_t min=0, size_t max=SIZE_MAX)
 
void Clear (void)
 
void Start (void)
 
void StartFromEnd (void)
 
void GoTo (size_t idx)
 
template<bool a, bool o>
void DeleteCurrent (RContainer< C, a, o > &c)
 
size_t GetPos (void) const
 
size_t GetMaxPos (void) const
 
size_t GetNb (void) const
 
bool Begin (void) const
 
bool End (void) const
 
bool IsAt (size_t idx) const
 
void Next (size_t inc=1)
 
void Prev (size_t inc=1)
 
C * operator() (void) const
 

Protected Attributes

C ** Current
 
size_t ActPtr
 
C ** Tab
 
size_t NbPtr
 
size_t CurNbPtr
 
size_t FirstPtr
 
size_t LastPtr
 

Detailed Description

template<class C>
class R::RCursor< C >

Container Cursor.

This class represent a cursor iterating a RContainer.

Parameters
CClass of the elements of the container.

Contrary to R::RCastCursor<C>, the elements iterated can be modified.

Here is an example of a cursor used:

int example(RContainer<RString,true,true>& c)
{
RCursor<MyElement> Cur(c);
for(Cur.Start();!Cur.End();Cur.Next())
Cur()->DoSomething(2.3);
RCursor<MyElement> Cur2(0,1); // Treat the first two elements
for(Cur2.Start();!Cur2.End();Cur2.Next())
Cur2()->DoSomething(2.3);
}
Attention
When an element is added or removed from the container parsed by the cursor, the cursor is not valid anymore.

Constructor & Destructor Documentation

RCursor ( void  )

Construct the cursor.

RCursor ( const RCursor< C > &  src)

Construct the cursor.

Parameters
srcSource container.
RCursor ( const iRContainer< C > &  c,
size_t  min = 0,
size_t  max = SIZE_MAX 
)

Construct the cursor.

Parameters
cContainer to iterate.
minMinimum position of the elements to iterate.
maxMaximum position of the elements to iterate (included max). If SIZE_MAX, iterate until the end of the container.

Member Function Documentation

RCursor<C>& operator= ( const RCursor< C > &  src)

Assignment operator using a "Cursor".

Parameters
srcSource container.
void Set ( const iRContainer< C > &  c,
size_t  min = 0,
size_t  max = SIZE_MAX 
)

Set the container.

Parameters
cContainer to iterate.
minMinimum position of the elements to iterate.
maxMaximum position of the elements to iterate (included max). If SIZE_MAX, iterate until the end of the container.
void Clear ( void  )

Clear the cursor.

void Start ( void  )

Start the iterator at the beginning of the container.

void StartFromEnd ( void  )

Start the iterator at the end of the container.

void GoTo ( size_t  idx)

Go to the i-th position of the cursor, event if this position contains a null pointer.

Parameters
idxIndex of the element to get.
void DeleteCurrent ( RContainer< C, a, o > &  c)

Delete the current element from the container.

Parameters
cContainer to delete from. Must be the one associated with the cursor.
size_t GetPos ( void  ) const

Get the actual position in the cursor.

size_t GetMaxPos ( void  ) const

Get the maximal position occupied by an elements in the container.

size_t GetNb ( void  ) const

Get the number of elements in the cursor.

Attention
Since a cursor has no idea of the number of non null elements in a cursor for the domain it covers, it must recompute it for each new assignment.
bool Begin ( void  ) const

Test if the begin of the cursor is reached.

bool End ( void  ) const

Test if the end of the cursor is reached.

bool IsAt ( size_t  idx) const

Test if the cursor is at a given index.

Parameters
idxIndex of the element.
void Next ( size_t  inc = 1)

Go to a given number of next elements. If the end is reached, go to the beginning.

Parameters
incNumber of elements to go to.
void Prev ( size_t  inc = 1)

Go to a given number of previous elements. If the begin is reached, go to the end.

Parameters
incNumber of elements to go to.
C* operator() ( void  ) const
Returns
the current element.

Field Documentation

C** Current
protected

This variable is used to go through the container.

size_t ActPtr
protected

This variable is used to see if the end of the container is reached.

C** Tab
protected

The array of pointers for the elements.

size_t NbPtr
protected

The number of elements in the container.

size_t CurNbPtr
protected

The number of elements in the cursor.

size_t FirstPtr
protected

The first position in the array handled by the cursor.

size_t LastPtr
protected

The last position in the array handled by the cursor.