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

#include <Bag.h>

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

Public Member Functions

 Bag ()
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
vector< ItemType > toVector () const

Detailed Description

template<class ItemType>
class Bag< ItemType >

Definition at line 14 of file Bag.h.

Constructor & Destructor Documentation

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

Definition at line 10 of file Bag.cpp.

Member Function Documentation

template<class ItemType >
bool Bag< 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 27 of file Bag.cpp.

Referenced by main(), and restoreBag().

template<class ItemType >
void Bag< 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 54 of file Bag.cpp.

template<class ItemType >
bool Bag< 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 78 of file Bag.cpp.

Referenced by main().

template<class ItemType >
int Bag< 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 15 of file Bag.cpp.

Referenced by processOption(), and restoreBag().

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

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

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

Implements BagInterface< ItemType >.

Definition at line 60 of file Bag.cpp.

template<class ItemType >
bool Bag< 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 21 of file Bag.cpp.

Referenced by main().

template<class ItemType >
bool Bag< 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 40 of file Bag.cpp.

Referenced by main().

template<class ItemType >
vector< ItemType > Bag< 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 108 of file Bag.cpp.

Referenced by displayBag().


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