mirror-chatterino2/src/messages/LimitedQueueSnapshot.hpp

63 lines
963 B
C++
Raw Normal View History

#pragma once
2017-02-02 20:35:12 +01: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 {
template <typename T>
class LimitedQueue;
2017-02-02 20:35:12 +01:00
template <typename T>
class LimitedQueueSnapshot
{
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:
LimitedQueueSnapshot() = default;
size_t size() const
2017-02-02 20:35:12 +01:00
{
return this->buffer_.size();
2017-02-02 20:35:12 +01:00
}
const T &operator[](size_t index) const
2017-02-02 20:35:12 +01:00
{
return this->buffer_[index];
2017-02-02 20:35:12 +01:00
}
auto begin() const
2017-02-02 20:35:12 +01:00
{
return this->buffer_.begin();
}
auto end() const
{
return this->buffer_.end();
}
auto rbegin() const
{
return this->buffer_.rbegin();
}
auto rend() const
{
return this->buffer_.rend();
2017-02-02 20:35:12 +01:00
}
private:
std::vector<T> buffer_;
2017-02-02 20:35:12 +01:00
};
2017-04-14 17:52:22 +02:00
} // namespace chatterino