mirror-chatterino2/messages/limitedqueuesnapshot.h
2017-02-03 19:31:51 +01:00

49 lines
847 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