2017-06-07 10:09:24 +02:00
|
|
|
#pragma once
|
2017-02-02 20:35:12 +01:00
|
|
|
|
2022-06-18 12:44:48 +02:00
|
|
|
#include <boost/circular_buffer.hpp>
|
|
|
|
|
2018-01-05 13:42:23 +01:00
|
|
|
#include <cassert>
|
2017-02-02 20:35:12 +01:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
2022-06-18 12:44:48 +02:00
|
|
|
template <typename T>
|
|
|
|
class LimitedQueue;
|
|
|
|
|
2017-02-02 20:35:12 +01:00
|
|
|
template <typename T>
|
|
|
|
class LimitedQueueSnapshot
|
|
|
|
{
|
2022-06-18 12:44:48 +02:00
|
|
|
private:
|
|
|
|
friend class LimitedQueue<T>;
|
|
|
|
|
|
|
|
LimitedQueueSnapshot(const boost::circular_buffer<T> &buf)
|
|
|
|
: buffer_(buf.begin(), buf.end())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-02-02 20:35:12 +01:00
|
|
|
public:
|
2018-04-03 02:55:32 +02:00
|
|
|
LimitedQueueSnapshot() = default;
|
2018-01-05 11:22:51 +01:00
|
|
|
|
2022-06-18 12:44:48 +02:00
|
|
|
size_t size() const
|
2017-02-02 20:35:12 +01:00
|
|
|
{
|
2022-06-18 12:44:48 +02:00
|
|
|
return this->buffer_.size();
|
2017-02-02 20:35:12 +01:00
|
|
|
}
|
|
|
|
|
2022-06-18 12:44:48 +02:00
|
|
|
const T &operator[](size_t index) const
|
2017-02-02 20:35:12 +01:00
|
|
|
{
|
2022-06-18 12:44:48 +02:00
|
|
|
return this->buffer_[index];
|
2017-02-02 20:35:12 +01:00
|
|
|
}
|
|
|
|
|
2022-06-18 12:44:48 +02:00
|
|
|
auto begin() const
|
2017-02-02 20:35:12 +01:00
|
|
|
{
|
2022-06-18 12:44:48 +02:00
|
|
|
return this->buffer_.begin();
|
|
|
|
}
|
2018-01-01 22:29:21 +01:00
|
|
|
|
2022-06-18 12:44:48 +02:00
|
|
|
auto end() const
|
|
|
|
{
|
|
|
|
return this->buffer_.end();
|
|
|
|
}
|
2018-01-01 22:29:21 +01:00
|
|
|
|
2022-06-18 12:44:48 +02:00
|
|
|
auto rbegin() const
|
|
|
|
{
|
|
|
|
return this->buffer_.rbegin();
|
|
|
|
}
|
2018-01-01 22:29:21 +01:00
|
|
|
|
2022-06-18 12:44:48 +02:00
|
|
|
auto rend() const
|
|
|
|
{
|
|
|
|
return this->buffer_.rend();
|
2017-02-02 20:35:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2022-06-18 12:44:48 +02:00
|
|
|
std::vector<T> buffer_;
|
2017-02-02 20:35:12 +01:00
|
|
|
};
|
2017-06-07 10:09:24 +02:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace chatterino
|