Main Page Modules Class Hierarchy Compound List File List Compound Members

# cBag Class Reference

`#include <carray.h>`

Inheritance diagram for cBag::

List of all members.

## Public Methods
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 cObject* | dup () const
virtual void | info (char *buf)
virtual int | netPack ()
virtual int | netUnpack ()
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)

## Detailed Description

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.

## Constructor & Destructor Documentation

cBag::cBag ( | const cBag & bag )

| Copy constructor.

cBag::cBag ( | const char * name = NULL,
| int esiz = 4,
| int siz = 0,
| int delt = 5 )`[explicit]`

| 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).

cBag::~cBag ( | )`[inline, virtual]`

| Destructor. The items in the object will be deleted.

## Member Function Documentation

int cBag::add ( | void * obj )

| 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.

int cBag::addAt ( | int m,
| void * obj )

| Inserts a new item into the array at the given position.

void cBag::clear ( | )

| Clears the whole contents of the cBag.

cObject * cBag::dup ( | ) const`[inline, virtual]`

| Creates and returns an exact copy of this object. See cObject for more details. Reimplemented from cObject.

int cBag::find ( | void * obj ) const

| 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.

const void * cBag::get ( | int m ) const

| Returns a pointer to the mth item in the array or NULL if the mth position is not used.

void * cBag::get ( | int m )

| Returns a pointer to the mth item in the array or NULL if the mth position is not used.

void cBag::info ( | char * buf )`[virtual]`

| Produces a one-line description of object contents into the buffer passed as argument. See cObject for more details. Reimplemented from cObject.

bool cBag::isUsed ( | int m ) const

| Returns true if the mth position exists and an item was inserted there.

int cBag::items ( | ) const`[inline]`

| 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.)

int cBag::netPack ( | )`[virtual]`

| 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.

int cBag::netUnpack ( | )`[virtual]`

| 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.

cBag & cBag::operator= ( | const cBag & bag )

| Assignment operator. The name member doesn't get copied; see cObject's operator=() for more details. Duplication and assignment work all right with cBag.

const void * cBag::operator[] ( | int m ) const`[inline]`

| The same as get(int m). With the indexing operator, cBag can be used as a vector.

void * cBag::operator[] ( | int m )`[inline]`

| The same as get(int m). With the indexing operator, cBag can be used as a vector.

void * cBag::remove ( | int m )

| FIXME: Remove item at position m and return its pointer. (???)

void cBag::setup ( | int esiz,
| int siz,
| int delt = 5 )

| Clears the current contents and changes element size, initial array size and delta parameters.

The documentation for this class was generated from the following file:

- carray.h