DataAccessor interface
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
/*********************************************************************
|
||||
* \file DataAccessor.cpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date August 2026
|
||||
*********************************************************************/
|
||||
#include <Engine/DataAccessor/DataAccessor.hpp>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
void SetDataAccessor(DataAccessor* p_dataAccessor)
|
||||
{
|
||||
g_dataAccessor = p_dataAccessor;
|
||||
}
|
||||
} // namespace Bigfoot
|
||||
@@ -0,0 +1,115 @@
|
||||
/*********************************************************************
|
||||
* \file DataAccessor.hpp
|
||||
*
|
||||
* \author Romain BOULLARD
|
||||
* \date August 2026
|
||||
*********************************************************************/
|
||||
#ifndef BIGFOOT_ENGINE_DATAACCESSOR_DATAACCESSOR_HPP
|
||||
#define BIGFOOT_ENGINE_DATAACCESSOR_DATAACCESSOR_HPP
|
||||
#include <Engine/Asset/AssetTypeID.hpp>
|
||||
|
||||
#include <System/Time/Time.hpp>
|
||||
#include <System/UUID/UUID.hpp>
|
||||
|
||||
#include <EASTL/span.h>
|
||||
#include <EASTL/string.h>
|
||||
#include <EASTL/vector.h>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
struct AssetMetadata
|
||||
{
|
||||
UUID m_uuid = UUID::NULL_UUID;
|
||||
eastl::string m_name {};
|
||||
|
||||
AssetTypeID m_typeID = 0;
|
||||
eastl::string m_typeName {};
|
||||
|
||||
Time m_creationTime = 0;
|
||||
Time m_modificationTime = 0;
|
||||
};
|
||||
|
||||
class DataAccessor
|
||||
{
|
||||
public:
|
||||
DataAccessor() = default;
|
||||
|
||||
DataAccessor(const DataAccessor& p_accessor) = default;
|
||||
DataAccessor(DataAccessor&& p_accessor) = default;
|
||||
|
||||
virtual ~DataAccessor() = default;
|
||||
|
||||
/**
|
||||
* Get an Asset flatbuffer
|
||||
*
|
||||
* \param p_uuid The asset to get the flatbuffer of
|
||||
* \return The flatbuffer, can be empty if asset was not found
|
||||
*/
|
||||
virtual eastl::vector<std::byte> GetAssetFlatbuffer(const UUID& p_uuid) const = 0;
|
||||
|
||||
/**
|
||||
* Get an Asset metadata
|
||||
*
|
||||
* \param p_uuid The asset to get the metadata of
|
||||
* \return The metadata, default initialized if not found (ie: UUID = NULL)
|
||||
*/
|
||||
virtual AssetMetadata GetAssetMetadata(const UUID& p_uuid) const = 0;
|
||||
|
||||
/**
|
||||
* Save an asset
|
||||
*
|
||||
* \p_metadata The metadata
|
||||
* \p_flatbuffer The flatbuffer of the asset
|
||||
*/
|
||||
virtual void SaveAssetFlatbuffer(const AssetMetadata& p_metadata,
|
||||
const eastl::span<const std::byte> p_flatbuffer) = 0;
|
||||
|
||||
DataAccessor& operator=(const DataAccessor& p_accessor) = default;
|
||||
DataAccessor& operator=(DataAccessor&& p_accessor) = default;
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
// The global data accessor for Bigfoot
|
||||
inline DataAccessor* g_dataAccessor = nullptr;
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
/*
|
||||
* Set the data accessor
|
||||
*
|
||||
* \param p_dataAccessor The data accessor to set g_dataAccessor to.
|
||||
*/
|
||||
void SetDataAccessor(DataAccessor* p_dataAccessor);
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
class ScopedDataAccessor
|
||||
{
|
||||
public:
|
||||
ScopedDataAccessor(DataAccessor* p_dataAccessor):
|
||||
m_previous(g_dataAccessor)
|
||||
{
|
||||
SetDataAccessor(p_dataAccessor);
|
||||
}
|
||||
|
||||
ScopedDataAccessor(const ScopedDataAccessor& p_scopedDataAccessor) = delete;
|
||||
ScopedDataAccessor(ScopedDataAccessor&& p_scopedDataAccessor) = delete;
|
||||
|
||||
~ScopedDataAccessor()
|
||||
{
|
||||
SetDataAccessor(m_previous);
|
||||
}
|
||||
|
||||
ScopedDataAccessor& operator=(const ScopedDataAccessor& p_scopedDataAccessor) = delete;
|
||||
ScopedDataAccessor& operator=(ScopedDataAccessor&& p_scopedDataAccessor) = delete;
|
||||
|
||||
private:
|
||||
/*
|
||||
* The previous data accessor.
|
||||
*/
|
||||
DataAccessor* m_previous = nullptr;
|
||||
};
|
||||
} // namespace Bigfoot
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user