[fnd] Added more operators and clear() to MemoryBlob.

This commit is contained in:
jakcron 2017-07-06 20:48:06 +10:00
parent 7d8fb6e3a5
commit f59068088d
2 changed files with 38 additions and 0 deletions

View file

@ -19,6 +19,34 @@ fnd::MemoryBlob::MemoryBlob(const byte_t * bytes, size_t len) :
memcpy(getBytes(), bytes, getSize());
}
bool fnd::MemoryBlob::operator==(const MemoryBlob & other) const
{
bool isEqual = true;
if (this->getSize() == other.getSize())
{
isEqual = memcmp(this->getBytes(), other.getBytes(), this->getSize()) == 0;
}
else
{
isEqual = false;
}
return isEqual;
}
bool fnd::MemoryBlob::operator!=(const MemoryBlob & other) const
{
return !operator==(other);
}
void fnd::MemoryBlob::operator=(const MemoryBlob & other)
{
alloc(other.getSize());
memcpy(getBytes(), other.getBytes(), getSize());
}
void MemoryBlob::alloc(size_t size)
{
if (size > mSize)
@ -42,6 +70,11 @@ void MemoryBlob::extend(size_t new_size)
}
}
void fnd::MemoryBlob::clear()
{
mVisableSize = 0;
}
void MemoryBlob::allocateMemory(size_t size)
{
mSize = (size_t)align(size, kAllocBlockSize);

View file

@ -14,8 +14,13 @@ namespace fnd
MemoryBlob();
MemoryBlob(const byte_t* bytes, size_t len);
bool operator==(const MemoryBlob& other) const;
bool operator!=(const MemoryBlob& other) const;
void operator=(const MemoryBlob& other);
void alloc(size_t size);
void extend(size_t new_size);
void clear();
inline byte_t& operator[](size_t index) { return mData[index]; }
inline const byte_t& operator[](size_t index) const { return mData[index]; }