mirror-chatterino2/messages/limitedqueuesnapshot.h
2017-02-02 20:35:12 +01:00

49 lines
827 B
C++

#ifndef LIMITEDQUEUESNAPSHOT_H
#define LIMITEDQUEUESNAPSHOT_H
#include <cassert>
#include <memory>
#include <vector>
namespace chatterino {
namespace messages {
template <typename T>
class LimitedQueueSnapshot
{
public:
LimitedQueueSnapshot(std::shared_ptr<std::vector<T>> ptr, int offset,
int length)
: vectorPtr(ptr)
, vector(ptr.get())
, offset(offset)
, length(length)
{
}
int
getLength()
{
return length;
}
T const &operator[](int index) const
{
assert(index >= 0);
assert(index < length);
return vector->at(index + offset);
}
private:
std::shared_ptr<std::vector<T>> vectorPtr;
std::vector<T> *vector;
int offset;
int length;
};
}
}
#endif // LIMITEDQUEUESNAPSHOT_H