92 lines
1.2 KiB
C++
92 lines
1.2 KiB
C++
|
//
|
||
|
// Created by kyle on 2023-10-09.
|
||
|
//
|
||
|
|
||
|
#include <cstring>
|
||
|
#include "Buffer.h"
|
||
|
|
||
|
namespace kge {
|
||
|
uint8_t *
|
||
|
Buffer::Contents()
|
||
|
{
|
||
|
return this->contents;
|
||
|
}
|
||
|
|
||
|
bool
|
||
|
Buffer::Append(uint8_t *data, size_t datalen)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
bool
|
||
|
Buffer::Append(uint8_t c)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
bool
|
||
|
Buffer::Insert(size_t index, uint8_t *data, size_t datalen)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
bool
|
||
|
Buffer::Insert(size_t index, uint8_t c)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
size_t
|
||
|
Buffer::Size()
|
||
|
{
|
||
|
return this->length;
|
||
|
}
|
||
|
|
||
|
void
|
||
|
Buffer::Resize(size_t newCapacity)
|
||
|
{
|
||
|
if (newCapacity < this->length) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
uint8_t *newContents = new uint8_t[newCapacity];
|
||
|
|
||
|
memcpy(newContents, this->contents, this->length);
|
||
|
delete this->contents;
|
||
|
this->contents = newContents;
|
||
|
this->capacity = newCapacity;
|
||
|
}
|
||
|
|
||
|
size_t
|
||
|
Buffer::Trim()
|
||
|
{
|
||
|
size_t projectedCapacity = this->capacity * 2;
|
||
|
|
||
|
if (projectedCapacity < this->capacity) {
|
||
|
this->Resize(projectedCapacity);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void
|
||
|
Buffer::Clear()
|
||
|
{
|
||
|
memset(this->contents, 0, this->length);
|
||
|
this->length = 0;
|
||
|
}
|
||
|
|
||
|
void
|
||
|
Buffer::Reclaim()
|
||
|
{
|
||
|
delete this->contents;
|
||
|
this->length = 0;
|
||
|
this->capacity = 0;
|
||
|
}
|
||
|
|
||
|
bool
|
||
|
Buffer::mustGrow(size_t newLength)
|
||
|
{
|
||
|
return (newLength + this->length) >= this->capacity;
|
||
|
}
|
||
|
|
||
|
|
||
|
} // kge
|