/* */ #ifndef D_SEQUENTIAL_PICKER_H #define D_SEQUENTIAL_PICKER_H #include "common.h" #include #include namespace aria2 { template class SequentialPicker { private: std::deque> entries_; std::unique_ptr pickedEntry_; public: bool isPicked() const { return pickedEntry_.get(); } const std::unique_ptr& getPickedEntry() const { return pickedEntry_; } void dropPickedEntry() { pickedEntry_.reset(); } bool hasNext() const { return !entries_.empty(); } T* pickNext() { if (hasNext()) { pickedEntry_ = std::move(entries_.front()); entries_.pop_front(); return pickedEntry_.get(); } return nullptr; } void pushEntry(std::unique_ptr entry) { entries_.push_back(std::move(entry)); } size_t countEntryInQueue() const { return entries_.size(); } }; } // namespace aria2 #endif // D_SEQUENTIAL_PICKER_H