Object Container. More...

#include <robjectcontainer.h>

Collaboration diagram for RObjectContainer< C, bAlloc >:
[legend]

Public Member Functions

 RObjectContainer (size_t first, size_t m, size_t i=0)
 
void VerifyTab (size_t max)
 
void Clear (size_t m=0, size_t i=0)
 
int Compare (const RObjectContainer< C, bAlloc > &) const
 
size_t GetNbObjs (void) const
 
size_t GetMaxObjId (void) const
 
size_t GetMaxObjPos (void) const
 
R::RCursor< C > GetObjs (size_t min=0, size_t max=SIZE_MAX) const
 
size_t GetObjs (C **&tab, bool alloc, size_t min=0, size_t max=0)
 
const C * operator[] (size_t id) const
 
C * operator[] (size_t id)
 
template<class TUse >
C * GetObj (const TUse &tag, bool sortkey=true)
 
bool InsertObj (C *obj)
 
void DeleteObj (C *obj)
 
void AssignId (C *obj)
 
virtual ~RObjectContainer (void)
 

Protected Attributes

RContainer< C, bAlloc, false > Objects
 
R::RContainer< ObjectRef, true,
true > 
ObjectsByRef
 
size_t FirstId
 

Detailed Description

template<class C, bool bAlloc>
class R::RObjectContainer< C, bAlloc >

Object Container.

This class represent a container of objects (class C). It is supposed that each object has an unique identifier (managed by this container). The container maintains a list of objects ordered by their identifier and one ordered by a search criteria (used for search purposes). The container can be responsible for the deallocation of the elements (bAlloc).

Template Parameters
CThe class of the elements to be contained.
bAllocSpecify if the elements are deallocated by the container.

To manage the objects, the container uses member functions of the class representing them (class C). These functions have the signatures:

int Search(const C& c) const;
int Search(const TUse& tag) const;
int GetId(void) const;
int SetId(size_t id);

In practice, the Search method can be different than the Compare method of the element (class C). While it supposes the allocation of reference pointer for each element inserted, it has the advantage to allow "normal" containers to use another method for sorting elements (typically using identifiers for "normal" containers and a string for this container).

Constructor & Destructor Documentation

RObjectContainer ( size_t  first,
size_t  m,
size_t  i = 0 
)

Constructor of a container of objects.

Parameters
firstFirst identifier assigned to an object.
mThe initial maximal size of the array.
iThe value used when increasing the array. If null value, the size is set to the half the maximal size or at least to 10.
virtual ~RObjectContainer ( void  )
virtual

Destructor.

Member Function Documentation

void VerifyTab ( size_t  max)

Verify that a given set of containers can hold a given size of objects.

Parameters
maxMaximum number of objects.
void Clear ( size_t  m = 0,
size_t  i = 0 
)

Clear the container and destruct the elements if it is responsible for the deallocation. The container can also be extended.

Parameters
mNew maximal size of the array. If null, the old size remains.
iNew increasing value. If null, the old value remains.
int Compare ( const RObjectContainer< C, bAlloc > &  ) const

Compare method that can be used to construct an unordered container of containers.

size_t GetNbObjs ( void  ) const

Get the number of the objects.

Returns
Maximum position occupied by the elements.
size_t GetMaxObjId ( void  ) const

Get the highest identifier for the objects.

Returns
Highest identifier.
size_t GetMaxObjPos ( void  ) const

Get the maximum position of the objects.

Returns
Maximum position occupied by the elements.
R::RCursor<C> GetObjs ( size_t  min = 0,
size_t  max = SIZE_MAX 
) const

This method get a cursor over the objects.

Parameters
minMinimum position of the elements to iterate.
maxMaximum position of the elements to iterate (included max). If SZE_MAX, iterate until the end of the container.
Returns
a cursor over the objects.
size_t GetObjs ( C **&  tab,
bool  alloc,
size_t  min = 0,
size_t  max = 0 
)

Fill an array of pointers with the objects.

Parameters
tabArray that will be filled.
allocMust the array be allocated.
minStarting index of the container's part concerned.
maxEnding index of the container's part concerned.
Returns
number of objects in the array (including null pointers).
const C* operator[] ( size_t  id) const

Get the object with a given identifier (Only read). The operator generates an exception is the identifier is out of range.

Parameters
idIdentifier of the object.
Returns
a pointer.
C* operator[] ( size_t  id)

Get the object with a given identifier (Read/Write). The operator generates an exception is the identifier is out of range.

Parameters
idIdentifier of the object.
Returns
a pointer.
Warning
If the identifier of the object is modified, this method can disorder the container.
C* GetObj ( const TUse &  tag,
bool  sortkey = true 
)

Get a object corresponding to a search criteria.

Template Parameters
TUseThe type of tag, the container uses the Compare(TUse &) member function of the elements.
Parameters
tagThe tag used.
sortkeyThe tag represents the sorting key. The default value depends if the container is ordered (true) or not (false).
Returns
a pointer to a object.
bool InsertObj ( C *  obj)

Insert a object.

Parameters
objObject.
Returns
true if the container has assigned an identifier to the object.
void DeleteObj ( C *  obj)

Delete a object.

Parameters
objObject.
void AssignId ( C *  obj)

Assign an identifier to a new object.

Parameters
objObject.

Field Documentation

RContainer<C,bAlloc,false> Objects
protected

The container of objects ordered by identifier.

R::RContainer<ObjectRef,true,true> ObjectsByRef
protected

The objects of the list ordered by the search criteria.

size_t FirstId
protected

First identifier of the objects.