mirror of
https://github.com/thunderbrewhq/common.git
synced 2025-12-12 03:02:29 +00:00
feat(datastore): add dtor for CDataStoreCache
This commit is contained in:
parent
7536dd706c
commit
467c0366e1
2 changed files with 33 additions and 0 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "common/datastore/CDataStore.hpp"
|
#include "common/datastore/CDataStore.hpp"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <storm/Memory.hpp>
|
||||||
|
|
||||||
template <size_t size>
|
template <size_t size>
|
||||||
class CDataStoreCache : public CDataStore {
|
class CDataStoreCache : public CDataStore {
|
||||||
|
|
@ -12,17 +13,42 @@ class CDataStoreCache : public CDataStore {
|
||||||
|
|
||||||
// Virtual member functions
|
// Virtual member functions
|
||||||
virtual void InternalInitialize(uint8_t*& data, uint32_t& base, uint32_t& alloc);
|
virtual void InternalInitialize(uint8_t*& data, uint32_t& base, uint32_t& alloc);
|
||||||
|
virtual void InternalDestroy(uint8_t*& data, uint32_t& base, uint32_t& alloc);
|
||||||
|
virtual ~CDataStoreCache();
|
||||||
|
|
||||||
// Member functions
|
// Member functions
|
||||||
CDataStoreCache() {
|
CDataStoreCache() {
|
||||||
this->InternalInitialize(this->m_data, this->m_base, this->m_alloc);
|
this->InternalInitialize(this->m_data, this->m_base, this->m_alloc);
|
||||||
}
|
}
|
||||||
|
void Destroy();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <size_t size>
|
||||||
|
CDataStoreCache<size>::~CDataStoreCache() {
|
||||||
|
this->Destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t size>
|
||||||
|
void CDataStoreCache<size>::Destroy() {
|
||||||
|
if (this->m_alloc != -1) {
|
||||||
|
this->InternalDestroy(this->m_data, this->m_base, this->m_alloc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <size_t size>
|
template <size_t size>
|
||||||
void CDataStoreCache<size>::InternalInitialize(uint8_t*& data, uint32_t& base, uint32_t& alloc) {
|
void CDataStoreCache<size>::InternalInitialize(uint8_t*& data, uint32_t& base, uint32_t& alloc) {
|
||||||
data = this->m_cache;
|
data = this->m_cache;
|
||||||
alloc = size;
|
alloc = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <size_t size>
|
||||||
|
void CDataStoreCache<size>::InternalDestroy(uint8_t*& data, uint32_t& base, uint32_t& alloc) {
|
||||||
|
if (data && data != this->m_cache) {
|
||||||
|
SMemFree(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
data = nullptr;
|
||||||
|
alloc = 0;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -136,3 +136,10 @@ TEST_CASE("CDataStore::Size", "[datastore]") {
|
||||||
REQUIRE(msg.Size() == 3);
|
REQUIRE(msg.Size() == 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("CDataStoreCache<1024>::CDataStoreCache<1024>", "[datastore]") {
|
||||||
|
SECTION("constructs new data store") {
|
||||||
|
CDataStoreCache<1024> msg;
|
||||||
|
SUCCEED();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue