/* */ #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::shared_ptr pickedEntry_; public: bool isPicked() const { return pickedEntry_.get(); } const std::shared_ptr& getPickedEntry() const { return pickedEntry_; } void dropPickedEntry() { pickedEntry_.reset(); } bool hasNext() const { return !entries_.empty(); } std::shared_ptr pickNext() { std::shared_ptr r; if(hasNext()) { r = entries_.front(); entries_.pop_front(); pickedEntry_ = r; } return r; } void pushEntry(const std::shared_ptr& entry) { entries_.push_back(entry); } size_t countEntryInQueue() const { return entries_.size(); } }; } // namespace aria2 #endif // D_SEQUENTIAL_PICKER_H