| 1 | #cxx . . $ `<file>/io/nativefilestream.h`/ifndef IOUTILITIES_NATIVE_FILE_STREAM |
| 2 | #define IOUTILITIES_NATIVE_FILE_STREAMcxx . . $ `io/nativefilestream.h:2:9`! |
| 3 | |
| 4 | #include "../global.h"cxx . . $ `<file>/global.h`/ |
| 5 | |
| 6 | #ifdef CPP_UTILITIES_USE_NATIVE_FILE_BUFFERcxx . . $ `<built-in>:483:9`! |
| 7 | #include <iostream> |
| 8 | #include <memory> |
| 9 | #include <streambuf> |
| 10 | #include <string> |
| 11 | #ifdef PLATFORM_WINDOWS |
| 12 | #include <string_view> |
| 13 | #endif |
| 14 | #else |
| 15 | #include <fstream> |
| 16 | #endif |
| 17 | |
| 18 | namespace CppUtilitiescxx . . $ CppUtilities/ { |
| 19 | |
| 20 | #ifdef CPP_UTILITIES_USE_NATIVE_FILE_BUFFERcxx . . $ `<built-in>:483:9`! |
| 21 | |
| 22 | class CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! NativeFileStreamcxx . . $ CppUtilities/NativeFileStream# : public stdcxx . . $ std/::iostreamcxx . . $ std/iostream# { |
| 23 | public: |
| 24 | #ifdef PLATFORM_WINDOWS |
| 25 | using Handle = void *; |
| 26 | #endif |
| 27 | struct CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! FileBuffercxx . . $ CppUtilities/NativeFileStream#FileBuffer# { |
| 28 | FileBuffercxx . . $ CppUtilities/NativeFileStream#FileBuffer#FileBuffer(7926eb18314c3706).(stdcxx . . $ std/::basic_streambufcxx . . $ std/basic_streambuf#<char> *buffer); |
| 29 | FileBuffercxx . . $ CppUtilities/NativeFileStream#FileBuffer#FileBuffer(b8cd37071ce335df).(const char *path, ios_basecxx . . $ std/ios_base#::openmodecxx . . $ std/ios_base#openmode# openMode); |
| 30 | FileBuffercxx . . $ CppUtilities/NativeFileStream#FileBuffer#FileBuffer(be6c264dafcf0985).(const stdcxx . . $ std/::stringcxx . . $ std/string# &path, ios_basecxx . . $ std/ios_base#::openmodecxx . . $ std/ios_base#openmode# openMode); |
| 31 | FileBuffercxx . . $ CppUtilities/NativeFileStream#FileBuffer#FileBuffer(95134c3a2f2e73fe).(int fileDescriptor, ios_basecxx . . $ std/ios_base#::openmodecxx . . $ std/ios_base#openmode# openMode); |
| 32 | |
| 33 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<stdcxx . . $ std/::basic_streambufcxx . . $ std/basic_streambuf#<char>> buffercxx . . $ CppUtilities/NativeFileStream#FileBuffer#buffer.; |
| 34 | #ifdef PLATFORM_WINDOWS |
| 35 | Handle handle = nullptr; |
| 36 | #endif |
| 37 | int descriptorcxx . . $ CppUtilities/NativeFileStream#FileBuffer#descriptor. = -1; |
| 38 | }; |
| 39 | |
| 40 | NativeFileStreamcxx . . $ CppUtilities/NativeFileStream#NativeFileStream(49f6e7a06ebc5aa8).(); |
| 41 | NativeFileStreamcxx . . $ CppUtilities/NativeFileStream#NativeFileStream(b8cd37071ce335df).(const char *path, stdcxx . . $ std/::ios_basecxx . . $ std/ios_base#::openmodecxx . . $ std/ios_base#openmode# openMode); |
| 42 | NativeFileStreamcxx . . $ CppUtilities/NativeFileStream#NativeFileStream(be6c264dafcf0985).(const stdcxx . . $ std/::stringcxx . . $ std/string# &path, stdcxx . . $ std/::ios_basecxx . . $ std/ios_base#::openmodecxx . . $ std/ios_base#openmode# openMode); |
| 43 | NativeFileStreamcxx . . $ CppUtilities/NativeFileStream#NativeFileStream(95134c3a2f2e73fe).(int fileDescriptor, stdcxx . . $ std/::ios_basecxx . . $ std/ios_base#::openmodecxx . . $ std/ios_base#openmode# openMode); |
| 44 | NativeFileStreamcxx . . $ CppUtilities/NativeFileStream#NativeFileStream(719b5dd2bbc4fb05).(NativeFileStreamcxx . . $ CppUtilities/NativeFileStream# &&); |
| 45 | ~cxx . . $ CppUtilities/NativeFileStream#`~NativeFileStream`(ced63f7c635d850d).NativeFileStreamcxx . . $ CppUtilities/NativeFileStream#() override; |
| 46 | |
| 47 | bool is_opencxx . . $ CppUtilities/NativeFileStream#is_open(50ce9a9e25b4a850).() const; |
| 48 | bool isOpencxx . . $ CppUtilities/NativeFileStream#isOpen(50ce9a9e25b4a850).() const; |
| 49 | void opencxx . . $ CppUtilities/NativeFileStream#open(b8cd37071ce335df).(const char *path, stdcxx . . $ std/::ios_basecxx . . $ std/ios_base#::openmodecxx . . $ std/ios_base#openmode# openMode); |
| 50 | void opencxx . . $ CppUtilities/NativeFileStream#open(be6c264dafcf0985).(const stdcxx . . $ std/::stringcxx . . $ std/string# &path, stdcxx . . $ std/::ios_basecxx . . $ std/ios_base#::openmodecxx . . $ std/ios_base#openmode# openMode); |
| 51 | void opencxx . . $ CppUtilities/NativeFileStream#open(95134c3a2f2e73fe).(int fileDescriptor, stdcxx . . $ std/::ios_basecxx . . $ std/ios_base#::openmodecxx . . $ std/ios_base#openmode# openMode); |
| 52 | void closecxx . . $ CppUtilities/NativeFileStream#close(49f6e7a06ebc5aa8).(); |
| 53 | int fileDescriptorcxx . . $ CppUtilities/NativeFileStream#fileDescriptor(b126dc7c1de90089).(); |
| 54 | #ifdef PLATFORM_WINDOWS |
| 55 | Handle fileHandle(); |
| 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); |
| 59 | #endif |
| 60 | |
| 61 | private: |
| 62 | void setDatacxx . . $ CppUtilities/NativeFileStream#setData(91ccaf2b92fd531e).(FileBuffercxx . . $ CppUtilities/NativeFileStream#FileBuffer# data, stdcxx . . $ std/::ios_basecxx . . $ std/ios_base#::openmodecxx . . $ std/ios_base#openmode# openMode); |
| 63 | |
| 64 | FileBuffercxx . . $ CppUtilities/NativeFileStream#FileBuffer# m_datacxx . . $ CppUtilities/NativeFileStream#m_data.; |
| 65 | stdcxx . . $ std/::ios_basecxx . . $ std/ios_base#::openmodecxx . . $ std/ios_base#openmode# m_openModecxx . . $ CppUtilities/NativeFileStream#m_openMode.; |
| 66 | }; |
| 67 | |
| 68 | /*! |
| 69 | * \brief Constructs a new NativeFileStream. The specified \a path is supposed to be UTF-8 encoded. |
| 70 | */ |
| 71 | inline NativeFileStreamcxx . . $ CppUtilities/NativeFileStream#::NativeFileStreamcxx . . $ CppUtilities/NativeFileStream#NativeFileStream(b8cd37071ce335df).(const char *path, ios_basecxx . . $ std/ios_base#::openmodecxx . . $ std/ios_base#openmode# openMode) |
| 72 | : NativeFileStreamcxx . . $ CppUtilities/NativeFileStream#NativeFileStream(49f6e7a06ebc5aa8).() |
| 73 | { |
| 74 | opencxx . . $ CppUtilities/NativeFileStream#open(b8cd37071ce335df).(path, openMode); |
| 75 | } |
| 76 | |
| 77 | /*! |
| 78 | * \brief Constructs a new NativeFileStream. The specified \a path is supposed to be UTF-8 encoded. |
| 79 | */ |
| 80 | inline NativeFileStreamcxx . . $ CppUtilities/NativeFileStream#::NativeFileStreamcxx . . $ CppUtilities/NativeFileStream#NativeFileStream(be6c264dafcf0985).(const stdcxx . . $ std/::stringcxx . . $ std/string# &path, ios_basecxx . . $ std/ios_base#::openmodecxx . . $ std/ios_base#openmode# openMode) |
| 81 | : NativeFileStreamcxx . . $ CppUtilities/NativeFileStream#NativeFileStream(b8cd37071ce335df).(path.datacxx . . $ std/__cxx11/basic_string#data(8e614c7de0b1573e).(), openMode) |
| 82 | { |
| 83 | } |
| 84 | |
| 85 | /*! |
| 86 | * \brief Constructs a new NativeFileStream. The specified \a fileDescriptor is either a POSIX file descriptor or a Windows CRT file descriptor. |
| 87 | */ |
| 88 | inline NativeFileStreamcxx . . $ CppUtilities/NativeFileStream#::NativeFileStreamcxx . . $ CppUtilities/NativeFileStream#NativeFileStream(95134c3a2f2e73fe).(int fileDescriptor, ios_basecxx . . $ std/ios_base#::openmodecxx . . $ std/ios_base#openmode# openMode) |
| 89 | : NativeFileStreamcxx . . $ CppUtilities/NativeFileStream#NativeFileStream(49f6e7a06ebc5aa8).() |
| 90 | { |
| 91 | opencxx . . $ CppUtilities/NativeFileStream#open(95134c3a2f2e73fe).(fileDescriptor, openMode); |
| 92 | } |
| 93 | |
| 94 | /*! |
| 95 | * \brief Returns the native POSIX or Windows CRT file descriptor. |
| 96 | * \remarks Might not be populated if only a Windows file handle is used. |
| 97 | */ |
| 98 | inline int NativeFileStreamcxx . . $ CppUtilities/NativeFileStream#::fileDescriptorcxx . . $ CppUtilities/NativeFileStream#fileDescriptor(b126dc7c1de90089).() |
| 99 | { |
| 100 | return m_datacxx . . $ CppUtilities/NativeFileStream#m_data..descriptorcxx . . $ CppUtilities/NativeFileStream#FileBuffer#descriptor.; |
| 101 | } |
| 102 | |
| 103 | #ifdef PLATFORM_WINDOWS |
| 104 | /*! |
| 105 | * \brief Returns the native Windows file handle. |
| 106 | * \remarks Might not be populated if only a Windows CRT file descriptor is used. |
| 107 | */ |
| 108 | inline NativeFileStream::Handle NativeFileStream::fileHandle() |
| 109 | { |
| 110 | return m_data.handle; |
| 111 | } |
| 112 | |
| 113 | /*! |
| 114 | * \brief Converts the specified UTF-8 encoded \a path to UTF-16 for passing it to WinAPI functions. |
| 115 | * \throws Throws std::ios_base::failure when an encoding error occurs. |
| 116 | */ |
| 117 | inline std::unique_ptr<wchar_t[]> NativeFileStream::makeWidePath(const char *path) |
| 118 | { |
| 119 | return makeWidePath(std::string_view(path)); |
| 120 | } |
| 121 | #endif |
| 122 | |
| 123 | /*! |
| 124 | * \brief Returns whether the file is open. |
| 125 | * \remarks Same as NativeFileStream::isOpen(); provided for API compatibility with std::fstream. |
| 126 | */ |
| 127 | inline bool NativeFileStreamcxx . . $ CppUtilities/NativeFileStream#::is_opencxx . . $ CppUtilities/NativeFileStream#is_open(50ce9a9e25b4a850).() const |
| 128 | { |
| 129 | return isOpencxx . . $ CppUtilities/NativeFileStream#isOpen(50ce9a9e25b4a850).(); |
| 130 | } |
| 131 | |
| 132 | #else // CPP_UTILITIES_USE_NATIVE_FILE_BUFFER |
| 133 | |
| 134 | using NativeFileStream = std::fstream; |
| 135 | |
| 136 | #endif |
| 137 | |
| 138 | } // namespace CppUtilities |
| 139 | |
| 140 | #endif // IOUTILITIES_NATIVE_FILE_STREAM |