mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
6ea3a1df08
cstdint) Make MessageElement to a class to fit better with the derived classes. Make MessageLayoutElement to a class to fit better with the derived classes. Remove virtual from override functions Replace all instances of boost::signals2 with pajlada::Signals. This lets us properly use clang code model to check for issues. Add missing virtual destructor to AbstractIrcServer Add missing virtual destructor to MessageLayoutElement Remove unused "connectedConnection" connection in TwitchChannel Fix typo in TrimChannelName function Fix typo in MessageParseArgs Replace some raw pointers with unique pointers where it made more sense. This allowed us to remove some manually written destructors whose only purpose was to delete that raw pointer. Reformat: Add namespace comments Reformat: Add empty empty lines between main namespace beginning and end Reformat: Re-order includes Reformat: Fix some includes that used quotes where they should use angle brackets Reformat: Replace some typedef's with using's Filter out more useless warnings
60 lines
1.3 KiB
C++
60 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <cassert>
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
namespace chatterino {
|
|
namespace messages {
|
|
|
|
template <typename T>
|
|
class LimitedQueueSnapshot
|
|
{
|
|
public:
|
|
LimitedQueueSnapshot() = default;
|
|
|
|
LimitedQueueSnapshot(std::shared_ptr<std::vector<std::shared_ptr<std::vector<T>>>> _chunks,
|
|
size_t _length, size_t _firstChunkOffset, size_t _lastChunkEnd)
|
|
: chunks(_chunks)
|
|
, length(_length)
|
|
, firstChunkOffset(_firstChunkOffset)
|
|
, lastChunkEnd(_lastChunkEnd)
|
|
{
|
|
}
|
|
|
|
std::size_t getLength()
|
|
{
|
|
return this->length;
|
|
}
|
|
|
|
T const &operator[](std::size_t index) const
|
|
{
|
|
index += this->firstChunkOffset;
|
|
|
|
size_t x = 0;
|
|
|
|
for (size_t i = 0; i < this->chunks->size(); i++) {
|
|
auto &chunk = this->chunks->at(i);
|
|
|
|
if (x <= index && x + chunk->size() > index) {
|
|
return chunk->at(index - x);
|
|
}
|
|
x += chunk->size();
|
|
}
|
|
|
|
assert(false && "out of range");
|
|
|
|
return this->chunks->at(0)->at(0);
|
|
}
|
|
|
|
private:
|
|
std::shared_ptr<std::vector<std::shared_ptr<std::vector<T>>>> chunks;
|
|
|
|
size_t length = 0;
|
|
size_t firstChunkOffset = 0;
|
|
size_t lastChunkEnd = 0;
|
|
};
|
|
|
|
} // namespace messages
|
|
} // namespace chatterino
|