- Main Page
- Modules
- Classes
- Files
- Directories
- Related Pages

- Class List
- Class Hierarchy
- Class Members

# cBag Class Reference
[Container classes]

`#include <carray.h>`

Inheritance diagram for cBag:

List of all members.

## Detailed Description

Use of this class is DISCOURAGED, it is provided for backward compatibility only.

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)

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

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

virtual cPolymorphic* 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.

virtual std::string cBag::info | ( |  | ) | const`[virtual]`

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

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

virtual void cBag::netPack | ( | cCommBuffer * | buffer | ) | `[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.

virtual void cBag::netUnpack | ( | cCommBuffer * | buffer | ) | `[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 | ) |

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

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