diff --git a/Bigfoot/Sources/Engine/BigFile/BigFile.cpp b/Bigfoot/Sources/Engine/BigFile/BigFile.cpp index 73b5108..d0ff2c3 100644 --- a/Bigfoot/Sources/Engine/BigFile/BigFile.cpp +++ b/Bigfoot/Sources/Engine/BigFile/BigFile.cpp @@ -64,6 +64,22 @@ BigFile::~BigFile() /****************************************************************************************/ +eastl::optional> BigFile::GetAssetFlatbuffer(const UUID& p_uuid) const +{ + BigFile::Request assetRequest {*this, "SELECT Asset FROM Asset WHERE UUID = ?1;"}; + assetRequest.Bind(1, p_uuid.ToBytes()); + + if (!assetRequest.Step()) + { + return eastl::nullopt; + } + + const eastl::span flatbuffer = assetRequest.Get(0); + return eastl::vector {flatbuffer.begin(), flatbuffer.end()}; +} + +/****************************************************************************************/ + eastl::vector> BigFile::GetAssetFlatbuffers(const eastl::span p_uuids) const { eastl::vector> flatbuffers; @@ -77,6 +93,7 @@ eastl::vector> BigFile::GetAssetFlatbuffers(const eastl uniqueUUIDs.erase(eastl::unique(uniqueUUIDs.begin(), uniqueUUIDs.end()), uniqueUUIDs.end()); eastl::string placeholders; + placeholders.reserve(uniqueUUIDs.size() * 3); for (std::size_t i = 0; i < uniqueUUIDs.size(); ++i) { if (i > 0) @@ -84,13 +101,9 @@ eastl::vector> BigFile::GetAssetFlatbuffers(const eastl placeholders += ", "; } placeholders += "?"; - placeholders += std::to_string(i + 1).c_str(); } - const std::string sqlRequest = fmt::format("SELECT Asset.Asset FROM Asset " - "JOIN AssetMetadata ON AssetMetadata.UUID = Asset.UUID " - "WHERE Asset.UUID IN ({});", - placeholders); + const std::string sqlRequest = fmt::format("SELECT Asset FROM Asset WHERE UUID IN ({});", placeholders); BigFile::Request assetRequest {*this, sqlRequest.c_str()}; for (std::size_t i = 0; i < uniqueUUIDs.size(); ++i) @@ -115,6 +128,30 @@ eastl::vector> BigFile::GetAssetFlatbuffers(const eastl /****************************************************************************************/ +eastl::optional BigFile::GetAssetMetadata(const UUID& p_uuid) const +{ + BigFile::Request assetRequest { + *this, + "SELECT UUID, Name, TypeID, TypeName, CreateTime, ModificationTime FROM AssetMetadata WHERE UUID = ?1;"}; + assetRequest.Bind(1, p_uuid.ToBytes()); + + if (!assetRequest.Step()) + { + return eastl::nullopt; + } + + return AssetMetadata {.m_uuid = UUID {std::span { + static_cast>(assetRequest.Get(0)).data(), + UUID::UUID_BYTE_SIZE}}, + .m_name = eastl::string {static_cast(assetRequest.Get(1))}, + .m_typeID = assetRequest.Get(2), + .m_typeName = eastl::string {static_cast(assetRequest.Get(3))}, + .m_creationTime = Time {static_cast(assetRequest.Get(4))}, + .m_modificationTime = Time {static_cast(assetRequest.Get(5))}}; +} + +/****************************************************************************************/ + eastl::vector BigFile::GetAssetMetadatas(const eastl::span p_uuids) const { eastl::vector metadatas; @@ -128,6 +165,7 @@ eastl::vector BigFile::GetAssetMetadatas(const eastl::span 0) @@ -135,7 +173,6 @@ eastl::vector BigFile::GetAssetMetadatas(const eastl::span> GetAssetFlatbuffer(const UUID& p_uuid) const override; + /** * Get several Asset flatbuffers * @@ -59,6 +67,14 @@ class BigFile: public DataAccessor */ eastl::vector> GetAssetFlatbuffers(eastl::span p_uuids) const override; + /** + * Get an Asset metadata + * + * \param p_uuid The asset to get the metadata of + * \return The metadata, or nullopt if the asset was not found + */ + eastl::optional GetAssetMetadata(const UUID& p_uuid) const override; + /** * Get several Asset metadatas * diff --git a/Bigfoot/Sources/Engine/Include/Engine/DataAccessor/DataAccessor.hpp b/Bigfoot/Sources/Engine/Include/Engine/DataAccessor/DataAccessor.hpp index e881600..afba0df 100644 --- a/Bigfoot/Sources/Engine/Include/Engine/DataAccessor/DataAccessor.hpp +++ b/Bigfoot/Sources/Engine/Include/Engine/DataAccessor/DataAccessor.hpp @@ -46,16 +46,7 @@ class DataAccessor * \param p_uuid The asset to get the flatbuffer of * \return The flatbuffer, or nullopt if the asset was not found */ - eastl::optional> GetAssetFlatbuffer(const UUID& p_uuid) const - { - eastl::vector> flatbuffers = GetAssetFlatbuffers(eastl::span {&p_uuid, 1}); - if (flatbuffers.empty()) - { - return eastl::nullopt; - } - - return std::move(flatbuffers.front()); - } + virtual eastl::optional> GetAssetFlatbuffer(const UUID& p_uuid) const = 0; /** * Get several Asset flatbuffers @@ -71,16 +62,7 @@ class DataAccessor * \param p_uuid The asset to get the metadata of * \return The metadata, or nullopt if the asset was not found */ - eastl::optional GetAssetMetadata(const UUID& p_uuid) const - { - eastl::vector metadatas = GetAssetMetadatas(eastl::span {&p_uuid, 1}); - if (metadatas.empty()) - { - return eastl::nullopt; - } - - return std::move(metadatas.front()); - } + virtual eastl::optional GetAssetMetadata(const UUID& p_uuid) const = 0; /** * Get several Asset metadatas diff --git a/Bigfoot/Tests/Engine/DataAccessor/DataAccessor.cpp b/Bigfoot/Tests/Engine/DataAccessor/DataAccessor.cpp index 5284742..1438bdb 100644 --- a/Bigfoot/Tests/Engine/DataAccessor/DataAccessor.cpp +++ b/Bigfoot/Tests/Engine/DataAccessor/DataAccessor.cpp @@ -17,10 +17,15 @@ class DataAccessorFixture: public ::testing::Test class DataAccessorMock: public DataAccessor { public: + MOCK_METHOD(eastl::optional>, + GetAssetFlatbuffer, + (const UUID& p_uuid), + (const, override)); MOCK_METHOD(eastl::vector>, GetAssetFlatbuffers, (eastl::span p_uuids), (const, override)); + MOCK_METHOD(eastl::optional, GetAssetMetadata, (const UUID& p_uuid), (const, override)); MOCK_METHOD(eastl::vector, GetAssetMetadatas, (eastl::span p_uuids),