Core/Stream: Add MemoryMapped stream options (allowing for direct memory access)

This commit is contained in:
SirLynix
2023-03-03 13:18:51 +01:00
parent 3000345eab
commit 34abeeb7bd
9 changed files with 103 additions and 72 deletions

View File

@@ -6,6 +6,7 @@
#include <Nazara/Core/ByteArray.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <cstring>
#include <Nazara/Core/Debug.hpp>
@@ -34,26 +35,6 @@ namespace Nz
return TestStreamEnd();
}
/*!
* \brief Gets the directory of the stream
* \return Empty string (meant to be virtual)
*/
std::filesystem::path Stream::GetDirectory() const
{
return {};
}
/*!
* \brief Gets the path of the stream
* \return Empty string (meant to be virtual)
*/
std::filesystem::path Stream::GetPath() const
{
return {};
}
UInt64 Stream::GetCursorPos() const
{
if (m_bufferCapacity == 0)
@@ -65,6 +46,24 @@ namespace Nz
}
}
/*!
* \brief Gets the directory of the stream
* \return Empty string (meant to be virtual)
*/
std::filesystem::path Stream::GetDirectory() const
{
return {};
}
/*!
* \brief Gets the path of the stream
* \return Empty string (meant to be virtual)
*/
std::filesystem::path Stream::GetPath() const
{
return {};
}
/*!
* \brief Reads the stream and puts the result in a buffer
* \return Size of the read
@@ -264,17 +263,22 @@ namespace Nz
#if defined(NAZARA_PLATFORM_WINDOWS)
std::string temp(string);
ReplaceStr(temp, "\n", "\r\n");
#elif defined(NAZARA_PLATFORM_LINUX) || defined(NAZARA_PLATFORM_WEB)
std::string_view temp(string);
// Nothing to do
string = temp;
#elif defined(NAZARA_PLATFORM_MACOS)
std::string temp(string);
ReplaceStr(temp, "\n", "\r");
#endif
return Write(temp.data(), temp.size()) == temp.size();
string = temp;
#endif
}
else
return Write(string.data(), string.size()) == string.size();
return Write(string.data(), string.size()) == string.size();
}
void* Stream::GetMemoryMappedPointer() const
{
NazaraError("Stream set the MemoryMapped option but did not implement GetMemoryMappedPointer");
return nullptr;
}
}