Object Container. More...
#include <robjecthashcontainer.h>
Public Member Functions | |
RObjectHashContainer (size_t first, size_t nb, size_t nbi, size_t s, 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 RObjectHashContainer< C, bAlloc > &) const |
size_t | GetNbObjs (void) const |
size_t | GetNbObjsHashCode (size_t hash) const |
size_t | GetMaxObjId (void) const |
template<class TUse > | |
size_t | GetIndex (const TUse &tag, size_t &hash, bool &find) 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) |
bool | InsertObjAt (C *obj, size_t hash, size_t idx, bool del=false) |
void | DeleteObj (C *obj) |
void | AssignId (C *obj) |
virtual | ~RObjectHashContainer (void) |
Protected Attributes | |
RContainer< C, bAlloc, false > | Objects |
RHashContainer< ObjectRef, false > | ObjectsByRef |
size_t | FirstId |
Detailed Description
template<class C, bool bAlloc>
class R::RObjectHashContainer< C, bAlloc >
Object Container.
This class represent a container of objects (class C) managed through a hash index. 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 with a hash index (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 methods of the class representing them (class C). These methods 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
RObjectHashContainer | ( | size_t | first, |
size_t | nb, | ||
size_t | nbi, | ||
size_t | s, | ||
size_t | m, | ||
size_t | i = 0 |
||
) |
Constructor of a container of objects.
- Parameters
-
first First identifier assigned to an object. âram nb Initial size of the container.
âram nbi Incremental size of the container.
s Size of the hash index. The hash codes of the elements must be in the range [0,s-1]. m The initial maximal size of the array for an index. i The value used when increasing the array for an index. If null value, the size is set to the half of the maximal size.
|
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 RObjectHashContainer< 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 GetNbObjsHashCode | ( | size_t | hash | ) | const |
Get the number of the objects sharing a given hash code.
- Parameters
-
hash Hash code.
- Returns
- Maximum position occupied by the elements.
size_t GetMaxObjId | ( | void | ) | const |
Get the highest identifier for the objects.
- Returns
- Highest identifier.
size_t GetIndex | ( | const TUse & | tag, |
size_t & | hash, | ||
bool & | find | ||
) | const |
This function returns the index of an element represented by tag in a particular array of a hash code.
- Template Parameters
-
TUse The type of tag, the container uses the Compare(TUse &) member function of the elements.
- Parameters
-
tag The tag used. hash Hash code of the tag (set by the method) find If the element represented by tag exist, find is set to true (set by the method).
- Returns
- Returns the index of the element if it exists or the index where is has to inserted.
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.
bool InsertObjAt | ( | C * | obj, |
size_t | hash, | ||
size_t | idx, | ||
bool | del = false |
||
) |
Insert an element in the container at a given index of a given hash code. If the corresponding index is already used, the previously inserted element is removed from the container (and destroy if the container is responsible for the allocation).
This method should be used very carefully (in general with the GetIndex method) because the container can then disfunction.
- Parameters
-
obj Object to insert. hash Hash code of the object to insert. index Index of the object to insert. del Specify if a similar existing element must be deleted or shifted.
- 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 managed through the search criteria.
|
protected |
First identifier of the objects.