From f59068088d09c65272f7bfd43afc01462c725c9f Mon Sep 17 00:00:00 2001 From: jakcron Date: Thu, 6 Jul 2017 20:48:06 +1000 Subject: [PATCH] [fnd] Added more operators and clear() to MemoryBlob. --- lib/fnd/memory_blob.cpp | 33 +++++++++++++++++++++++++++++++++ lib/fnd/memory_blob.h | 5 +++++ 2 files changed, 38 insertions(+) diff --git a/lib/fnd/memory_blob.cpp b/lib/fnd/memory_blob.cpp index 8e7f4b6..33b817e 100644 --- a/lib/fnd/memory_blob.cpp +++ b/lib/fnd/memory_blob.cpp @@ -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); diff --git a/lib/fnd/memory_blob.h b/lib/fnd/memory_blob.h index 1b9abae..465f257 100644 --- a/lib/fnd/memory_blob.h +++ b/lib/fnd/memory_blob.h @@ -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]; }