#ifndef WAREHOUSE_HPP #define WAREHOUSE_HPP // Since this is depended on in main.cpp this has to be here even though // Box.h is not directly used in this file :c #include "Box.h" #include #include /** * @brief takes in things and puts them into a list. stores all the items internally */ template class Warehouse { public: /** * @brief Construct a new Warehouse object with no items by default */ Warehouse(); /** * @brief Don't allow a Warehouse to be copied */ Warehouse(const Warehouse&) = delete; /** * @brief Don't allow a Warehouse to be copied */ Warehouse& operator=(const Warehouse&) = delete; /** * @brief Destroy the Warehouse object */ ~Warehouse(); /** * @brief puts the item into the warhouse * @param ITEM item to store */ void store(const T ITEM); /** * @brief Get the item at given position with the warehouse * @param ITEM_POS position to retrieve * @return T& corresponding item */ T& retrieve(const size_t ITEM_POS) const; /** * @brief Get the Number Of items * @return int */ size_t getNumberOfItems() const; /** * @brief retrieves the warehouse letter identifier * @return char warehouse letter identifier */ char getWarehouseLetter() const; /** * @brief sets the warehouse letter identifier * @param warehouseLetter letter to identify warehouse by */ void setWarehouseLetter(char warehouseLetter); private: /** * @brief holds a list of pointers to Boxes * */ std::vector* _pItems; /** * @brief Warehouse letter identifier */ char _warehouseLetter; }; template std::ostream& operator<<(std::ostream&, const Warehouse&); //---------------------------------------------------------------------------- template Warehouse::Warehouse() { _pItems = new std::vector; } template Warehouse::~Warehouse() { while( !_pItems->empty() ) { delete _pItems->back(); _pItems->pop_back(); } delete _pItems; } template void Warehouse::store(const T ITEM) { _pItems->push_back( new T(ITEM) ); } template T& Warehouse::retrieve(const size_t ITEM_POS) const { return *(_pItems->at(ITEM_POS)); } template size_t Warehouse::getNumberOfItems() const { return _pItems->size(); } template char Warehouse::getWarehouseLetter() const { return _warehouseLetter; } template void Warehouse::setWarehouseLetter(const char warehouseLetter) { _warehouseLetter = warehouseLetter; } template std::ostream& operator<<(std::ostream& os, const Warehouse& WH) { const size_t NUM_ITEMS = WH.getNumberOfItems(); os << "Warehouse " << WH.getWarehouseLetter() << " has " << NUM_ITEMS << " items ("; for(size_t i = 0; i < NUM_ITEMS; i++) { os << WH.retrieve(i); if(i < NUM_ITEMS - 1) { os << ", "; } } os << ")"; return os; } #endif//WAREHOUSE_HPP