CISC 2200 Project 2
Public Member Functions | List of all members
VectorBag< ItemType > Class Template Reference

VectorBag is a vector-based implementation of BagInterface. More...

#include <VectorBag.h>

Inheritance diagram for VectorBag< ItemType >:
Inheritance graph
[legend]
Collaboration diagram for VectorBag< ItemType >:
Collaboration graph
[legend]

Public Member Functions

int getCurrentSize () const
 Gets the current number of entries in this bag. More...
 
bool isEmpty () const
 Sees whether this bag is empty. More...
 
bool add (const ItemType &newEntry)
 Adds a new entry to this bag. More...
 
bool remove (const ItemType &anEntry)
 Removes one occurrence of a given entry from this bag, if possible. More...
 
void clear ()
 Removes all entries from this bag. More...
 
bool contains (const ItemType &anEntry) const
 Tests whether this bag contains a given entry. More...
 
int getFrequencyOf (const ItemType &anEntry) const
 Counts the number of times a given entry appears in bag. More...
 
vector< ItemType > toVector () const
 Empties and then f ills a given vector with all entries that are in this bag. More...
 
VectorBag< ItemType > operator+ (VectorBag< ItemType > anotherBag)
 Creates a new bag that combines the contents of this bag and a second given bag without affecting the original two bags. More...
 
VectorBag< ItemType > operator* (VectorBag< ItemType > anotherBag)
 Creates a new bag that contains those objects that occur in both this bag and a second given bag without affecting the original two bags. More...
 
VectorBag< ItemType > operator- (VectorBag< ItemType > anotherBag)
 Creates a new bag of objects that would be left in this bag after removing those that also occur in a second given bag without affecting the original two bags. More...
 

Detailed Description

template<class ItemType>
class VectorBag< ItemType >

VectorBag is a vector-based implementation of BagInterface.

Member Function Documentation

◆ add()

template<class ItemType >
bool VectorBag< 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 >.

◆ clear()

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

Removes all entries from this bag.

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

Implements BagInterface< ItemType >.

◆ contains()

template<class ItemType >
bool VectorBag< 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 >.

◆ getCurrentSize()

template<class ItemType >
int VectorBag< 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 >.

◆ getFrequencyOf()

template<class ItemType >
int VectorBag< 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 >.

◆ isEmpty()

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

Sees whether this bag is empty.

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

Implements BagInterface< ItemType >.

◆ operator*()

template<class ItemType >
VectorBag< ItemType > VectorBag< ItemType >::operator* ( VectorBag< ItemType >  anotherBag)

Creates a new bag that contains those objects that occur in both this bag and a second given bag without affecting the original two bags.

Parameters
anotherBagThe given bag.
Returns
A bag that is the intersection of the two bags.

◆ operator+()

template<class ItemType >
VectorBag< ItemType > VectorBag< ItemType >::operator+ ( VectorBag< ItemType >  anotherBag)

Creates a new bag that combines the contents of this bag and a second given bag without affecting the original two bags.

Note that we can't call this operation "<code>union</code>", since "<code>union</code>" is a reserved word.

Parameters
anotherBagThe given bag.
Returns
A bag that is the union of the two bags.

◆ operator-()

template<class ItemType >
VectorBag< ItemType > VectorBag< ItemType >::operator- ( VectorBag< ItemType >  anotherBag)

Creates a new bag of objects that would be left in this bag after removing those that also occur in a second given bag without affecting the original two bags.

Parameters
anotherBagThe given bag.
Returns
A bag that is the difference of the two bags.

◆ remove()

template<class ItemType >
bool VectorBag< 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 >.

◆ toVector()

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

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

Returns
A vector containing all the entries in the bag.

Implements BagInterface< ItemType >.


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