Constant Container Child Cursor. More...
#include <rconstcursor.h>
Inheritance diagram for RConstCastCursor< B, C >:
Collaboration diagram for RConstCastCursor< B, C >:
Public Member Functions | |
RConstCastCursor (void) | |
RConstCastCursor (const RConstCursor< B > &src) | |
RConstCastCursor (const RCastCursor< B, C > &src) | |
template<bool a, bool o> | |
RConstCastCursor (const RContainer< B, a, o > &c, size_t min=0, size_t max=SIZE_MAX) | |
RConstCastCursor< B, C > & | operator= (const RCastCursor< B, C > &src) |
const C * | operator() (void) const |
Public Member Functions inherited from RConstCursor< B > | |
RConstCursor (void) | |
RConstCursor (const RConstCursor< B > &src) | |
RConstCursor (const iRContainer< B > &c, size_t min=0, size_t max=SIZE_MAX) | |
RConstCursor< B > & | operator= (const RConstCursor< 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) |
const B * | operator() (void) const |
Additional Inherited Members | |
Protected Attributes inherited from RConstCursor< 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::RConstCastCursor< B, C >
Constant Container Child Cursor.
This class represent a constant 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
-
C Class of the elements of the container. It must inherit from the class B. B Base class of the elements of the container. The class must declare at least one virtual method (for example the destructor).
Contrary to R::RCastCursor<B,C>, the elements iterated cannot 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) {}
};
class O2 : public O
{
public:
int Id;
};
void Test(void)
{
RContainer<O,true,true> Cont(20);
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
RConstCastCursor | ( | void | ) |
Construct the cursor.
RConstCastCursor | ( | const RConstCursor< B > & | src | ) |
Construct the cursor.
- Parameters
-
src Source container.
RConstCastCursor | ( | const RCastCursor< B, C > & | src | ) |
Construct the cursor.
- Parameters
-
src Source container.
RConstCastCursor | ( | const RContainer< B, a, o > & | c, |
size_t | min = 0 , |
||
size_t | max = SIZE_MAX |
||
) |
Construct the cursor.
- Parameters
-
c Container to iterate. min Minimum position of the elements to iterate. max Maximum position of the elements to iterate. If SIZE_MAX, iterate until the end of the container.
Member Function Documentation
RConstCastCursor<B,C>& operator= | ( | const RCastCursor< B, C > & | src | ) |
Assignment operator using a "Cursor".
- Parameters
-
src Source container.
const C* operator() | ( | void | ) | const |
Return the current element.