59 lines
1.9 KiB
C++
59 lines
1.9 KiB
C++
// IACore-OSS; The Core Library for All IA Open Source Projects
|
|
// Copyright (C) 2025 IAS (ias@iasoft.dev)
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
#include <IACore/StreamReader.hpp>
|
|
#include <IACore/FileOps.hpp>
|
|
#include <IACore/Logger.hpp>
|
|
|
|
namespace IACore
|
|
{
|
|
StreamReader::StreamReader(IN CONST FilePath &path) : m_storageType(EStorageType::OWNING_MMAP)
|
|
{
|
|
const auto t = FileOps::MapFile(path, m_dataSize);
|
|
if (!t)
|
|
{
|
|
Logger::Error("Failed to memory map file {}", path.string());
|
|
return;
|
|
}
|
|
m_data = *t;
|
|
}
|
|
|
|
StreamReader::StreamReader(IN Vector<UINT8> &&data)
|
|
: m_owningVector(IA_MOVE(data)), m_storageType(EStorageType::OWNING_VECTOR)
|
|
{
|
|
m_data = m_owningVector.data();
|
|
m_dataSize = m_owningVector.size();
|
|
}
|
|
|
|
StreamReader::StreamReader(IN Span<CONST UINT8> data)
|
|
: m_data(data.data()), m_dataSize(data.size()), m_storageType(EStorageType::NON_OWNING)
|
|
{
|
|
}
|
|
|
|
StreamReader::~StreamReader()
|
|
{
|
|
switch (m_storageType)
|
|
{
|
|
case EStorageType::OWNING_MMAP:
|
|
FileOps::UnmapFile(m_data);
|
|
break;
|
|
|
|
case EStorageType::NON_OWNING:
|
|
case EStorageType::OWNING_VECTOR:
|
|
break;
|
|
}
|
|
}
|
|
} // namespace IACore
|