#include <carray.h>
Inheritance diagram for cBag:
Use std::vector instead.
Container class to hold small non-class items (int, double, etc). cBag stores full copy of each item inserted and NOT the pointer.
cBag is a container class which is designed to hold non-cObject items without constructors/destructors (ints, doubles, small structs etc.). cBag stores full, bit-by-bit copies of the items inserted (and not the pointers). cBag works as an array, but if it gets full, it grows automatically by a specified delta.
Public Member Functions | |
Constructors, destructor, assignment. | |
cBag (const cBag &bag) | |
cBag (const char *name=NULL, int esiz=4, int siz=0, int delt=5) | |
virtual | ~cBag () |
cBag & | operator= (const cBag &bag) |
Redefined cObject member functions | |
virtual cPolymorphic * | dup () const |
virtual std::string | info () const |
virtual void | netPack (cCommBuffer *buffer) |
virtual void | netUnpack (cCommBuffer *buffer) |
Container functions. | |
void | setup (int esiz, int siz, int delt=5) |
void | clear () |
int | items () const |
int | add (void *obj) |
int | addAt (int m, void *obj) |
int | find (void *obj) const |
void * | get (int m) |
const void * | get (int m) const |
void * | operator[] (int m) |
const void * | operator[] (int m) const |
bool | isUsed (int m) const |
void * | remove (int m) |
|
Copy constructor.
|
|
Constructor. Parameters are: name, the size of elements in bytes, the initial size of the container and the delta (by which the size will grow if it gets full). |
|
Destructor. The items in the object will be deleted. |
|
Inserts a new item into the array. A copy will be made of the item pointed to by data. The return value is the item's index in the array. |
|
Inserts a new item into the array at the given position.
|
|
Clears the whole contents of the cBag.
|
|
Creates and returns an exact copy of this object. See cObject for more details. Reimplemented from cObject. |
|
Returns the index of the first item in the array that equals the item pointed to by obj. The comparison is done byte-by-byte. If no such item was found, -1 is returned. |
|
Returns a pointer to the mth item in the array or NULL if the mth position is not used.
|
|
Returns a pointer to the mth item in the array or NULL if the mth position is not used.
|
|
Produces a one-line description of object contents into the buffer passed as argument. See cObject for more details. Reimplemented from cPolymorphic. |
|
Returns true if the mth position exists and an item was inserted there.
|
|
Returns the index of last used position+1. This is the same as the number of contained objects if there are no 'holes' in the array. (Removals may create holes.) |
|
Serializes the object into a PVM or MPI send buffer. Used by the simulation kernel for parallel execution. See cObject for more details. Reimplemented from cObject. |
|
Deserializes the object from a PVM or MPI receive buffer Used by the simulation kernel for parallel execution. See cObject for more details. Reimplemented from cObject. |
|
Assignment operator. The name member doesn't get copied; see cObject's operator=() for more details. Duplication and assignment work all right with cBag. |
|
The same as get(int m). With the indexing operator, cBag can be used as a vector. |
|
The same as get(int m). With the indexing operator, cBag can be used as a vector. |
|
Marks the mth position as free and returns pointer to corresponding item. Should be used with care as subsequent add() calls may overwrite the data at that position. |
|
Clears the current contents and changes element size, initial array size and delta parameters.
|