/// @copyright 2020 ECCI, Universidad de Costa Rica. All rights reserved /// This code is released under the GNU Public License version 3 /// @author Jeisson Hidalgo-Céspedes #ifndef PRODUCER_HPP #define PRODUCER_HPP #include #include "Queue.hpp" #include "Thread.hpp" /** * @brief A template that generates abstract base classes for Producers * Producers are execution threads. They create elements that are pushed * to a queue. These elements will be popped by a consumer thread. */ template class Producer : public Thread { DISABLE_COPY(Producer); protected: /// This thread will produce for this queue Queue* queue; public: /// Constructor explicit Producer(Queue* queue = nullptr) : queue(queue) { } /// Destructor virtual ~Producer() { } /// Set the queue where this thread will produce elements inline void setQueue(Queue* queue) { this->queue = queue; } /// Add to the queue the produced data unit virtual void produce(const DataType& data) { assert(this->queue); this->queue->push(data); } }; #endif // PRODUCER_HPP