Bag  0.91
Public Member Functions | List of all members
ArrayBag< ItemType > Class Template Reference

#include <ArrayBag.h>

Inheritance diagram for ArrayBag< ItemType >:
BagInterface< ItemType >

Public Member Functions

 ArrayBag ()
int getCurrentSize () const
bool isEmpty () const
bool add (const ItemType &newEntry)
bool remove (const ItemType &anEntry)
void clear ()
bool contains (const ItemType &anEntry) const
int getFrequencyOf (const ItemType &anEntry) const
std::vector< ItemType > toVector () const
- Public Member Functions inherited from BagInterface< ItemType >
virtual ~BagInterface ()

Detailed Description

template<class ItemType>
class ArrayBag< ItemType >

Definition at line 13 of file ArrayBag.h.

Constructor & Destructor Documentation

template<class ItemType >
ArrayBag< ItemType >::ArrayBag ( )

Definition at line 11 of file ArrayBag.cpp.

Member Function Documentation

template<class ItemType >
bool ArrayBag< ItemType >::add ( const ItemType &  newEntry)
virtual

Adds a new entry to this bag.

Postcondition
If successful, newEntry is stored in the bag and the count of items in the bag has increased by 1.
Parameters
newEntryThe object to be added as a new entry.
Returns
True if addition was successful, or false if not.

Implements BagInterface< ItemType >.

Definition at line 28 of file ArrayBag.cpp.

Referenced by restoreBag().

template<class ItemType >
void ArrayBag< ItemType >::clear ( )
virtual

Removes all entries from this bag.

Postcondition
Bag contains no items, and the count of items is 0.

Implements BagInterface< ItemType >.

Definition at line 55 of file ArrayBag.cpp.

template<class ItemType >
bool ArrayBag< ItemType >::contains ( const ItemType &  anEntry) const
virtual

Tests whether this bag contains a given entry.

Parameters
anEntryThe entry to locate.
Returns
True if bag contains anEntry, or false otherwise.

Implements BagInterface< ItemType >.

Definition at line 79 of file ArrayBag.cpp.

template<class ItemType >
int ArrayBag< ItemType >::getCurrentSize ( ) const
virtual

Gets the current number of entries in this bag.

Returns
The integer number of entries currently in the bag.

Implements BagInterface< ItemType >.

Definition at line 16 of file ArrayBag.cpp.

Referenced by processOption(), and restoreBag().

template<class ItemType >
int ArrayBag< ItemType >::getFrequencyOf ( const ItemType &  anEntry) const
virtual

Counts the number of times a given entry appears in this bag.

Parameters
anEntryThe entry to be counted.
Returns
The number of times anEntry appears in the bag.

Implements BagInterface< ItemType >.

Definition at line 61 of file ArrayBag.cpp.

template<class ItemType >
bool ArrayBag< ItemType >::isEmpty ( ) const
virtual

Sees whether this bag is empty.

Returns
True if the bag is empty, or false if not.

Implements BagInterface< ItemType >.

Definition at line 22 of file ArrayBag.cpp.

template<class ItemType >
bool ArrayBag< ItemType >::remove ( const ItemType &  anEntry)
virtual

Removes one occurrence of a given entry from this bag, if possible.

Postcondition
If successful, anEntry has been removed from the bag and the count of items in the bag has decreased by 1.
Parameters
anEntryThe entry to be removed.
Returns
True if removal was successful, or false if not.

Implements BagInterface< ItemType >.

Definition at line 41 of file ArrayBag.cpp.

template<class ItemType >
std::vector< ItemType > ArrayBag< ItemType >::toVector ( ) const
virtual

Empties and then fills a given vector with all entries that are in this bag.

Returns
A vector containing all the entries in the bag.

Implements BagInterface< ItemType >.

Definition at line 85 of file ArrayBag.cpp.

Referenced by displayBag().


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