Object Container. More...
#include <robjectcontainer.h>
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
-
C The class of the elements to be contained. bAlloc Specify 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:
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
-
first First identifier assigned to an object. m The initial maximal size of the array. i The 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 |
Destructor.
Member Function Documentation
void VerifyTab | ( | size_t | max | ) |
Verify that a given set of containers can hold a given size of objects.
- Parameters
-
max Maximum 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
-
m New maximal size of the array. If null, the old size remains. i New 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
-
min Minimum position of the elements to iterate. max Maximum 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
-
tab Array that will be filled. alloc Must the array be allocated. min Starting index of the container's part concerned. max Ending 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
-
id Identifier 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
-
id Identifier 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
-
TUse The type of tag, the container uses the Compare(TUse &) member function of the elements.
- Parameters
-
tag The tag used. sortkey The 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
-
obj Object.
- Returns
- true if the container has assigned an identifier to the object.
void DeleteObj | ( | C * | obj | ) |
Delete a object.
- Parameters
-
obj Object.
void AssignId | ( | C * | obj | ) |
Assign an identifier to a new object.
- Parameters
-
obj Object.
Field Documentation
|
protected |
The container of objects ordered by identifier.
|
protected |
The objects of the list ordered by the search criteria.
|
protected |
First identifier of the objects.