mirror of
https://github.com/jakcron/nstool
synced 2024-12-25 06:01:12 +00:00
[fnd] Added more operators and clear() to MemoryBlob.
This commit is contained in:
parent
7d8fb6e3a5
commit
f59068088d
2 changed files with 38 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -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]; }
|
||||
|
|
Loading…
Reference in a new issue