Container Child Cursor. More...

#include <rcursor.h>

Inheritance diagram for RCastCursor< B, C >:
[legend]
Collaboration diagram for RCastCursor< B, C >:
[legend]

Public Member Functions

 RCastCursor (void)
 
 RCastCursor (const RCursor< B > &src)
 
 RCastCursor (const RCastCursor< B, C > &src)
 
template<bool a, bool o>
 RCastCursor (const RContainer< B, a, o > &c, size_t min=0, size_t max=SIZE_MAX)
 
void Set (const iRContainer< B > &c, size_t min=0, size_t max=SIZE_MAX)
 
RCastCursor< B, C > & operator= (const RCastCursor< B, C > &src)
 
C * operator() (void) const
 
- Public Member Functions inherited from RCursor< B >
 RCursor (void)
 
 RCursor (const RCursor< B > &src)
 
 RCursor (const iRContainer< B > &c, size_t min=0, size_t max=SIZE_MAX)
 
RCursor< B > & operator= (const RCursor< B > &src)
 
void Set (const iRContainer< B > &c, size_t min=0, size_t max=SIZE_MAX)
 
void Clear (void)
 
void Start (void)
 
void StartFromEnd (void)
 
void GoTo (size_t idx)
 
void DeleteCurrent (RContainer< B, 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)
 
B * operator() (void) const
 

Additional Inherited Members

- Protected Attributes inherited from RCursor< B >
B ** Current
 
size_t ActPtr
 
B ** Tab
 
size_t NbPtr
 
size_t CurNbPtr
 
size_t FirstPtr
 
size_t LastPtr
 

Detailed Description

template<class B, class C>
class R::RCastCursor< B, C >

Container Child Cursor.

This class represent a cursor iterating a RContainer and performing cast of the pointers stored. It is used when the container to iterate is supposed to handle objects from a given class but the objects allocated are of a child class.

Template Parameters
CClass of the elements of the container. It must inherit from the class B.
BBase class of the elements of the container. The class must declare at least one virtual method (for example the destructor).

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

Here is an example of a cursor used:

#include <rcontainer.h>
#include <rcursor.h>
using namespace R;
class O
{
public:
RString Name;
O(const RString& name) : Name(name) {}
int Compare(const O& o) const {return(Name.Compare(o.Name));}
};
class O2 : public O
{
public:
int Id;
O2(const RString& name,int id) : O(name), Id(id) {}
};
void Test(void)
{
Cont.InsertPtr(new O2("Obj1",1));
Cont.InsertPtr(new O2("Obj2",2));
Cont.InsertPtr(new O2("Obj3",3));
RCastCursor<O,O2> Cur(Cont);
for(Cur.Start();!Cur.End();Cur.Next())
cout<<Cur()->Name<<" - "<<Cur()->Id<<endl;
}
Attention
When an element is added or removed from the container parsed by the cursor, the cursor is not valid anymore.

Constructor & Destructor Documentation

RCastCursor ( void  )

Construct the cursor.

RCastCursor ( const RCursor< B > &  src)

Construct the cursor.

Parameters
srcSource container.
RCastCursor ( const RCastCursor< B, C > &  src)

Construct the cursor.

Parameters
srcSource container.
RCastCursor ( const RContainer< B, a, o > &  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. If SIZE_MAX, iterate until the end of the container.

Member Function Documentation

void Set ( const iRContainer< B > &  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.
RCastCursor<B,C>& operator= ( const RCastCursor< B, C > &  src)

Assignment operator using a "Cursor".

Parameters
srcSource container.
C* operator() ( void  ) const

Return the current element.