Added ResizeablePointer::shift operator to shift data forward in buffer
This commit is contained in:
parent
6c117b63cf
commit
df4076a06e
2 changed files with 12 additions and 0 deletions
11
lib/util.cpp
11
lib/util.cpp
|
@ -191,6 +191,17 @@ namespace Util{
|
||||||
maxSize = 0;
|
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){
|
bool ResizeablePointer::assign(const void *p, uint32_t l){
|
||||||
if (!allocate(l)){return false;}
|
if (!allocate(l)){return false;}
|
||||||
memcpy(ptr, p, l);
|
memcpy(ptr, p, l);
|
||||||
|
|
|
@ -45,6 +45,7 @@ namespace Util{
|
||||||
bool append(const void *p, uint32_t l);
|
bool append(const void *p, uint32_t l);
|
||||||
bool append(const std::string &str);
|
bool append(const std::string &str);
|
||||||
bool allocate(uint32_t l);
|
bool allocate(uint32_t l);
|
||||||
|
void shift(size_t byteCount);
|
||||||
uint32_t rsize();
|
uint32_t rsize();
|
||||||
void truncate(const size_t newLen);
|
void truncate(const size_t newLen);
|
||||||
inline operator char *(){return (char *)ptr;}
|
inline operator char *(){return (char *)ptr;}
|
||||||
|
|
Loading…
Add table
Reference in a new issue