1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-18 20:43:04 +01:00
Files
OpenRCT2/src/openrct2/core/FileStream.h
James103 1d8dc111f1 Replace 2023 with 2024 in copyright headers (#21139)
Replace all instances of the year 2023 with 2024 in all copyright headers
2024-01-01 12:52:28 +01:00

60 lines
1.8 KiB
C++

/*****************************************************************************
* Copyright (c) 2014-2024 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#pragma once
#include "../common.h"
#include "FileSystem.hpp"
#include "IStream.hpp"
namespace OpenRCT2
{
enum
{
FILE_MODE_OPEN,
FILE_MODE_WRITE,
FILE_MODE_APPEND,
};
/**
* A stream for reading and writing to files.
*/
class FileStream final : public IStream
{
private:
FILE* _file = nullptr;
bool _ownsFilePtr = false;
bool _canRead = false;
bool _canWrite = false;
bool _disposed = false;
uint64_t _fileSize = 0;
public:
FileStream(const fs::path& path, int32_t fileMode);
FileStream(const std::string& path, int32_t fileMode);
FileStream(std::string_view path, int32_t fileMode);
FileStream(const utf8* path, int32_t fileMode);
~FileStream() override;
bool CanRead() const override;
bool CanWrite() const override;
uint64_t GetLength() const override;
uint64_t GetPosition() const override;
void SetPosition(uint64_t position) override;
void Seek(int64_t offset, int32_t origin) override;
void Read(void* buffer, uint64_t length) override;
void Write(const void* buffer, uint64_t length) override;
uint64_t TryRead(void* buffer, uint64_t length) override;
const void* GetData() const override;
};
} // namespace OpenRCT2