#ifndef STORM_HASH_TS_EXPORT_TABLE_SIMPLE_REUSE_HPP #define STORM_HASH_TS_EXPORT_TABLE_SIMPLE_REUSE_HPP #include "storm/hash/Hashkey.hpp" #include "storm/hash/TSHashTableReuse.hpp" template class TSExportTableSimpleReuse : public TSHashTableReuse { public: // Virtual member functions virtual ~TSExportTableSimpleReuse() = default; // Member functions void Delete(T* ptr); T* New(THandle* handlePtr); T* Ptr(THandle handle); private: // Member variables HASHKEY_NONE m_key; uint32_t m_sequence = ~reinterpret_cast(this) & 0xFFFFFFF; int32_t m_wrapped = 0; // Member functions THandle GenerateUniqueHandle(); }; template void TSExportTableSimpleReuse::Delete(T* ptr) { TSHashTable::Delete(ptr); } template THandle TSExportTableSimpleReuse::GenerateUniqueHandle() { while (true) { while (true) { this->m_sequence += 1; if (this->m_sequence) { break; } this->m_wrapped = 1; } if (!this->m_wrapped || !this->Ptr(reinterpret_cast(this->m_sequence))) { break; } } return reinterpret_cast(this->m_sequence); } template T* TSExportTableSimpleReuse::New(THandle* handlePtr) { auto handle = this->GenerateUniqueHandle(); *handlePtr = handle; auto hashval = static_cast(reinterpret_cast(handle)); return this->TSHashTable::New(hashval, this->m_key, 0, 0x0); } template T* TSExportTableSimpleReuse::Ptr(THandle handle) { auto hashval = static_cast(reinterpret_cast(handle)); return this->TSHashTable::Ptr(hashval, this->m_key); } #endif