-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectionFactory.h
More file actions
77 lines (60 loc) · 2.88 KB
/
Copy pathCollectionFactory.h
File metadata and controls
77 lines (60 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Blake Berry
// 03/08/2022
// Homework 4
// This file is an interface for the CollectionFactory class. The
// CollectionFactory class has a hashtable that is capable of generating
// Collectible objects that represent items that can be acted upon sold bought
// at a collectibles store
//-----------------------------------------------------------------------------
#pragma once
#include "Collectible.h"
#include "Coin.h"
#include "SportsCard.h"
#include "Comic.h"
#include <vector>
class CollectionFactory
{
private:
static const int FACTORY_SIZE = 26; // the number of collectibles possible
// for this factory. Cannot be less than
// 1
HashableObject** itemsFactory_; // hashtable filled with collectibles
//-------------------------- hashCollectible ------------------------------
// Takes a collectibles key and hashes it for quick access in the factory
// Preconditions : The key is the first char of the string and is between
// 'A' and 'Z'
// Postconditions: returns an integer hash of the collectibles key
int hashCollectible(std::string collectionType) const;
//-------------------------- validCollectibleHash --------------------------
// Returns a bool for if the hash is valid given the current collection
// factory
// Preconditions : The key has been hashed appropriately
// Postconditions: returns true if the index is between 0 and FACTORY_SIZE
// false otherwise
bool validCollectibleHash(int collectionIndex) const;
public:
//-------------------------- constructor -----------------------------------
// Fills the collection factory with the basic collectibles that it should
// be able to create
// Preconditions : the FACTORY_SIZE must be greater than 1
//
// Assumes no collisions -- meaning each collectible has a
// unique key
// Postconditions: The factory will be filled with collectibles through
// hashing
CollectionFactory();
//-------------------------- destructor -----------------------------------
// Frees the memory associated with the factory
// Preconditions : the hashable object frees its own dynamically allocated
// memory
// Postconditions: The hashtable is cleared of all the dynamic memory that
// is associated
~CollectionFactory();
//-------------------------- create ----------------------------------------
// Given a key a collectible pointer is returned containg this value. The
// value is a shell of a collectible from the factory
// PreConditions : The first element is the key associated with the
// collectible
// Postconditions: a constant Hashable object pointer is returned from a key
const Collectible* create(std::string key) const;
};