Added ResizeablePointer::shift operator to shift data forward in buffer

This commit is contained in:
Thulinma 2022-08-17 14:57:29 +02:00
parent 6c117b63cf
commit df4076a06e
2 changed files with 12 additions and 0 deletions

View file

@ -191,6 +191,17 @@ namespace Util{
maxSize = 0;
}
void ResizeablePointer::shift(size_t byteCount){
//Shifting the entire buffer is easy, we do nothing and set size to zero
if (byteCount >= currSize){
currSize = 0;
return;
}
//Shifting partial needs a memmove and size change
memmove(ptr, ((char*)ptr)+byteCount, currSize-byteCount);
currSize -= byteCount;
}
bool ResizeablePointer::assign(const void *p, uint32_t l){
if (!allocate(l)){return false;}
memcpy(ptr, p, l);

View file

@ -45,6 +45,7 @@ namespace Util{
bool append(const void *p, uint32_t l);
bool append(const std::string &str);
bool allocate(uint32_t l);
void shift(size_t byteCount);
uint32_t rsize();
void truncate(const size_t newLen);
inline operator char *(){return (char *)ptr;}