Testing AssetLibrary
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 6m16s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 5m41s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 6m7s
Bigfoot / Build & Test Debug with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Successful in 6m8s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 6m30s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 6m24s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 7m20s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Successful in 7m20s
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: OFF) (push) Successful in 6m12s
Bigfoot / Build & Test Release with ./ConanProfiles/clang (Unity Build: ON) (push) Successful in 6m8s
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: OFF) (push) Successful in 7m7s
Bigfoot / Build & Test Release with ./ConanProfiles/clang_asan (Unity Build: ON) (push) Successful in 6m52s
Bigfoot / Clang Format Checks (push) Successful in 1m40s

This commit is contained in:
2026-08-02 22:42:21 +02:00
parent b2220d981f
commit 6788961ca0
16 changed files with 346 additions and 376 deletions
@@ -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:
@@ -48,7 +48,13 @@ class ContainerHandle
}
[[nodiscard]]
AssetBase* GetAsset() const
AssetBase* GetAsset()
{
return m_asset;
}
[[nodiscard]]
const AssetBase* GetAsset() const
{
return m_asset;
}
@@ -67,6 +73,8 @@ class ContainerHandle
AssetBase* m_asset = nullptr;
};
/****************************************************************************************/
class AssetContainerBase
{
public:
@@ -98,7 +106,7 @@ class AssetContainerBase
}
const SlotMapKey key = m_handles.Insert();
m_uuidToContainerHandleSlotKey.insert({p_uuid, key});
m_uuidToContainerHandleSlotKey.emplace(p_uuid, key);
return *m_handles.Get(key);
}
@@ -119,6 +127,8 @@ class AssetContainerBase
StableSlotMap<ContainerHandle> m_handles;
};
/****************************************************************************************/
template<class ASSET>
class AssetContainer: public AssetContainerBase
{
@@ -134,11 +144,19 @@ class AssetContainer: public AssetContainerBase
[[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);
if (const auto it = m_uuidToAssetSlotKey.find(asset->GetHeader().uuid); it != m_uuidToAssetSlotKey.end())
{
m_assets.Remove(slotKey);
slotKey = it->second;
}
else
{
m_uuidToAssetSlotKey.emplace(asset->GetHeader().uuid, slotKey);
AcquireHandle(asset->GetHeader().uuid).SetAsset(asset);
}
return slotKey;
}
@@ -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,8 +107,14 @@ 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)
{
@@ -90,8 +127,14 @@ 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)
{
@@ -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
@@ -10,16 +10,6 @@ struct HardReference (bigfoot_ref_wrapper: "::Bigfoot::HardReference")
}
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->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,188 +215,22 @@ class SoftReference
private:
void Acquire()
{
if (AssetContainerBase* assetContainer = g_assetLibrary.GetBase(GetAssetTypeID<ASSET>());
assetContainer && m_uuid)
if (!m_uuid)
{
if (!m_handle)
{
m_handle = &assetContainer->AcquireHandle(m_uuid);
}
m_handle->IncrementSoftRefCount();
return;
}
}
void Release()
{
if (m_handle)
AssetContainerBase* assetContainer = nullptr;
if constexpr (std::is_same_v<ASSET, AssetBase>)
{
m_handle->DecrementSoftRefCount();
m_handle = nullptr;
assetContainer = g_activeAssetLibrary->FindAssetContainerContainerForUUID(m_uuid);
}
}
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)
else
{
Release();
m_uuid = p_ref.m_uuid;
m_handle = p_ref.m_handle;
Acquire();
assetContainer = g_activeAssetLibrary->GetAssetContainer(GetAssetTypeID<ASSET>());
}
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 (assetContainer)
{
if (!m_handle)
{
@@ -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
@@ -0,0 +1,22 @@
/*********************************************************************
* \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;
};
/****************************************************************************************/
} // namespace Bigfoot
+135
View File
@@ -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
@@ -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())}; }