Finish basic buffer implementation.
This commit is contained in:
21
Buffer.h
21
Buffer.h
@@ -14,19 +14,24 @@ namespace klib {
|
||||
class Buffer {
|
||||
public:
|
||||
Buffer();
|
||||
Buffer(size_t);
|
||||
Buffer(const char *);
|
||||
explicit Buffer(size_t);
|
||||
explicit Buffer(const char *);
|
||||
~Buffer() { this->Reclaim(); }
|
||||
|
||||
uint8_t *Contents() { return this->contents; }
|
||||
size_t Size() { return this->length; };
|
||||
size_t Capacity() { return this->capacity; }
|
||||
size_t Length() const { return this->length; };
|
||||
size_t Capacity() const { return this->capacity; }
|
||||
|
||||
bool Append(const char *s);
|
||||
bool Append(uint8_t *data, size_t datalen);
|
||||
bool Append(uint8_t c);
|
||||
|
||||
bool Insert(size_t index, const char *s);
|
||||
bool Insert(size_t index, uint8_t *data, size_t datalen);
|
||||
bool Insert(size_t index, uint8_t c);
|
||||
|
||||
// bool Remove(size_t index, size_t length);
|
||||
bool Remove(size_t index, size_t count);
|
||||
bool Remove(size_t index); // remove single char
|
||||
|
||||
/* memory management */
|
||||
void Resize(size_t newCapacity);
|
||||
@@ -34,15 +39,19 @@ public:
|
||||
void Clear();
|
||||
void Reclaim();
|
||||
|
||||
uint8_t &operator[](size_t index);
|
||||
private:
|
||||
size_t mustGrow(size_t delta);
|
||||
bool shift(size_t offset, size_t delta);
|
||||
bool shiftRight(size_t offset, size_t delta);
|
||||
bool shiftLeft(size_t offset, size_t delta);
|
||||
|
||||
uint8_t *contents;
|
||||
size_t length;
|
||||
size_t capacity;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace klib
|
||||
|
||||
#endif //KGE_BUFFER_H
|
||||
|
||||
Reference in New Issue
Block a user