1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-08 09:37:53 +00:00
OpenMW/components/platform/file.hpp

50 lines
1002 B
C++
Raw Normal View History

#ifndef OPENMW_COMPONENTS_PLATFORM_FILE_HPP
#define OPENMW_COMPONENTS_PLATFORM_FILE_HPP
#include <cstdlib>
#include <string_view>
namespace Platform::File {
enum class Handle : intptr_t
{
Invalid = -1
};
enum class SeekType
{
Begin,
Current,
End
};
Handle open(const char* filename);
void close(Handle handle);
size_t size(Handle handle);
void seek(Handle handle, size_t Position, SeekType type = SeekType::Begin);
size_t tell(Handle handle);
size_t read(Handle handle, void* data, size_t size);
2022-07-18 18:13:41 +00:00
class ScopedHandle
{
Handle mHandle{ Handle::Invalid };
public:
ScopedHandle() = default;
ScopedHandle(Handle handle) : mHandle(handle) {}
2022-07-18 18:44:03 +00:00
~ScopedHandle()
{
if(mHandle != Handle::Invalid)
close(mHandle);
}
2022-07-18 18:13:41 +00:00
operator Handle() const { return mHandle; }
};
}
#endif // OPENMW_COMPONENTS_PLATFORM_FILE_HPP