class BagInterface
1: // Created by Frank M. Carrano and Tim Henry.
2: // Copyright (c) 2013 __Pearson Education__. All rights reserved.
4: /** Listing 1-1.
5: @file BagInterface.h */
6: #ifndef _BAG_INTERFACE
7: #define _BAG_INTERFACE
9: #include <vector>
10: using namespace std;
12: template<class ItemType>
13: class BagInterface
14: {
15: public:
16: /** Gets the current number of entries in this bag.
17: @return The integer number of entries currently in the bag. */
18: virtual int getCurrentSize() const = 0;
19:
20: /** Sees whether this bag is empty.
21: @return True if the bag is empty, or false if not. */
22: virtual bool isEmpty() const = 0;
23:
24: /** Adds a new entry to this bag.
25: @post If successful, newEntry is stored in the bag and
26: the count of items in the bag has increased by 1.
27: @param newEntry The object to be added as a new entry.
28: @return True if addition was successful, or false if not. */
29: virtual bool add(const ItemType& newEntry) = 0;
30:
31: /** Removes one occurrence of a given entry from this bag,
32: if possible.
33: @post If successful, anEntry has been removed from the bag
34: and the count of items in the bag has decreased by 1.
35: @param anEntry The entry to be removed.
36: @return True if removal was successful, or false if not. */
37: virtual bool remove(const ItemType& anEntry) = 0;
38:
39: /** Removes all entries from this bag.
40: @post Bag contains no items, and the count of items is 0. */
41: virtual void clear() = 0;
42:
43: /** Counts the number of times a given entry appears in bag.
44: @param anEntry The entry to be counted.
45: @return The number of times anEntry appears in the bag. */
46: virtual int getFrequencyOf(const ItemType& anEntry) const = 0;
47:
48: /** Tests whether this bag contains a given entry.
49: @param anEntry The entry to locate.
50: @return True if bag contains anEntry, or false otherwise. */
51: virtual bool contains(const ItemType& anEntry) const = 0;
52:
53: /** Empties and then f ills a given vector with all entries that
54: are in this bag.
55: @return A vector containing all the entries in the bag. */
56: virtual vector<ItemType> toVector() const = 0;
57: }; // end BagInterface
58: #endif