1#ifndef IOUTILITIES_NATIVE_FILE_STREAM
2#define IOUTILITIES_NATIVE_FILE_STREAM
6#ifdef CPP_UTILITIES_USE_NATIVE_FILE_BUFFER
11#ifdef PLATFORM_WINDOWS
20#ifdef CPP_UTILITIES_USE_NATIVE_FILE_BUFFER
24#ifdef PLATFORM_WINDOWS
25 using Handle =
void *;
28 FileBuffer(std::basic_streambuf<char> *buffer);
29 FileBuffer(
const char *path, ios_base::openmode openMode);
30 FileBuffer(
const std::string &path, ios_base::openmode openMode);
31 FileBuffer(
int fileDescriptor, ios_base::openmode openMode);
33 std::unique_ptr<std::basic_streambuf<char>> buffer;
34#ifdef PLATFORM_WINDOWS
35 Handle handle =
nullptr;
45 ~NativeFileStream()
override;
49 void open(
const char *path, std::ios_base::openmode openMode);
50 void open(
const std::string &path, std::ios_base::openmode openMode);
51 void open(
int fileDescriptor, std::ios_base::openmode openMode);
54#ifdef PLATFORM_WINDOWS
56 static std::unique_ptr<wchar_t[]> makeWidePath(std::string_view path);
57 static std::unique_ptr<wchar_t[]> makeWidePath(
const char *path);
58 static std::unique_ptr<wchar_t[]> makeWidePath(
const std::string &path);
62 void setData(FileBuffer data, std::ios_base::openmode openMode);
65 std::ios_base::openmode m_openMode;
71inline NativeFileStream::NativeFileStream(
const char *path, ios_base::openmode openMode)
80inline NativeFileStream::NativeFileStream(
const std::string &path, ios_base::openmode openMode)
88inline NativeFileStream::NativeFileStream(
int fileDescriptor, ios_base::openmode openMode)
91 open(fileDescriptor, openMode);
98inline int NativeFileStream::fileDescriptor()
100 return m_data.descriptor;
103#ifdef PLATFORM_WINDOWS
108inline NativeFileStream::Handle NativeFileStream::fileHandle()
110 return m_data.handle;
117inline std::unique_ptr<wchar_t[]> NativeFileStream::makeWidePath(
const char *path)
119 return makeWidePath(std::string_view(path));
127inline bool NativeFileStream::is_open()
const
#define CPP_UTILITIES_EXPORT
Marks the symbol to be exported by the c++utilities library.
Contains all utilities provided by the c++utilities library.
std::fstream NativeFileStream