Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f9a57e5172 | |||
| b1d71993da | |||
| 1b32cd07f6 | |||
| 6788961ca0 |
@@ -1,34 +0,0 @@
|
||||
/*********************************************************************
|
||||
* \file Reference.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date July 2026
|
||||
*********************************************************************/
|
||||
#include <Engine/Asset/Reference.hpp>
|
||||
|
||||
#include <Engine/Asset/Reference_generated.hpp>
|
||||
|
||||
namespace flatbuffers
|
||||
{
|
||||
Flat::Bigfoot::AnyHardReference Pack(const ::Bigfoot::AnyHardReference& p_ref)
|
||||
{
|
||||
return {Pack(p_ref.GetUUID())};
|
||||
}
|
||||
|
||||
::Bigfoot::AnyHardReference UnPack(const Flat::Bigfoot::AnyHardReference& p_ref)
|
||||
{
|
||||
return {UnPack(p_ref.uuid())};
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
Flat::Bigfoot::AnySoftReference Pack(const ::Bigfoot::AnySoftReference& p_ref)
|
||||
{
|
||||
return {Pack(p_ref.GetUUID())};
|
||||
}
|
||||
|
||||
::Bigfoot::AnySoftReference UnPack(const Flat::Bigfoot::AnySoftReference& p_ref)
|
||||
{
|
||||
return {UnPack(p_ref.uuid())};
|
||||
}
|
||||
} // namespace flatbuffers
|
||||
@@ -65,7 +65,7 @@ class Asset: public AssetBase
|
||||
flatbuffers::GetRoot<FLAT_ASSET>(asset->inner_asset()->data())->UnPackTo(&m_asset, nullptr);
|
||||
}
|
||||
|
||||
Asset(const Asset& p_asset) = delete;
|
||||
Asset(const Asset& p_asset) = default;
|
||||
Asset(Asset&& p_asset) = default;
|
||||
|
||||
~Asset() = default;
|
||||
@@ -130,7 +130,7 @@ class Asset: public AssetBase
|
||||
return FLAT_ASSET::GetFullyQualifiedName();
|
||||
}
|
||||
|
||||
Asset& operator=(const Asset& p_asset) = delete;
|
||||
Asset& operator=(const Asset& p_asset) = default;
|
||||
Asset& operator=(Asset&& p_asset) = default;
|
||||
|
||||
private:
|
||||
|
||||
@@ -27,32 +27,69 @@ class ContainerHandle
|
||||
|
||||
~ContainerHandle() = default;
|
||||
|
||||
/*
|
||||
* Increment the HardRef count
|
||||
*
|
||||
*/
|
||||
void IncrementHardRefCount()
|
||||
{
|
||||
++m_hardRefCount;
|
||||
}
|
||||
|
||||
/*
|
||||
* Decrement the HardRef count
|
||||
*
|
||||
*/
|
||||
void DecrementHardRefCount()
|
||||
{
|
||||
--m_hardRefCount;
|
||||
}
|
||||
|
||||
/*
|
||||
* Increment the SoftRef count
|
||||
*
|
||||
*/
|
||||
void IncrementSoftRefCount()
|
||||
{
|
||||
++m_softRefCount;
|
||||
}
|
||||
|
||||
/*
|
||||
* Decrement the SoftRef count
|
||||
*
|
||||
*/
|
||||
void DecrementSoftRefCount()
|
||||
{
|
||||
--m_softRefCount;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the Asset
|
||||
*
|
||||
* \return The asset, can be nullptr
|
||||
*/
|
||||
[[nodiscard]]
|
||||
AssetBase* GetAsset() const
|
||||
AssetBase* GetAsset()
|
||||
{
|
||||
return m_asset;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the Asset
|
||||
*
|
||||
* \return The asset
|
||||
*/
|
||||
[[nodiscard]]
|
||||
const AssetBase* GetAsset() const
|
||||
{
|
||||
return m_asset;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the asset
|
||||
*
|
||||
* \param p_asset The asset
|
||||
*/
|
||||
void SetAsset(AssetBase* p_asset)
|
||||
{
|
||||
m_asset = p_asset;
|
||||
@@ -62,63 +99,162 @@ class ContainerHandle
|
||||
ContainerHandle& operator=(ContainerHandle&& p_handle) = default;
|
||||
|
||||
private:
|
||||
/*
|
||||
* The HardRef count
|
||||
*/
|
||||
std::uint32_t m_hardRefCount = 0;
|
||||
|
||||
/*
|
||||
* The SoftRef count
|
||||
*/
|
||||
std::uint32_t m_softRefCount = 0;
|
||||
|
||||
/*
|
||||
* The asset
|
||||
*/
|
||||
AssetBase* m_asset = nullptr;
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
class AssetContainerBase
|
||||
{
|
||||
public:
|
||||
virtual ~AssetContainerBase() = default;
|
||||
|
||||
[[nodiscard]]
|
||||
SlotMapKey GetAssetSlotKey(const UUID& p_uuid) const
|
||||
{
|
||||
if (const auto it = m_uuidToAssetSlotKey.find(p_uuid); it != m_uuidToAssetSlotKey.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
|
||||
return SlotMapKey {};
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if an Asset is in the AssetContainer or not
|
||||
*
|
||||
* \param p_uuid The UUID to check
|
||||
* \return True if in AssetContainer, false otherwise
|
||||
*/
|
||||
[[nodiscard]]
|
||||
bool Has(const UUID& p_uuid) const
|
||||
{
|
||||
return m_uuidToAssetSlotKey.contains(p_uuid);
|
||||
const Entry* entry = FindEntry(p_uuid);
|
||||
return entry != nullptr && entry->m_assetSlotKey.Valid();
|
||||
}
|
||||
|
||||
/*
|
||||
* Acquires a ContainerHandle for a given UUID
|
||||
* Will create it if it does not exists
|
||||
*
|
||||
* \param p_uuid The UUID to get ContainerHandle for
|
||||
* \return A ContainerHandle for the UUID
|
||||
*/
|
||||
[[nodiscard]]
|
||||
ContainerHandle& AcquireHandle(const UUID& p_uuid)
|
||||
ContainerHandle& AcquireContainerHandle(const UUID& p_uuid)
|
||||
{
|
||||
if (const auto it = m_uuidToContainerHandleSlotKey.find(p_uuid); it != m_uuidToContainerHandleSlotKey.end())
|
||||
{
|
||||
return *m_handles.Get(it->second);
|
||||
return *m_handles.Get(GetOrCreateEntry(p_uuid).m_handleSlotKey);
|
||||
}
|
||||
|
||||
const SlotMapKey key = m_handles.Insert();
|
||||
m_uuidToContainerHandleSlotKey.insert({p_uuid, key});
|
||||
|
||||
return *m_handles.Get(key);
|
||||
/*
|
||||
* Remove an Asset from the AssetContainer
|
||||
*
|
||||
* \param p_uuid The UUID to remove
|
||||
*/
|
||||
virtual void Remove(const UUID& p_uuid)
|
||||
{
|
||||
if (Entry* entry = FindEntry(p_uuid); entry != nullptr && entry->m_handleSlotKey.Valid())
|
||||
{
|
||||
m_handles.Remove(entry->m_handleSlotKey);
|
||||
m_uuidToEntry.erase(p_uuid);
|
||||
}
|
||||
}
|
||||
|
||||
AssetContainerBase& operator=(const AssetContainerBase& p_container) = delete;
|
||||
AssetContainerBase& operator=(AssetContainerBase&& p_container) = default;
|
||||
|
||||
protected:
|
||||
struct Entry
|
||||
{
|
||||
/*
|
||||
* SlotMapKey to the handle
|
||||
*/
|
||||
SlotMapKey m_handleSlotKey;
|
||||
|
||||
/*
|
||||
* SlotMapKey to the asset
|
||||
*/
|
||||
SlotMapKey m_assetSlotKey;
|
||||
};
|
||||
|
||||
AssetContainerBase() = default;
|
||||
|
||||
AssetContainerBase(const AssetContainerBase& p_container) = delete;
|
||||
AssetContainerBase(AssetContainerBase&& p_container) = default;
|
||||
|
||||
ankerl::unordered_dense::segmented_map<UUID, SlotMapKey> m_uuidToAssetSlotKey;
|
||||
ankerl::unordered_dense::segmented_map<UUID, SlotMapKey> m_uuidToContainerHandleSlotKey;
|
||||
/*
|
||||
* Finds an entry matching the Asset
|
||||
*
|
||||
* \param p_uuid The UUID to find
|
||||
* \return Pointer to an Entry, nullptr otherwise
|
||||
*/
|
||||
[[nodiscard]]
|
||||
Entry* FindEntry(const UUID& p_uuid)
|
||||
{
|
||||
const auto it = m_uuidToEntry.find(p_uuid);
|
||||
return it != m_uuidToEntry.end() ? &it->second : nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Finds an entry matching the Asset
|
||||
*
|
||||
* \param p_uuid The UUID to find
|
||||
* \return Pointer to an Entry, nullptr otherwise
|
||||
*/
|
||||
[[nodiscard]]
|
||||
const Entry* FindEntry(const UUID& p_uuid) const
|
||||
{
|
||||
const auto it = m_uuidToEntry.find(p_uuid);
|
||||
return it != m_uuidToEntry.end() ? &it->second : nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Finds an entry matching the Asset
|
||||
* Creates it if it does not exist
|
||||
*
|
||||
* \param p_uuid The UUID to find
|
||||
* \return The entry matching the Asset
|
||||
*/
|
||||
[[nodiscard]]
|
||||
Entry& GetOrCreateEntry(const UUID& p_uuid)
|
||||
{
|
||||
auto [it, inserted] = m_uuidToEntry.try_emplace(p_uuid);
|
||||
if (inserted)
|
||||
{
|
||||
it->second.m_handleSlotKey = m_handles.Insert();
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get a ContainerHandle
|
||||
*
|
||||
* \param p_handleSlotKey The key to the container
|
||||
* \return The container
|
||||
*/
|
||||
[[nodiscard]]
|
||||
ContainerHandle& FindContainerHandle(const SlotMapKey p_handleSlotKey)
|
||||
{
|
||||
return *m_handles.Get(p_handleSlotKey);
|
||||
}
|
||||
|
||||
private:
|
||||
/*
|
||||
* HandleContainers
|
||||
*/
|
||||
StableSlotMap<ContainerHandle> m_handles;
|
||||
|
||||
/*
|
||||
* Every Asset added to the map
|
||||
*/
|
||||
ankerl::unordered_dense::segmented_map<UUID, Entry> m_uuidToEntry;
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
template<class ASSET>
|
||||
class AssetContainer: public AssetContainerBase
|
||||
{
|
||||
@@ -130,45 +266,83 @@ class AssetContainer: public AssetContainerBase
|
||||
|
||||
~AssetContainer() = default;
|
||||
|
||||
/*
|
||||
* Inserts an Asset to the AssetContainer
|
||||
*
|
||||
* \tparam ARGS Arguments to construct the asset
|
||||
* \param p_args The arguments
|
||||
* \return The key to the inserted asset.
|
||||
*/
|
||||
template<class... ARGS>
|
||||
[[nodiscard]]
|
||||
SlotMapKey Insert(ARGS&&... p_args)
|
||||
{
|
||||
const SlotMapKey slotKey = m_assets.Insert(std::forward<ARGS>(p_args)...);
|
||||
SlotMapKey slotKey = m_assets.Insert(std::forward<ARGS>(p_args)...);
|
||||
ASSET* asset = m_assets.Get(slotKey);
|
||||
m_uuidToAssetSlotKey.insert({asset->GetHeader().uuid, slotKey});
|
||||
|
||||
AcquireHandle(asset->GetHeader().uuid).SetAsset(asset);
|
||||
Entry& entry = GetOrCreateEntry(asset->GetHeader().uuid);
|
||||
if (entry.m_assetSlotKey.Valid())
|
||||
{
|
||||
m_assets.Remove(slotKey);
|
||||
slotKey = entry.m_assetSlotKey;
|
||||
}
|
||||
else
|
||||
{
|
||||
entry.m_assetSlotKey = slotKey;
|
||||
FindContainerHandle(entry.m_handleSlotKey).SetAsset(asset);
|
||||
}
|
||||
|
||||
return slotKey;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the Asset
|
||||
*
|
||||
* \param p_key The key to the asset
|
||||
* \return Pointer to the Asset
|
||||
*/
|
||||
[[nodiscard]]
|
||||
ASSET* Get(const SlotMapKey p_key)
|
||||
{
|
||||
return m_assets.Get(p_key);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the Asset
|
||||
*
|
||||
* \param p_key The key to the asset
|
||||
* \return Pointer to the Asset
|
||||
*/
|
||||
[[nodiscard]]
|
||||
const ASSET* Get(const SlotMapKey p_key) const
|
||||
{
|
||||
return m_assets.Get(p_key);
|
||||
}
|
||||
|
||||
void Remove(const UUID& p_uuid)
|
||||
/*
|
||||
* Remove an Asset from the AssetContainer
|
||||
*
|
||||
* \param p_uuid The UUID to remove
|
||||
*/
|
||||
void Remove(const UUID& p_uuid) override
|
||||
{
|
||||
if (const auto it = m_uuidToAssetSlotKey.find(p_uuid); it != m_uuidToAssetSlotKey.end())
|
||||
if (Entry* entry = FindEntry(p_uuid); entry != nullptr && entry->m_assetSlotKey.Valid())
|
||||
{
|
||||
AcquireHandle(p_uuid).SetAsset(nullptr);
|
||||
m_assets.Remove(it->second);
|
||||
m_uuidToAssetSlotKey.erase(it->first);
|
||||
FindContainerHandle(entry->m_handleSlotKey).SetAsset(nullptr);
|
||||
m_assets.Remove(entry->m_assetSlotKey);
|
||||
entry->m_assetSlotKey = SlotMapKey {};
|
||||
}
|
||||
|
||||
AssetContainerBase::Remove(p_uuid);
|
||||
}
|
||||
|
||||
AssetContainer& operator=(const AssetContainer& p_container) = delete;
|
||||
AssetContainer& operator=(AssetContainer&& p_container) = default;
|
||||
|
||||
private:
|
||||
/*
|
||||
* The assets
|
||||
*/
|
||||
StableSlotMap<ASSET> m_assets;
|
||||
};
|
||||
} // namespace Bigfoot
|
||||
|
||||
@@ -23,6 +23,13 @@ class AssetLibrary
|
||||
|
||||
~AssetLibrary() = default;
|
||||
|
||||
/**
|
||||
* Insert an AssetContainer pointer to the library
|
||||
*
|
||||
* \tparam ASSET The Asset type
|
||||
* \param p_assetContainer The asset container
|
||||
* \return The AssetContainer for the Asset type. Nullptr if not found
|
||||
*/
|
||||
template<class ASSET>
|
||||
[[nodiscard]]
|
||||
bool Insert(AssetContainer<ASSET>* p_assetContainer)
|
||||
@@ -38,24 +45,42 @@ class AssetLibrary
|
||||
return inserted.second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the AssetContainer for a given Asset type
|
||||
*
|
||||
* \tparam ASSET The Asset type
|
||||
* \return The AssetContainer for the Asset type. Nullptr if not found
|
||||
*/
|
||||
template<class ASSET>
|
||||
[[nodiscard]]
|
||||
AssetContainer<ASSET>* Get()
|
||||
AssetContainer<ASSET>* GetAssetContainer()
|
||||
{
|
||||
static const AssetTypeID typeID = ASSET::GetTypeID();
|
||||
return static_cast<AssetContainer<ASSET>*>(GetBase(typeID));
|
||||
return static_cast<AssetContainer<ASSET>*>(GetAssetContainer(typeID));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the AssetContainer for a given Asset type
|
||||
*
|
||||
* \tparam ASSET The Asset type
|
||||
* \return The AssetContainer for the Asset type. Nullptr if not found
|
||||
*/
|
||||
template<class ASSET>
|
||||
[[nodiscard]]
|
||||
const AssetContainer<ASSET>* Get() const
|
||||
const AssetContainer<ASSET>* GetAssetContainer() const
|
||||
{
|
||||
static const AssetTypeID typeID = ASSET::GetTypeID();
|
||||
return static_cast<const AssetContainer<ASSET>*>(GetBase(typeID));
|
||||
return static_cast<const AssetContainer<ASSET>*>(GetAssetContainer(typeID));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the AssetContainer for a given AssetType
|
||||
*
|
||||
* \param p_typeID The asset type ID
|
||||
* \return The AssetContainer for the AssetType. Nullptr if not found
|
||||
*/
|
||||
[[nodiscard]]
|
||||
AssetContainerBase* GetBase(const AssetTypeID p_typeID)
|
||||
AssetContainerBase* GetAssetContainer(const AssetTypeID p_typeID)
|
||||
{
|
||||
if (const auto container = m_assetContainers.find(p_typeID); container != m_assetContainers.end())
|
||||
{
|
||||
@@ -65,8 +90,14 @@ class AssetLibrary
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the AssetContainer for a given AssetType
|
||||
*
|
||||
* \param p_typeID The asset type ID
|
||||
* \return The AssetContainer for the AssetType. Nullptr if not found
|
||||
*/
|
||||
[[nodiscard]]
|
||||
const AssetContainerBase* GetBase(const AssetTypeID p_typeID) const
|
||||
const AssetContainerBase* GetAssetContainer(const AssetTypeID p_typeID) const
|
||||
{
|
||||
if (const auto container = m_assetContainers.find(p_typeID); container != m_assetContainers.end())
|
||||
{
|
||||
@@ -76,12 +107,18 @@ class AssetLibrary
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find The associated container for a given UUID identifying an Asset
|
||||
*
|
||||
* \param p_uuid The UUID
|
||||
* \return The AssetContainer containing the asset. Nullptr if not found
|
||||
*/
|
||||
[[nodiscard]]
|
||||
AssetContainerBase* FindContainer(const UUID& p_uuid)
|
||||
AssetContainerBase* FindAssetContainerContainerForUUID(const UUID& p_uuid)
|
||||
{
|
||||
for (const auto& [typeID, container]: m_assetContainers)
|
||||
{
|
||||
if (container->GetAssetSlotKey(p_uuid).Valid())
|
||||
if (container->Has(p_uuid))
|
||||
{
|
||||
return container;
|
||||
}
|
||||
@@ -90,12 +127,18 @@ class AssetLibrary
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find The associated container for a given UUID identifying an Asset
|
||||
*
|
||||
* \param p_uuid The UUID
|
||||
* \return The AssetContainer containing the asset. Nullptr if not found
|
||||
*/
|
||||
[[nodiscard]]
|
||||
const AssetContainerBase* FindContainer(const UUID& p_uuid) const
|
||||
const AssetContainerBase* FindAssetContainerContainerForUUID(const UUID& p_uuid) const
|
||||
{
|
||||
for (const auto& [typeID, container]: m_assetContainers)
|
||||
{
|
||||
if (container->GetAssetSlotKey(p_uuid).Valid())
|
||||
if (container->Has(p_uuid))
|
||||
{
|
||||
return container;
|
||||
}
|
||||
@@ -108,10 +151,44 @@ class AssetLibrary
|
||||
AssetLibrary& operator=(AssetLibrary&& p_library) = default;
|
||||
|
||||
private:
|
||||
// All the asset containers
|
||||
ankerl::unordered_dense::segmented_map<AssetTypeID, AssetContainerBase*> m_assetContainers;
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
// The global asset library for Bigfoot
|
||||
inline AssetLibrary g_assetLibrary;
|
||||
inline AssetLibrary* g_activeAssetLibrary = &g_assetLibrary;
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
class ScopedActiveAssetLibrary
|
||||
{
|
||||
public:
|
||||
ScopedActiveAssetLibrary(AssetLibrary* p_assetLibrary):
|
||||
m_previous(g_activeAssetLibrary)
|
||||
{
|
||||
g_activeAssetLibrary = p_assetLibrary;
|
||||
}
|
||||
|
||||
ScopedActiveAssetLibrary(const ScopedActiveAssetLibrary& p_scopedActiveAssetLibrary) = default;
|
||||
ScopedActiveAssetLibrary(ScopedActiveAssetLibrary&& p_scopedActiveAssetLibrary) = default;
|
||||
|
||||
~ScopedActiveAssetLibrary()
|
||||
{
|
||||
g_activeAssetLibrary = m_previous;
|
||||
}
|
||||
|
||||
ScopedActiveAssetLibrary& operator=(const ScopedActiveAssetLibrary& p_scopedActiveAssetLibrary) = default;
|
||||
ScopedActiveAssetLibrary& operator=(ScopedActiveAssetLibrary&& p_scopedActiveAssetLibrary) = default;
|
||||
|
||||
private:
|
||||
/*
|
||||
* The previously active asset library.
|
||||
*/
|
||||
AssetLibrary* m_previous = nullptr;
|
||||
};
|
||||
} // namespace Bigfoot
|
||||
|
||||
#endif
|
||||
|
||||
@@ -13,13 +13,3 @@ struct SoftReference (bigfoot_ref_wrapper: "::Bigfoot::SoftReference")
|
||||
{
|
||||
uuid: UUID;
|
||||
}
|
||||
|
||||
struct AnyHardReference (native_type: "::Bigfoot::AnyHardReference")
|
||||
{
|
||||
uuid: UUID;
|
||||
}
|
||||
|
||||
struct AnySoftReference (native_type: "::Bigfoot::AnySoftReference")
|
||||
{
|
||||
uuid: UUID;
|
||||
}
|
||||
@@ -49,7 +49,13 @@ class HardReference
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ASSET* Get() const
|
||||
const ASSET* Get() const
|
||||
{
|
||||
return m_handle ? static_cast<const ASSET*>(m_handle->GetAsset()) : nullptr;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ASSET* Get()
|
||||
{
|
||||
return m_handle ? static_cast<ASSET*>(m_handle->GetAsset()) : nullptr;
|
||||
}
|
||||
@@ -91,14 +97,28 @@ class HardReference
|
||||
private:
|
||||
void Acquire()
|
||||
{
|
||||
if (AssetContainerBase* assetContainer = g_assetLibrary.GetBase(GetAssetTypeID<ASSET>());
|
||||
assetContainer && m_uuid)
|
||||
if (!m_uuid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AssetContainerBase* assetContainer = nullptr;
|
||||
if constexpr (std::is_same_v<ASSET, AssetBase>)
|
||||
{
|
||||
assetContainer = g_activeAssetLibrary->FindAssetContainerContainerForUUID(m_uuid);
|
||||
}
|
||||
else
|
||||
{
|
||||
assetContainer = g_activeAssetLibrary->GetAssetContainer(GetAssetTypeID<ASSET>());
|
||||
}
|
||||
|
||||
if (assetContainer)
|
||||
{
|
||||
if (!m_handle)
|
||||
{
|
||||
m_handle = &assetContainer->AcquireHandle(m_uuid);
|
||||
m_handle = &assetContainer->AcquireContainerHandle(m_uuid);
|
||||
}
|
||||
m_handle->IncrementHardRefCount();
|
||||
m_handle->IncrementSoftRefCount();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +167,13 @@ class SoftReference
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ASSET* Get() const
|
||||
const ASSET* Get() const
|
||||
{
|
||||
return m_handle ? static_cast<const ASSET*>(m_handle->GetAsset()) : nullptr;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ASSET* Get()
|
||||
{
|
||||
return m_handle ? static_cast<ASSET*>(m_handle->GetAsset()) : nullptr;
|
||||
}
|
||||
@@ -189,192 +215,26 @@ class SoftReference
|
||||
private:
|
||||
void Acquire()
|
||||
{
|
||||
if (AssetContainerBase* assetContainer = g_assetLibrary.GetBase(GetAssetTypeID<ASSET>());
|
||||
assetContainer && m_uuid)
|
||||
if (!m_uuid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AssetContainerBase* assetContainer = nullptr;
|
||||
if constexpr (std::is_same_v<ASSET, AssetBase>)
|
||||
{
|
||||
assetContainer = g_activeAssetLibrary->FindAssetContainerContainerForUUID(m_uuid);
|
||||
}
|
||||
else
|
||||
{
|
||||
assetContainer = g_activeAssetLibrary->GetAssetContainer(GetAssetTypeID<ASSET>());
|
||||
}
|
||||
|
||||
if (assetContainer)
|
||||
{
|
||||
if (!m_handle)
|
||||
{
|
||||
m_handle = &assetContainer->AcquireHandle(m_uuid);
|
||||
}
|
||||
m_handle->IncrementSoftRefCount();
|
||||
}
|
||||
}
|
||||
|
||||
void Release()
|
||||
{
|
||||
if (m_handle)
|
||||
{
|
||||
m_handle->DecrementSoftRefCount();
|
||||
m_handle = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
UUID m_uuid = UUID::NULL_UUID;
|
||||
ContainerHandle* m_handle = nullptr;
|
||||
};
|
||||
|
||||
class AnyHardReference
|
||||
{
|
||||
public:
|
||||
AnyHardReference() = default;
|
||||
|
||||
AnyHardReference(const UUID& p_uuid):
|
||||
m_uuid(p_uuid)
|
||||
{
|
||||
Acquire();
|
||||
}
|
||||
|
||||
AnyHardReference(const AnyHardReference& p_ref):
|
||||
m_uuid(p_ref.m_uuid),
|
||||
m_handle(p_ref.m_handle)
|
||||
{
|
||||
Acquire();
|
||||
}
|
||||
|
||||
AnyHardReference(AnyHardReference&& p_ref) noexcept:
|
||||
m_uuid(std::exchange(p_ref.m_uuid, UUID::NULL_UUID)),
|
||||
m_handle(std::exchange(p_ref.m_handle, nullptr))
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
const UUID& GetUUID() const
|
||||
{
|
||||
return m_uuid;
|
||||
}
|
||||
|
||||
~AnyHardReference()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
AnyHardReference& operator=(const AnyHardReference& p_ref)
|
||||
{
|
||||
if (this != &p_ref)
|
||||
{
|
||||
Release();
|
||||
m_uuid = p_ref.m_uuid;
|
||||
m_handle = p_ref.m_handle;
|
||||
Acquire();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
AnyHardReference& operator=(AnyHardReference&& p_ref) noexcept
|
||||
{
|
||||
if (this != &p_ref)
|
||||
{
|
||||
Release();
|
||||
m_uuid = std::exchange(p_ref.m_uuid, UUID::NULL_UUID);
|
||||
m_handle = std::exchange(p_ref.m_handle, nullptr);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool operator==(const AnyHardReference& p_ref) const
|
||||
{
|
||||
return m_uuid == p_ref.m_uuid;
|
||||
}
|
||||
|
||||
private:
|
||||
void Acquire()
|
||||
{
|
||||
if (AssetContainerBase* assetContainer = g_assetLibrary.FindContainer(m_uuid); assetContainer && m_uuid)
|
||||
{
|
||||
if (!m_handle)
|
||||
{
|
||||
m_handle = &assetContainer->AcquireHandle(m_uuid);
|
||||
}
|
||||
m_handle->IncrementHardRefCount();
|
||||
}
|
||||
}
|
||||
|
||||
void Release()
|
||||
{
|
||||
if (m_handle)
|
||||
{
|
||||
m_handle->DecrementHardRefCount();
|
||||
m_handle = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
UUID m_uuid = UUID::NULL_UUID;
|
||||
ContainerHandle* m_handle = nullptr;
|
||||
};
|
||||
|
||||
class AnySoftReference
|
||||
{
|
||||
public:
|
||||
AnySoftReference() = default;
|
||||
|
||||
AnySoftReference(const UUID& p_uuid):
|
||||
m_uuid(p_uuid)
|
||||
{
|
||||
Acquire();
|
||||
}
|
||||
|
||||
AnySoftReference(const AnySoftReference& p_ref):
|
||||
m_uuid(p_ref.m_uuid),
|
||||
m_handle(p_ref.m_handle)
|
||||
{
|
||||
Acquire();
|
||||
}
|
||||
|
||||
AnySoftReference(AnySoftReference&& p_ref) noexcept:
|
||||
m_uuid(std::exchange(p_ref.m_uuid, UUID::NULL_UUID)),
|
||||
m_handle(std::exchange(p_ref.m_handle, nullptr))
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
const UUID& GetUUID() const
|
||||
{
|
||||
return m_uuid;
|
||||
}
|
||||
|
||||
~AnySoftReference()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
AnySoftReference& operator=(const AnySoftReference& p_ref)
|
||||
{
|
||||
if (this != &p_ref)
|
||||
{
|
||||
Release();
|
||||
m_uuid = p_ref.m_uuid;
|
||||
m_handle = p_ref.m_handle;
|
||||
Acquire();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
AnySoftReference& operator=(AnySoftReference&& p_ref) noexcept
|
||||
{
|
||||
if (this != &p_ref)
|
||||
{
|
||||
Release();
|
||||
m_uuid = std::exchange(p_ref.m_uuid, UUID::NULL_UUID);
|
||||
m_handle = std::exchange(p_ref.m_handle, nullptr);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool operator==(const AnySoftReference& p_ref) const
|
||||
{
|
||||
return m_uuid == p_ref.m_uuid;
|
||||
}
|
||||
|
||||
private:
|
||||
void Acquire()
|
||||
{
|
||||
if (AssetContainerBase* assetContainer = g_assetLibrary.FindContainer(m_uuid); assetContainer && m_uuid)
|
||||
{
|
||||
if (!m_handle)
|
||||
{
|
||||
m_handle = &assetContainer->AcquireHandle(m_uuid);
|
||||
m_handle = &assetContainer->AcquireContainerHandle(m_uuid);
|
||||
}
|
||||
m_handle->IncrementSoftRefCount();
|
||||
}
|
||||
@@ -393,27 +253,4 @@ class AnySoftReference
|
||||
ContainerHandle* m_handle = nullptr;
|
||||
};
|
||||
} // namespace Bigfoot
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
namespace Flat
|
||||
{
|
||||
namespace Bigfoot
|
||||
{
|
||||
struct AnyHardReference;
|
||||
struct AnySoftReference;
|
||||
} // namespace Bigfoot
|
||||
} // namespace Flat
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
namespace flatbuffers
|
||||
{
|
||||
Flat::Bigfoot::AnyHardReference Pack(const ::Bigfoot::AnyHardReference& p_ref);
|
||||
::Bigfoot::AnyHardReference UnPack(const Flat::Bigfoot::AnyHardReference& p_ref);
|
||||
|
||||
Flat::Bigfoot::AnySoftReference Pack(const ::Bigfoot::AnySoftReference& p_ref);
|
||||
::Bigfoot::AnySoftReference UnPack(const Flat::Bigfoot::AnySoftReference& p_ref);
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif
|
||||
|
||||
@@ -35,18 +35,10 @@ struct HardReference;
|
||||
|
||||
struct SoftReference;
|
||||
|
||||
struct AnyHardReference;
|
||||
|
||||
struct AnySoftReference;
|
||||
|
||||
inline const ::flatbuffers::TypeTable *HardReferenceTypeTable();
|
||||
|
||||
inline const ::flatbuffers::TypeTable *SoftReferenceTypeTable();
|
||||
|
||||
inline const ::flatbuffers::TypeTable *AnyHardReferenceTypeTable();
|
||||
|
||||
inline const ::flatbuffers::TypeTable *AnySoftReferenceTypeTable();
|
||||
|
||||
FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) HardReference FLATBUFFERS_FINAL_CLASS {
|
||||
private:
|
||||
Flat::Bigfoot::UUID uuid_;
|
||||
@@ -103,62 +95,6 @@ struct SoftReference::Traits {
|
||||
using type = SoftReference;
|
||||
};
|
||||
|
||||
FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) AnyHardReference FLATBUFFERS_FINAL_CLASS {
|
||||
private:
|
||||
Flat::Bigfoot::UUID uuid_;
|
||||
|
||||
public:
|
||||
struct Traits;
|
||||
static const ::flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
return AnyHardReferenceTypeTable();
|
||||
}
|
||||
static FLATBUFFERS_CONSTEXPR_CPP11 const char *GetFullyQualifiedName() {
|
||||
return "Flat.Bigfoot.AnyHardReference";
|
||||
}
|
||||
AnyHardReference()
|
||||
: uuid_() {
|
||||
}
|
||||
AnyHardReference(const Flat::Bigfoot::UUID &_uuid)
|
||||
: uuid_(_uuid) {
|
||||
}
|
||||
const Flat::Bigfoot::UUID &uuid() const {
|
||||
return uuid_;
|
||||
}
|
||||
};
|
||||
FLATBUFFERS_STRUCT_END(AnyHardReference, 16);
|
||||
|
||||
struct AnyHardReference::Traits {
|
||||
using type = AnyHardReference;
|
||||
};
|
||||
|
||||
FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) AnySoftReference FLATBUFFERS_FINAL_CLASS {
|
||||
private:
|
||||
Flat::Bigfoot::UUID uuid_;
|
||||
|
||||
public:
|
||||
struct Traits;
|
||||
static const ::flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
return AnySoftReferenceTypeTable();
|
||||
}
|
||||
static FLATBUFFERS_CONSTEXPR_CPP11 const char *GetFullyQualifiedName() {
|
||||
return "Flat.Bigfoot.AnySoftReference";
|
||||
}
|
||||
AnySoftReference()
|
||||
: uuid_() {
|
||||
}
|
||||
AnySoftReference(const Flat::Bigfoot::UUID &_uuid)
|
||||
: uuid_(_uuid) {
|
||||
}
|
||||
const Flat::Bigfoot::UUID &uuid() const {
|
||||
return uuid_;
|
||||
}
|
||||
};
|
||||
FLATBUFFERS_STRUCT_END(AnySoftReference, 16);
|
||||
|
||||
struct AnySoftReference::Traits {
|
||||
using type = AnySoftReference;
|
||||
};
|
||||
|
||||
inline const ::flatbuffers::TypeTable *HardReferenceTypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_SEQUENCE, 0, 0 }
|
||||
@@ -187,34 +123,6 @@ inline const ::flatbuffers::TypeTable *SoftReferenceTypeTable() {
|
||||
return &tt;
|
||||
}
|
||||
|
||||
inline const ::flatbuffers::TypeTable *AnyHardReferenceTypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_SEQUENCE, 0, 0 }
|
||||
};
|
||||
static const ::flatbuffers::TypeFunction type_refs[] = {
|
||||
Flat::Bigfoot::UUIDTypeTable
|
||||
};
|
||||
static const int64_t values[] = { 0, 16 };
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_STRUCT, 1, type_codes, type_refs, nullptr, values, nullptr
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
inline const ::flatbuffers::TypeTable *AnySoftReferenceTypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_SEQUENCE, 0, 0 }
|
||||
};
|
||||
static const ::flatbuffers::TypeFunction type_refs[] = {
|
||||
Flat::Bigfoot::UUIDTypeTable
|
||||
};
|
||||
static const int64_t values[] = { 0, 16 };
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_STRUCT, 1, type_codes, type_refs, nullptr, values, nullptr
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
} // namespace Bigfoot
|
||||
} // namespace Flat
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ class SlotMapBase
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
std::size_t GetSize() const
|
||||
std::size_t Size() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
/*********************************************************************
|
||||
* \file AssetContainer.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date July 2026
|
||||
*********************************************************************/
|
||||
#include <Engine/Asset/AssetContainer.hpp>
|
||||
|
||||
#include <AssetsForTesting/Asset/AssetA.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class AssetContainerFixture: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
AssetContainer<AssetA> m_containerA;
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(AssetContainerFixture, Has_ShouldReturnTrueIfTheContainerHasTheAsset)
|
||||
{
|
||||
AssetA asset1;
|
||||
std::ignore = m_containerA.Insert(asset1);
|
||||
EXPECT_TRUE(m_containerA.Has(asset1.GetHeader().uuid));
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(AssetContainerFixture, Has_ShouldReturnFalseIfTheContainerDoesNotHaveTheAsset)
|
||||
{
|
||||
AssetA asset1;
|
||||
EXPECT_FALSE(m_containerA.Has(asset1.GetHeader().uuid));
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(AssetContainerFixture, AcquireHandle_ShouldReturnTheAssociatedContainerHandle)
|
||||
{
|
||||
AssetA asset1;
|
||||
std::ignore = m_containerA.Insert(asset1);
|
||||
|
||||
const ContainerHandle& handle = m_containerA.AcquireContainerHandle(asset1.GetHeader().uuid);
|
||||
EXPECT_EQ(static_cast<const AssetA*>(handle.GetAsset())->GetHeader().uuid, asset1.GetHeader().uuid);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(AssetContainerFixture, AcquireHandle_ShouldCreateTheAssociatedContainerHandleIfItDoesNotExists)
|
||||
{
|
||||
AssetA asset1;
|
||||
|
||||
const ContainerHandle& handle = m_containerA.AcquireContainerHandle(asset1.GetHeader().uuid);
|
||||
EXPECT_EQ(handle.GetAsset(), nullptr);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(AssetContainerFixture, Insert_ShouldReturnValidAndUniqueSlotKeyOnInsert)
|
||||
{
|
||||
AssetA asset1;
|
||||
const SlotMapKey slotKey = m_containerA.Insert(asset1);
|
||||
EXPECT_TRUE(slotKey.Valid());
|
||||
EXPECT_NE(slotKey, m_containerA.Insert());
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(AssetContainerFixture, Insert_ShouldReturnTheSameSlotKeyInCaseOfDuplicatedUUID)
|
||||
{
|
||||
AssetA asset;
|
||||
const SlotMapKey slotKey = m_containerA.Insert(asset);
|
||||
EXPECT_EQ(slotKey, m_containerA.Insert(asset));
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(AssetContainerFixture, Get_ShouldReturnTheAssetWithTheSlotKey)
|
||||
{
|
||||
AssetA asset;
|
||||
const SlotMapKey slotKey = m_containerA.Insert(asset);
|
||||
|
||||
EXPECT_EQ(m_containerA.Get(slotKey)->GetHeader().uuid, asset.GetHeader().uuid);
|
||||
EXPECT_EQ(const_cast<const AssetContainer<AssetA>&>(m_containerA).Get(slotKey)->GetHeader().uuid,
|
||||
asset.GetHeader().uuid);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(AssetContainerFixture, Get_ShouldReturnNullptrIfSlotKeyNotInContainer)
|
||||
{
|
||||
EXPECT_EQ(m_containerA.Get(SlotMapKey {1, 0}), nullptr);
|
||||
EXPECT_EQ(const_cast<const AssetContainer<AssetA>&>(m_containerA).Get(SlotMapKey {1, 0}), nullptr);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(AssetContainerFixture, Remove_ShouldRemoveTheAsset)
|
||||
{
|
||||
AssetA asset;
|
||||
const SlotMapKey slotKey = m_containerA.Insert(asset);
|
||||
|
||||
m_containerA.Remove(asset.GetHeader().uuid);
|
||||
|
||||
EXPECT_EQ(m_containerA.Get(slotKey), nullptr);
|
||||
EXPECT_FALSE(m_containerA.Has(asset.GetHeader().uuid));
|
||||
}
|
||||
} // namespace Bigfoot
|
||||
@@ -0,0 +1,135 @@
|
||||
/*********************************************************************
|
||||
* \file AssetLibrary.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date July 2026
|
||||
*********************************************************************/
|
||||
#include <Engine/Asset/AssetLibrary.hpp>
|
||||
|
||||
#include <AssetsForTesting/Asset/AssetA.hpp>
|
||||
#include <AssetsForTesting/Asset/AssetB.hpp>
|
||||
#include <AssetsForTesting/Asset/AssetC.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class AssetLibraryFixture: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
AssetContainer<AssetA> m_containerA;
|
||||
AssetContainer<AssetB> m_containerB;
|
||||
AssetContainer<AssetC> m_containerC;
|
||||
|
||||
AssetLibrary m_library;
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(AssetLibraryFixture, Insert_ShouldReturnTrueOnSuccess)
|
||||
{
|
||||
EXPECT_TRUE(m_library.Insert(&m_containerA));
|
||||
EXPECT_TRUE(m_library.Insert(&m_containerB));
|
||||
EXPECT_TRUE(m_library.Insert(&m_containerC));
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(AssetLibraryFixture, Insert_ShouldReturnFalseOnDuplicate)
|
||||
{
|
||||
std::ignore = m_library.Insert(&m_containerA);
|
||||
EXPECT_FALSE(m_library.Insert(&m_containerA));
|
||||
|
||||
AssetContainer<AssetA> m_containerAA;
|
||||
EXPECT_FALSE(m_library.Insert(&m_containerAA));
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(AssetLibraryFixture, GetAssetContainer_ShouldReturnTheAssetContainerIfAvailable)
|
||||
{
|
||||
std::ignore = m_library.Insert(&m_containerA);
|
||||
std::ignore = m_library.Insert(&m_containerB);
|
||||
std::ignore = m_library.Insert(&m_containerC);
|
||||
|
||||
EXPECT_EQ(m_library.GetAssetContainer<AssetA>(), &m_containerA);
|
||||
EXPECT_EQ(m_library.GetAssetContainer(GetAssetTypeID<AssetA>()), &m_containerA);
|
||||
EXPECT_EQ(m_library.GetAssetContainer<AssetB>(), &m_containerB);
|
||||
EXPECT_EQ(m_library.GetAssetContainer(GetAssetTypeID<AssetB>()), &m_containerB);
|
||||
EXPECT_EQ(m_library.GetAssetContainer<AssetC>(), &m_containerC);
|
||||
EXPECT_EQ(m_library.GetAssetContainer(GetAssetTypeID<AssetC>()), &m_containerC);
|
||||
|
||||
EXPECT_EQ(const_cast<const AssetLibrary&>(m_library).GetAssetContainer<AssetA>(), &m_containerA);
|
||||
EXPECT_EQ(const_cast<const AssetLibrary&>(m_library).GetAssetContainer(GetAssetTypeID<AssetA>()), &m_containerA);
|
||||
EXPECT_EQ(const_cast<const AssetLibrary&>(m_library).GetAssetContainer<AssetB>(), &m_containerB);
|
||||
EXPECT_EQ(const_cast<const AssetLibrary&>(m_library).GetAssetContainer(GetAssetTypeID<AssetB>()), &m_containerB);
|
||||
EXPECT_EQ(const_cast<const AssetLibrary&>(m_library).GetAssetContainer<AssetC>(), &m_containerC);
|
||||
EXPECT_EQ(const_cast<const AssetLibrary&>(m_library).GetAssetContainer(GetAssetTypeID<AssetC>()), &m_containerC);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(AssetLibraryFixture, GetAssetContainer_ShouldReturnNullptrIfTheContainerDoesNotExist)
|
||||
{
|
||||
std::ignore = m_library.Insert(&m_containerB);
|
||||
|
||||
EXPECT_EQ(m_library.GetAssetContainer<AssetA>(), nullptr);
|
||||
EXPECT_EQ(m_library.GetAssetContainer(GetAssetTypeID<AssetA>()), nullptr);
|
||||
|
||||
EXPECT_EQ(const_cast<const AssetLibrary&>(m_library).GetAssetContainer<AssetA>(), nullptr);
|
||||
EXPECT_EQ(const_cast<const AssetLibrary&>(m_library).GetAssetContainer(GetAssetTypeID<AssetA>()), nullptr);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(AssetLibraryFixture, FindAssetContainerContainerForUUID_ShouldReturnTheAssetContainerIfAvailable)
|
||||
{
|
||||
std::ignore = m_library.Insert(&m_containerA);
|
||||
std::ignore = m_library.Insert(&m_containerB);
|
||||
std::ignore = m_library.Insert(&m_containerC);
|
||||
|
||||
const SlotMapKey keyA = m_containerA.Insert();
|
||||
const SlotMapKey keyB = m_containerB.Insert();
|
||||
const SlotMapKey keyC = m_containerC.Insert();
|
||||
|
||||
const UUID uuidA = m_containerA.Get(keyA)->GetHeader().uuid;
|
||||
const UUID uuidB = m_containerB.Get(keyB)->GetHeader().uuid;
|
||||
const UUID uuidC = m_containerC.Get(keyC)->GetHeader().uuid;
|
||||
|
||||
EXPECT_EQ(m_library.FindAssetContainerContainerForUUID(uuidA), &m_containerA);
|
||||
EXPECT_EQ(m_library.FindAssetContainerContainerForUUID(uuidB), &m_containerB);
|
||||
EXPECT_EQ(m_library.FindAssetContainerContainerForUUID(uuidC), &m_containerC);
|
||||
|
||||
EXPECT_EQ(const_cast<const AssetLibrary&>(m_library).FindAssetContainerContainerForUUID(uuidA), &m_containerA);
|
||||
EXPECT_EQ(const_cast<const AssetLibrary&>(m_library).FindAssetContainerContainerForUUID(uuidB), &m_containerB);
|
||||
EXPECT_EQ(const_cast<const AssetLibrary&>(m_library).FindAssetContainerContainerForUUID(uuidC), &m_containerC);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(AssetLibraryFixture, FindAssetContainerContainerForUUID_ShouldReturnNullptrIfTheContainerDoesNotExist)
|
||||
{
|
||||
std::ignore = m_library.Insert(&m_containerA);
|
||||
std::ignore = m_library.Insert(&m_containerB);
|
||||
std::ignore = m_library.Insert(&m_containerC);
|
||||
|
||||
std::ignore = m_containerA.Insert();
|
||||
std::ignore = m_containerB.Insert();
|
||||
std::ignore = m_containerC.Insert();
|
||||
|
||||
EXPECT_EQ(m_library.FindAssetContainerContainerForUUID(UUID {}), nullptr);
|
||||
|
||||
EXPECT_EQ(const_cast<const AssetLibrary&>(m_library).FindAssetContainerContainerForUUID(UUID {}), nullptr);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(AssetLibraryFixture, ScopedActiveAssetLibrary_ShouldChangeTheActiveAssetLibraryInAScopedWay)
|
||||
{
|
||||
EXPECT_EQ(g_activeAssetLibrary, &g_assetLibrary);
|
||||
{
|
||||
ScopedActiveAssetLibrary activeAssetLibraryScoped {&m_library};
|
||||
EXPECT_EQ(g_activeAssetLibrary, &m_library);
|
||||
}
|
||||
EXPECT_EQ(g_activeAssetLibrary, &g_assetLibrary);
|
||||
}
|
||||
} // namespace Bigfoot
|
||||
@@ -27,12 +27,12 @@ class AssetA: public Asset<AssetATraits>
|
||||
{
|
||||
}
|
||||
|
||||
AssetA(const AssetA& p_asset) = delete;
|
||||
AssetA(const AssetA& p_asset) = default;
|
||||
AssetA(AssetA&& p_asset) = default;
|
||||
|
||||
~AssetA() = default;
|
||||
|
||||
AssetA& operator=(const AssetA& p_asset) = delete;
|
||||
AssetA& operator=(const AssetA& p_asset) = default;
|
||||
AssetA& operator=(AssetA&& p_asset) = default;
|
||||
};
|
||||
} // namespace Bigfoot
|
||||
|
||||
@@ -7,8 +7,8 @@ table InnerTable
|
||||
asset_a_ref: HardReference (native_inline, bigfoot_ref: "::Bigfoot::AssetA");
|
||||
asset_a_refs: [HardReference] (native_inline, bigfoot_ref: "::Bigfoot::AssetA");
|
||||
|
||||
any_asset: AnyHardReference (native_inline);
|
||||
any_assets: [AnySoftReference] (native_inline);
|
||||
any_asset: HardReference (native_inline, bigfoot_ref: "::Bigfoot::AssetBase");
|
||||
any_assets: [SoftReference] (native_inline, bigfoot_ref: "::Bigfoot::AssetBase");
|
||||
}
|
||||
|
||||
table AssetC
|
||||
|
||||
+36
-19
@@ -46,6 +46,10 @@ namespace Bigfoot {
|
||||
class AssetA;
|
||||
} // namespace Bigfoot
|
||||
|
||||
namespace Bigfoot {
|
||||
class AssetBase;
|
||||
} // namespace Bigfoot
|
||||
|
||||
namespace Bigfoot {
|
||||
class AssetB;
|
||||
} // namespace Bigfoot
|
||||
@@ -53,6 +57,10 @@ class AssetB;
|
||||
namespace flatbuffers {
|
||||
Flat::Bigfoot::HardReference PackHardReferenceAssetA(const ::Bigfoot::HardReference<::Bigfoot::AssetA>& p_asset);
|
||||
::Bigfoot::HardReference<::Bigfoot::AssetA> UnPackHardReferenceAssetA(const Flat::Bigfoot::HardReference& p_asset);
|
||||
Flat::Bigfoot::HardReference PackHardReferenceAssetBase(const ::Bigfoot::HardReference<::Bigfoot::AssetBase>& p_asset);
|
||||
::Bigfoot::HardReference<::Bigfoot::AssetBase> UnPackHardReferenceAssetBase(const Flat::Bigfoot::HardReference& p_asset);
|
||||
Flat::Bigfoot::SoftReference PackSoftReferenceAssetBase(const ::Bigfoot::SoftReference<::Bigfoot::AssetBase>& p_asset);
|
||||
::Bigfoot::SoftReference<::Bigfoot::AssetBase> UnPackSoftReferenceAssetBase(const Flat::Bigfoot::SoftReference& p_asset);
|
||||
Flat::Bigfoot::HardReference PackHardReferenceAssetB(const ::Bigfoot::HardReference<::Bigfoot::AssetB>& p_asset);
|
||||
::Bigfoot::HardReference<::Bigfoot::AssetB> UnPackHardReferenceAssetB(const Flat::Bigfoot::HardReference& p_asset);
|
||||
Flat::Bigfoot::SoftReference PackSoftReferenceAssetB(const ::Bigfoot::SoftReference<::Bigfoot::AssetB>& p_asset);
|
||||
@@ -73,8 +81,8 @@ struct InnerTableT : public ::flatbuffers::NativeTable {
|
||||
}
|
||||
::Bigfoot::HardReference<::Bigfoot::AssetA> asset_a_ref{};
|
||||
eastl::vector<::Bigfoot::HardReference<::Bigfoot::AssetA>> asset_a_refs{};
|
||||
::Bigfoot::AnyHardReference any_asset{};
|
||||
eastl::vector<::Bigfoot::AnySoftReference> any_assets{};
|
||||
::Bigfoot::HardReference<::Bigfoot::AssetBase> any_asset{};
|
||||
eastl::vector<::Bigfoot::SoftReference<::Bigfoot::AssetBase>> any_assets{};
|
||||
};
|
||||
|
||||
struct InnerTable FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
@@ -99,11 +107,11 @@ struct InnerTable FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
const ::flatbuffers::Vector<const Flat::Bigfoot::HardReference *> *asset_a_refs() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<const Flat::Bigfoot::HardReference *> *>(VT_ASSET_A_REFS);
|
||||
}
|
||||
const Flat::Bigfoot::AnyHardReference *any_asset() const {
|
||||
return GetStruct<const Flat::Bigfoot::AnyHardReference *>(VT_ANY_ASSET);
|
||||
const Flat::Bigfoot::HardReference *any_asset() const {
|
||||
return GetStruct<const Flat::Bigfoot::HardReference *>(VT_ANY_ASSET);
|
||||
}
|
||||
const ::flatbuffers::Vector<const Flat::Bigfoot::AnySoftReference *> *any_assets() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<const Flat::Bigfoot::AnySoftReference *> *>(VT_ANY_ASSETS);
|
||||
const ::flatbuffers::Vector<const Flat::Bigfoot::SoftReference *> *any_assets() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<const Flat::Bigfoot::SoftReference *> *>(VT_ANY_ASSETS);
|
||||
}
|
||||
template <bool B = false>
|
||||
bool Verify(::flatbuffers::VerifierTemplate<B> &verifier) const {
|
||||
@@ -111,7 +119,7 @@ struct InnerTable FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
VerifyField<Flat::Bigfoot::HardReference>(verifier, VT_ASSET_A_REF, 1) &&
|
||||
VerifyOffset(verifier, VT_ASSET_A_REFS) &&
|
||||
verifier.VerifyVector(asset_a_refs()) &&
|
||||
VerifyField<Flat::Bigfoot::AnyHardReference>(verifier, VT_ANY_ASSET, 1) &&
|
||||
VerifyField<Flat::Bigfoot::HardReference>(verifier, VT_ANY_ASSET, 1) &&
|
||||
VerifyOffset(verifier, VT_ANY_ASSETS) &&
|
||||
verifier.VerifyVector(any_assets()) &&
|
||||
verifier.EndTable();
|
||||
@@ -131,10 +139,10 @@ struct InnerTableBuilder {
|
||||
void add_asset_a_refs(::flatbuffers::Offset<::flatbuffers::Vector<const Flat::Bigfoot::HardReference *>> asset_a_refs) {
|
||||
fbb_.AddOffset(InnerTable::VT_ASSET_A_REFS, asset_a_refs);
|
||||
}
|
||||
void add_any_asset(const Flat::Bigfoot::AnyHardReference *any_asset) {
|
||||
void add_any_asset(const Flat::Bigfoot::HardReference *any_asset) {
|
||||
fbb_.AddStruct(InnerTable::VT_ANY_ASSET, any_asset);
|
||||
}
|
||||
void add_any_assets(::flatbuffers::Offset<::flatbuffers::Vector<const Flat::Bigfoot::AnySoftReference *>> any_assets) {
|
||||
void add_any_assets(::flatbuffers::Offset<::flatbuffers::Vector<const Flat::Bigfoot::SoftReference *>> any_assets) {
|
||||
fbb_.AddOffset(InnerTable::VT_ANY_ASSETS, any_assets);
|
||||
}
|
||||
explicit InnerTableBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
@@ -152,8 +160,8 @@ inline ::flatbuffers::Offset<InnerTable> CreateInnerTable(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
const Flat::Bigfoot::HardReference *asset_a_ref = nullptr,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<const Flat::Bigfoot::HardReference *>> asset_a_refs = 0,
|
||||
const Flat::Bigfoot::AnyHardReference *any_asset = nullptr,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<const Flat::Bigfoot::AnySoftReference *>> any_assets = 0) {
|
||||
const Flat::Bigfoot::HardReference *any_asset = nullptr,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<const Flat::Bigfoot::SoftReference *>> any_assets = 0) {
|
||||
InnerTableBuilder builder_(_fbb);
|
||||
builder_.add_any_assets(any_assets);
|
||||
builder_.add_any_asset(any_asset);
|
||||
@@ -277,8 +285,8 @@ inline void InnerTable::UnPackTo(InnerTableT *_o, const ::flatbuffers::resolver_
|
||||
(void)_resolver;
|
||||
{ auto _e = asset_a_ref(); if (_e) _o->asset_a_ref = ::flatbuffers::UnPackHardReferenceAssetA(*_e); }
|
||||
{ auto _e = asset_a_refs(); if (_e) { _o->asset_a_refs.resize(_e->size()); for (::flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->asset_a_refs[_i] = ::flatbuffers::UnPackHardReferenceAssetA(*_e->Get(_i)); } } else { _o->asset_a_refs.resize(0); } }
|
||||
{ auto _e = any_asset(); if (_e) _o->any_asset = ::flatbuffers::UnPack(*_e); }
|
||||
{ auto _e = any_assets(); if (_e) { _o->any_assets.resize(_e->size()); for (::flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->any_assets[_i] = ::flatbuffers::UnPack(*_e->Get(_i)); } } else { _o->any_assets.resize(0); } }
|
||||
{ auto _e = any_asset(); if (_e) _o->any_asset = ::flatbuffers::UnPackHardReferenceAssetBase(*_e); }
|
||||
{ auto _e = any_assets(); if (_e) { _o->any_assets.resize(_e->size()); for (::flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->any_assets[_i] = ::flatbuffers::UnPackSoftReferenceAssetBase(*_e->Get(_i)); } } else { _o->any_assets.resize(0); } }
|
||||
}
|
||||
|
||||
inline ::flatbuffers::Offset<InnerTable> CreateInnerTable(::flatbuffers::FlatBufferBuilder &_fbb, const InnerTableT *_o, const ::flatbuffers::rehasher_function_t *_rehasher) {
|
||||
@@ -291,8 +299,8 @@ inline ::flatbuffers::Offset<InnerTable> InnerTable::Pack(::flatbuffers::FlatBuf
|
||||
struct _VectorArgs { ::flatbuffers::FlatBufferBuilder *__fbb; const InnerTableT* __o; const ::flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va;
|
||||
auto _asset_a_ref = ::flatbuffers::PackHardReferenceAssetA(_o->asset_a_ref);
|
||||
auto _asset_a_refs = _fbb.CreateVectorOfNativeStructs<Flat::Bigfoot::HardReference, ::Bigfoot::HardReference<::Bigfoot::AssetA>>(_o->asset_a_refs.data(), _o->asset_a_refs.size(), ::flatbuffers::PackHardReferenceAssetA);
|
||||
auto _any_asset = ::flatbuffers::Pack(_o->any_asset);
|
||||
auto _any_assets = _fbb.CreateVectorOfNativeStructs<Flat::Bigfoot::AnySoftReference, ::Bigfoot::AnySoftReference>(_o->any_assets.data(), _o->any_assets.size());
|
||||
auto _any_asset = ::flatbuffers::PackHardReferenceAssetBase(_o->any_asset);
|
||||
auto _any_assets = _fbb.CreateVectorOfNativeStructs<Flat::Bigfoot::SoftReference, ::Bigfoot::SoftReference<::Bigfoot::AssetBase>>(_o->any_assets.data(), _o->any_assets.size(), ::flatbuffers::PackSoftReferenceAssetBase);
|
||||
return Flat::Bigfoot::CreateInnerTable(
|
||||
_fbb,
|
||||
&_asset_a_ref,
|
||||
@@ -350,13 +358,12 @@ inline const ::flatbuffers::TypeTable *InnerTableTypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_SEQUENCE, 0, 0 },
|
||||
{ ::flatbuffers::ET_SEQUENCE, 1, 0 },
|
||||
{ ::flatbuffers::ET_SEQUENCE, 0, 1 },
|
||||
{ ::flatbuffers::ET_SEQUENCE, 1, 2 }
|
||||
{ ::flatbuffers::ET_SEQUENCE, 0, 0 },
|
||||
{ ::flatbuffers::ET_SEQUENCE, 1, 1 }
|
||||
};
|
||||
static const ::flatbuffers::TypeFunction type_refs[] = {
|
||||
Flat::Bigfoot::HardReferenceTypeTable,
|
||||
Flat::Bigfoot::AnyHardReferenceTypeTable,
|
||||
Flat::Bigfoot::AnySoftReferenceTypeTable
|
||||
Flat::Bigfoot::SoftReferenceTypeTable
|
||||
};
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_TABLE, 4, type_codes, type_refs, nullptr, nullptr, nullptr
|
||||
@@ -438,6 +445,16 @@ namespace flatbuffers {
|
||||
inline Flat::Bigfoot::HardReference PackHardReferenceAssetA(const ::Bigfoot::HardReference<::Bigfoot::AssetA>& p_asset) { return {Pack(p_asset.GetUUID())}; }
|
||||
inline ::Bigfoot::HardReference<::Bigfoot::AssetA> UnPackHardReferenceAssetA(const Flat::Bigfoot::HardReference& p_asset) { return {UnPack(p_asset.uuid())}; }
|
||||
#endif // FLATBUFFERS_BIGFOOT_REF_HARDREFERENCEASSETA
|
||||
#ifndef FLATBUFFERS_BIGFOOT_REF_HARDREFERENCEASSETBASE
|
||||
#define FLATBUFFERS_BIGFOOT_REF_HARDREFERENCEASSETBASE
|
||||
inline Flat::Bigfoot::HardReference PackHardReferenceAssetBase(const ::Bigfoot::HardReference<::Bigfoot::AssetBase>& p_asset) { return {Pack(p_asset.GetUUID())}; }
|
||||
inline ::Bigfoot::HardReference<::Bigfoot::AssetBase> UnPackHardReferenceAssetBase(const Flat::Bigfoot::HardReference& p_asset) { return {UnPack(p_asset.uuid())}; }
|
||||
#endif // FLATBUFFERS_BIGFOOT_REF_HARDREFERENCEASSETBASE
|
||||
#ifndef FLATBUFFERS_BIGFOOT_REF_SOFTREFERENCEASSETBASE
|
||||
#define FLATBUFFERS_BIGFOOT_REF_SOFTREFERENCEASSETBASE
|
||||
inline Flat::Bigfoot::SoftReference PackSoftReferenceAssetBase(const ::Bigfoot::SoftReference<::Bigfoot::AssetBase>& p_asset) { return {Pack(p_asset.GetUUID())}; }
|
||||
inline ::Bigfoot::SoftReference<::Bigfoot::AssetBase> UnPackSoftReferenceAssetBase(const Flat::Bigfoot::SoftReference& p_asset) { return {UnPack(p_asset.uuid())}; }
|
||||
#endif // FLATBUFFERS_BIGFOOT_REF_SOFTREFERENCEASSETBASE
|
||||
#ifndef FLATBUFFERS_BIGFOOT_REF_HARDREFERENCEASSETB
|
||||
#define FLATBUFFERS_BIGFOOT_REF_HARDREFERENCEASSETB
|
||||
inline Flat::Bigfoot::HardReference PackHardReferenceAssetB(const ::Bigfoot::HardReference<::Bigfoot::AssetB>& p_asset) { return {Pack(p_asset.GetUUID())}; }
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
/*********************************************************************
|
||||
* \file SlotMap.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date August 2026
|
||||
*********************************************************************/
|
||||
#include <Utils/Containers/SlotMap.hpp>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class SlotMapKeyFixture: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(SlotMapKeyFixture, INVALID_VERSION_IsZero)
|
||||
{
|
||||
EXPECT_EQ(SlotMapKey::INVALID_VERSION, 0);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(SlotMapKeyFixture, MAX_INDEX_IsMaxU32)
|
||||
{
|
||||
EXPECT_EQ(SlotMapKey::MAX_INDEX, std::numeric_limits<std::uint32_t>::max());
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(SlotMapKeyFixture, Valid_ShouldReturnFalseIfVersionIsInvalid)
|
||||
{
|
||||
EXPECT_FALSE(SlotMapKey().Valid());
|
||||
EXPECT_FALSE(SlotMapKey(0, 0).Valid());
|
||||
EXPECT_FALSE(SlotMapKey(SlotMapKey::INVALID_VERSION, 0).Valid());
|
||||
EXPECT_FALSE(SlotMapKey(0, 42).Valid());
|
||||
EXPECT_FALSE(SlotMapKey(SlotMapKey::INVALID_VERSION, 42).Valid());
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(SlotMapKeyFixture, Valid_ShouldReturnTrueIfVersionisNotInvalid)
|
||||
{
|
||||
EXPECT_TRUE(SlotMapKey(1, 0).Valid());
|
||||
EXPECT_TRUE(SlotMapKey(1, 42).Valid());
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(SlotMapKeyFixture, GetVersion_ShouldReturnTheVersion)
|
||||
{
|
||||
EXPECT_EQ(SlotMapKey(0, 0).GetVersion(), 0);
|
||||
EXPECT_EQ(SlotMapKey(42, 69).GetVersion(), 42);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(SlotMapKeyFixture, GetIndex_ShouldReturnTheIndex)
|
||||
{
|
||||
EXPECT_EQ(SlotMapKey(0, 0).GetIndex(), 0);
|
||||
EXPECT_EQ(SlotMapKey(42, 69).GetIndex(), 69);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
template<class SLOTMAP>
|
||||
class SlotMapFixture: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
SLOTMAP m_slotMap;
|
||||
};
|
||||
|
||||
class SlotMapNameGenerator
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
static std::string GetName(int)
|
||||
{
|
||||
if constexpr (std::is_same_v<T, DenseSlotMap<std::uint32_t>>)
|
||||
{
|
||||
return "DenseSlotMap";
|
||||
}
|
||||
if constexpr (std::is_same_v<T, StableSlotMap<std::uint32_t>>)
|
||||
{
|
||||
return "StableSlotMap";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
using SlotMapTypes = ::testing::Types<DenseSlotMap<std::uint32_t>, StableSlotMap<std::uint32_t>>;
|
||||
TYPED_TEST_SUITE(SlotMapFixture, SlotMapTypes, SlotMapNameGenerator);
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TYPED_TEST(SlotMapFixture, Has_ReturnTrueIfSlotMapHasTheKey)
|
||||
{
|
||||
const SlotMapKey key = this->m_slotMap.Insert(42);
|
||||
EXPECT_TRUE(this->m_slotMap.Has(key));
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TYPED_TEST(SlotMapFixture, Has_ReturnFalseIfSlotMapDoesNotHaveTheKey)
|
||||
{
|
||||
std::ignore = this->m_slotMap.Insert(42);
|
||||
EXPECT_FALSE(this->m_slotMap.Has(SlotMapKey {1, 23}));
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TYPED_TEST(SlotMapFixture, Size_ShouldReturnTheSizeOfTheSlotMap)
|
||||
{
|
||||
EXPECT_EQ(this->m_slotMap.Size(), 0);
|
||||
const SlotMapKey key1 = this->m_slotMap.Insert(42);
|
||||
const SlotMapKey key2 = this->m_slotMap.Insert(69);
|
||||
EXPECT_EQ(this->m_slotMap.Size(), 2);
|
||||
this->m_slotMap.Remove(key1);
|
||||
EXPECT_EQ(this->m_slotMap.Size(), 1);
|
||||
this->m_slotMap.Remove(key2);
|
||||
EXPECT_EQ(this->m_slotMap.Size(), 0);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TYPED_TEST(SlotMapFixture, Empty_ShouldReturnTrueIfTheSlotMapIsEmpty)
|
||||
{
|
||||
EXPECT_TRUE(this->m_slotMap.Empty());
|
||||
const SlotMapKey key1 = this->m_slotMap.Insert(42);
|
||||
const SlotMapKey key2 = this->m_slotMap.Insert(69);
|
||||
this->m_slotMap.Remove(key1);
|
||||
this->m_slotMap.Remove(key2);
|
||||
EXPECT_TRUE(this->m_slotMap.Empty());
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TYPED_TEST(SlotMapFixture, Empty_ShouldReturnFalseIfTheSlotMapIsNotEmpty)
|
||||
{
|
||||
const SlotMapKey key1 = this->m_slotMap.Insert(42);
|
||||
EXPECT_FALSE(this->m_slotMap.Empty());
|
||||
const SlotMapKey key2 = this->m_slotMap.Insert(69);
|
||||
EXPECT_FALSE(this->m_slotMap.Empty());
|
||||
this->m_slotMap.Remove(key1);
|
||||
EXPECT_FALSE(this->m_slotMap.Empty());
|
||||
this->m_slotMap.Remove(key2);
|
||||
}
|
||||
} // namespace Bigfoot
|
||||
Reference in New Issue
Block a user