#pragma once
#ifndef _FSTREAM_
#define _FSTREAM_
#include <yvals_core.h>
#if _STL_COMPILER_PREPROCESSOR
#include <istream>
#pragma pack(push, _CRT_PACKING)
#pragma warning(push, _STL_WARNING_LEVEL)
#pragma warning(disable : _STL_DISABLED_WARNINGS)
_STL_DISABLE_CLANG_WARNINGS
#pragma push_macro("new")
#undef new
_STD_BEGIN
#if _HAS_CXX17
namespace filesystem {
class path;
}
#endif
#ifndef _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
#ifdef _M_CEE
#define _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM 0
#else
#define _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM 1
#endif
#endif
#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
namespace experimental {
namespace filesystem {
inline namespace v1 {
class path;
}
}
}
#endif
extern _CRTIMP2_PURE FILE* __CLRCALL_PURE_OR_CDECL _Fiopen(const char*, ios_base::openmode, int);
extern _CRTIMP2_PURE FILE* __CLRCALL_PURE_OR_CDECL _Fiopen(const wchar_t*, ios_base::openmode, int);
#ifdef _NATIVE_WCHAR_T_DEFINED
extern _CRTIMP2_PURE FILE* __CLRCALL_PURE_OR_CDECL _Fiopen(const unsigned short*, ios_base::openmode, int);
#endif
template <class _Elem>
bool _Fgetc(_Elem& _Ch, FILE* _File) {
return _CSTD fread(&_Ch, sizeof(_Elem), 1, _File) == 1;
}
template <>
inline bool _Fgetc(char& _Byte, FILE* _File) {
int _Meta;
if ((_Meta = _CSTD fgetc(_File)) == EOF) {
return false;
} else {
_Byte = static_cast<char>(_Meta);
return true;
}
}
template <>
inline bool _Fgetc(wchar_t& _Wchar, FILE* _File) {
wint_t _Meta;
if ((_Meta = _CSTD fgetwc(_File)) == WEOF) {
return false;
} else {
_Wchar = static_cast<wchar_t>(_Meta);
return true;
}
}
#ifdef _NATIVE_WCHAR_T_DEFINED
template <>
inline bool _Fgetc(unsigned short& _Wchar, FILE* _File) {
wint_t _Meta;
if ((_Meta = _CSTD fgetwc(_File)) == WEOF) {
return false;
} else {
_Wchar = static_cast<unsigned short>(_Meta);
return true;
}
}
#endif
template <class _Elem>
bool _Fputc(_Elem _Ch, FILE* _File) {
return _CSTD fwrite(&_Ch, 1, sizeof(_Elem), _File) == sizeof(_Elem);
}
template <>
inline bool _Fputc(char _Byte, FILE* _File) {
return _CSTD fputc(_Byte, _File) != EOF;
}
template <>
inline bool _Fputc(wchar_t _Wchar, FILE* _File) {
return _CSTD fputwc(_Wchar, _File) != WEOF;
}
#ifdef _NATIVE_WCHAR_T_DEFINED
template <>
inline bool _Fputc(unsigned short _Wchar, FILE* _File) {
return _CSTD fputwc(_Wchar, _File) != WEOF;
}
#endif
template <class _Elem>
bool _Ungetc(const _Elem&, FILE*) {
return false;
}
template <>
inline bool _Ungetc(const char& _Byte, FILE* _File) {
return _CSTD ungetc(static_cast<unsigned char>(_Byte), _File) != EOF;
}
template <>
inline bool _Ungetc(const signed char& _Byte, FILE* _File) {
return _CSTD ungetc(static_cast<unsigned char>(_Byte), _File) != EOF;
}
template <>
inline bool _Ungetc(const unsigned char& _Byte, FILE* _File) {
return _CSTD ungetc(_Byte, _File) != EOF;
}
template <>
inline bool _Ungetc(const wchar_t& _Wchar, FILE* _File) {
return _CSTD ungetwc(_Wchar, _File) != WEOF;
}
#ifdef _NATIVE_WCHAR_T_DEFINED
template <>
inline bool _Ungetc(const unsigned short& _Wchar, FILE* _File) {
return _CSTD ungetwc(_Wchar, _File) != WEOF;
}
#endif
template <class _Elem, class _Traits>
class basic_filebuf : public basic_streambuf<_Elem, _Traits> {
public:
using _Mysb = basic_streambuf<_Elem, _Traits>;
using _Cvt = codecvt<_Elem, char, typename _Traits::state_type>;
basic_filebuf() : _Mysb() {
_Init(nullptr, _Newfl);
}
explicit basic_filebuf(FILE* const _File) : _Mysb() {
_Init(_File, _Newfl);
}
virtual __CLR_OR_THIS_CALL ~basic_filebuf() noexcept {
if (_Myfile) {
_Reset_back();
}
if (_Closef) {
close();
}
}
using int_type = typename _Traits::int_type;
using pos_type = typename _Traits::pos_type;
using off_type = typename _Traits::off_type;
basic_filebuf(_Uninitialized) : _Mysb(_Noinit) {}
basic_filebuf(basic_filebuf&& _Right) {
_Init(_Right._Myfile, _Newfl);
_Init(static_cast<FILE*>(nullptr), _Closefl);
_Assign_rv(_STD move(_Right));
}
basic_filebuf& operator=(basic_filebuf&& _Right) {
_Assign_rv(_STD move(_Right));
return *this;
}
void _Assign_rv(basic_filebuf&& _Right) {
if (this != _STD addressof(_Right)) {
close();
this->swap(_Right);
}
}
void swap(basic_filebuf& _Right) {
if (this != _STD addressof(_Right)) {
FILE* _Myfile_sav = _Myfile;
const _Cvt* _Pcvt_sav = _Pcvt;
typename _Traits::state_type _State_sav = _State;
bool _Wrotesome_sav = _Wrotesome;
bool _Closef_sav = _Closef;
bool _Set_eback_sav = _Mysb::eback() == &_Mychar;
bool _Set_eback_live = _Mysb::gptr() == &_Mychar;
_Elem* _Pfirst0 = _Mysb::pbase();
_Elem* _Pnext0 = _Mysb::pptr();
_Elem* _Pend = _Mysb::epptr();
_Elem* _Gfirst0 = _Mysb::eback();
_Elem* _Gnext0 = _Mysb::gptr();
_Elem* _Gend = _Mysb::egptr();
_Init(_Right._Myfile, _Right._Myfile ? _Openfl : _Newfl);
_Mysb::setp(_Right.pbase(), _Right.pptr(), _Right.epptr());
if (_Right.eback() != &_Right._Mychar) {
_Mysb::setg(_Right.eback(), _Right.gptr(), _Right.egptr());
} else if (_Right.gptr() != &_Right._Mychar) {
_Mysb::setg(&_Mychar, &_Mychar + 1, &_Mychar + 1);
} else {
_Mysb::setg(&_Mychar, &_Mychar, &_Mychar + 1);
}
_Pcvt = _Right._Pcvt;
_State = _Right._State;
_Wrotesome = _Right._Wrotesome;
_Closef = _Right._Closef;
_Right._Init(_Myfile_sav, _Myfile_sav ? _Openfl : _Newfl);
_Right.setp(_Pfirst0, _Pnext0, _Pend);
if (!_Set_eback_sav) {
_Right.setg(_Gfirst0, _Gnext0, _Gend);
} else if (!_Set_eback_live) {
_Right.setg(&_Right._Mychar, &_Right._Mychar + 1, &_Right._Mychar + 1);
} else {
_Right.setg(&_Right._Mychar, &_Right._Mychar, &_Right._Mychar + 1);
}
_Right._Pcvt = _Pcvt_sav;
_Right._State = _State_sav;
_Right._Wrotesome = _Wrotesome_sav;
_Right._Closef = _Closef_sav;
_STD swap(_Set_eback, _Right._Set_eback);
_STD swap(_Set_egptr, _Right._Set_egptr);
_STD swap(_Mychar, _Right._Mychar);
_STD swap(_Mysb::_Plocale, _Right._Plocale);
}
}
basic_filebuf(const basic_filebuf&) = delete;
basic_filebuf& operator=(const basic_filebuf&) = delete;
enum _Initfl {
_Newfl,
_Openfl,
_Closefl
};
_NODISCARD bool is_open() const {
return static_cast<bool>(_Myfile);
}
basic_filebuf* open(const char* _Filename, ios_base::openmode _Mode, int _Prot = ios_base::_Default_open_prot) {
if (_Myfile) {
return nullptr;
}
const auto _File = _Fiopen(_Filename, _Mode, _Prot);
if (!_File) {
return nullptr;
}
_Init(_File, _Openfl);
_Initcvt(_STD use_facet<_Cvt>(_Mysb::getloc()));
return this;
}
basic_filebuf* open(const string& _Str, ios_base::openmode _Mode, int _Prot = ios_base::_Default_open_prot) {
return open(_Str.c_str(), _Mode, _Prot);
}
#if _HAS_OLD_IOSTREAMS_MEMBERS
basic_filebuf* open(const char* _Filename, ios_base::open_mode _Mode) {
return open(_Filename, static_cast<ios_base::openmode>(_Mode));
}
#endif
basic_filebuf* open(const wchar_t* _Filename, ios_base::openmode _Mode, int _Prot = ios_base::_Default_open_prot) {
if (_Myfile) {
return nullptr;
}
const auto _File = _Fiopen(_Filename, _Mode, _Prot);
if (!_File) {
return nullptr;
}
_Init(_File, _Openfl);
_Initcvt(_STD use_facet<_Cvt>(_Mysb::getloc()));
return this;
}
basic_filebuf* open(const wstring& _Str, ios_base::openmode _Mode, int _Prot = ios_base::_Default_open_prot) {
return open(_Str.c_str(), _Mode, _Prot);
}
#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
template <class _Path_ish = experimental::filesystem::path>
basic_filebuf* open(
const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode, int _Prot = ios_base::_Default_open_prot) {
return open(_Path.c_str(), _Mode, _Prot);
}
#endif
#if _HAS_CXX17
template <int = 0, class _Path_ish = filesystem::path>
basic_filebuf* open(
const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode, int _Prot = ios_base::_Default_open_prot) {
return open(_Path.c_str(), _Mode, _Prot);
}
#endif
#if _HAS_OLD_IOSTREAMS_MEMBERS
basic_filebuf* open(const wchar_t* _Filename, ios_base::open_mode _Mode) {
return open(_Filename, static_cast<ios_base::openmode>(_Mode));
}
#endif
#ifdef _NATIVE_WCHAR_T_DEFINED
basic_filebuf* open(
const unsigned short* _Filename, ios_base::openmode _Mode, int _Prot = ios_base::_Default_open_prot) {
if (_Myfile) {
return nullptr;
}
const auto _File = _Fiopen(_Filename, _Mode, _Prot);
if (!_File) {
return nullptr;
}
_Init(_File, _Openfl);
_Initcvt(_STD use_facet<_Cvt>(_Mysb::getloc()));
return this;
}
#if _HAS_OLD_IOSTREAMS_MEMBERS
basic_filebuf* open(const unsigned short* _Filename, ios_base::open_mode _Mode) {
return open(_Filename, static_cast<ios_base::openmode>(_Mode));
}
#endif
#endif
basic_filebuf* close() {
basic_filebuf* _Ans;
if (_Myfile) {
_Ans = this;
if (!_Endwrite()) {
_Ans = nullptr;
}
if (_CSTD fclose(_Myfile) != 0) {
_Ans = nullptr;
}
} else {
_Ans = nullptr;
}
_Init(nullptr, _Closefl);
return _Ans;
}
virtual void __CLR_OR_THIS_CALL _Lock() override {
if (_Myfile) {
_CSTD _lock_file(_Myfile);
}
}
virtual void __CLR_OR_THIS_CALL _Unlock() override {
if (_Myfile) {
_CSTD _unlock_file(_Myfile);
}
}
protected:
virtual int_type __CLR_OR_THIS_CALL overflow(int_type _Meta = _Traits::eof()) override {
if (_Traits::eq_int_type(_Traits::eof(), _Meta)) {
return _Traits::not_eof(_Meta);
}
if (_Mysb::pptr() && _Mysb::pptr() < _Mysb::epptr()) {
*_Mysb::_Pninc() = _Traits::to_char_type(_Meta);
return _Meta;
}
if (!_Myfile) {
return _Traits::eof();
}
_Reset_back();
if (!_Pcvt) {
return _Fputc(_Traits::to_char_type(_Meta), _Myfile) ? _Meta : _Traits::eof();
}
constexpr size_t _Codecvt_temp_buf = 32;
char _Str[_Codecvt_temp_buf];
const _Elem _Ch = _Traits::to_char_type(_Meta);
const _Elem* _Src;
char* _Dest;
switch (_Pcvt->out(_State, &_Ch, &_Ch + 1, _Src, _Str, _Str + _Codecvt_temp_buf,
_Dest)) {
case codecvt_base::partial:
case codecvt_base::ok: {
const auto _Count = static_cast<size_t>(_Dest - _Str);
if (0 < _Count && _Count != static_cast<size_t>(_CSTD fwrite(_Str, 1, _Count, _Myfile))) {
return _Traits::eof();
}
_Wrotesome = true;
if (_Src != &_Ch) {
return _Meta;
}
return _Traits::eof();
}
case codecvt_base::noconv:
return _Fputc(_Ch, _Myfile) ? _Meta : _Traits::eof();
default:
return _Traits::eof();
}
}
virtual int_type __CLR_OR_THIS_CALL pbackfail(int_type _Meta = _Traits::eof()) override {
if (_Mysb::gptr() && _Mysb::eback() < _Mysb::gptr()
&& (_Traits::eq_int_type(_Traits::eof(), _Meta)
|| _Traits::eq_int_type(_Traits::to_int_type(_Mysb::gptr()[-1]),
_Meta))) {
_Mysb::_Gndec();
return _Traits::not_eof(_Meta);
} else if (!_Myfile || _Traits::eq_int_type(_Traits::eof(), _Meta)) {
return _Traits::eof();
} else if (!_Pcvt && _Ungetc(_Traits::to_char_type(_Meta), _Myfile)) {
return _Meta;
} else if (_Mysb::gptr() != &_Mychar) {
_Mychar = _Traits::to_char_type(_Meta);
_Set_back();
return _Meta;
} else {
return _Traits::eof();
}
}
virtual int_type __CLR_OR_THIS_CALL underflow() override {
int_type _Meta;
if (_Mysb::gptr() && _Mysb::gptr() < _Mysb::egptr()) {
return _Traits::to_int_type(*_Mysb::gptr());
} else if (_Traits::eq_int_type(_Traits::eof(), _Meta = uflow())) {
return _Meta;
} else {
pbackfail(_Meta);
return _Meta;
}
}
virtual int_type __CLR_OR_THIS_CALL uflow() override {
if (_Mysb::gptr() && _Mysb::gptr() < _Mysb::egptr()) {
return _Traits::to_int_type(*_Mysb::_Gninc());
}
if (!_Myfile) {
return _Traits::eof();
}
_Reset_back();
if (!_Pcvt) {
_Elem _Ch;
return _Fgetc(_Ch, _Myfile) ? _Traits::to_int_type(_Ch) : _Traits::eof();
}
string _Str;
for (;;) {
const char* _Src;
int _Meta = _CSTD fgetc(_Myfile);
if (_Meta == EOF) {
return _Traits::eof();
}
_Str.push_back(static_cast<char>(_Meta));
_Elem _Ch;
_Elem* _Dest;
switch (_Pcvt->in(_State, _Str.data(), _Str.data() + _Str.size(), _Src, &_Ch, &_Ch + 1,
_Dest)) {
case codecvt_base::partial:
case codecvt_base::ok:
if (_Dest != &_Ch) {
auto _Nleft = _Str.data() + _Str.size() - _Src;
while (0 < _Nleft) {
_CSTD ungetc(_Src[--_Nleft], _Myfile);
}
return _Traits::to_int_type(_Ch);
}
_Str.erase(0, static_cast<size_t>(_Src - _Str.data()));
break;
case codecvt_base::noconv:
return static_cast<int_type>(_Str.front());
default:
return _Traits::eof();
}
}
}
#pragma warning(push)
#pragma warning(disable : 4127)
virtual streamsize __CLR_OR_THIS_CALL xsgetn(_Elem* _Ptr, streamsize _Count) override {
if
_CONSTEXPR_IF(sizeof(_Elem) == 1) {
if (_Count <= 0) {
return 0;
}
if (_Pcvt) {
return _Mysb::xsgetn(_Ptr, _Count);
}
auto _Count_s = static_cast<size_t>(_Count);
const auto _Start_count = _Count;
const auto _Available = static_cast<size_t>(_Mysb::_Gnavail());
if (0 < _Available) {
const auto _Read_size = _Min_value(_Count_s, _Available);
_Traits::copy(_Ptr, _Mysb::gptr(), _Read_size);
_Ptr += _Read_size;
_Count_s -= _Read_size;
_Mysb::gbump(static_cast<int>(_Read_size));
}
if (_Myfile) {
_Reset_back();
constexpr size_t _Read_size = 4095;
while (_Read_size < _Count_s) {
const auto _Actual_read = _CSTD fread(_Ptr, sizeof(_Elem), _Read_size, _Myfile);
_Ptr += _Actual_read;
_Count_s -= _Actual_read;
if (_Actual_read != _Read_size) {
return static_cast<streamsize>(_Start_count - _Count_s);
}
}
if (0 < _Count_s) {
_Count_s -= _CSTD fread(_Ptr, sizeof(_Elem), _Count_s, _Myfile);
}
}
return static_cast<streamsize>(_Start_count - _Count_s);
}
else {
return _Mysb::xsgetn(_Ptr, _Count);
}
}
virtual streamsize __CLR_OR_THIS_CALL xsputn(const _Elem* _Ptr, streamsize _Count) override {
if
_CONSTEXPR_IF(sizeof(_Elem) == 1) {
if (_Pcvt) {
return _Mysb::xsputn(_Ptr, _Count);
}
const streamsize _Start_count = _Count;
streamsize _Size = _Mysb::_Pnavail();
if (0 < _Count && 0 < _Size) {
if (_Count < _Size) {
_Size = _Count;
}
_Traits::copy(_Mysb::pptr(), _Ptr, static_cast<size_t>(_Size));
_Ptr += _Size;
_Count -= _Size;
_Mysb::pbump(static_cast<int>(_Size));
}
if (0 < _Count && _Myfile) {
_Count -= _CSTD fwrite(_Ptr, sizeof(_Elem), static_cast<size_t>(_Count), _Myfile);
}
return _Start_count - _Count;
}
else {
return _Mysb::xsputn(_Ptr, _Count);
}
}
#pragma warning(pop)
virtual pos_type __CLR_OR_THIS_CALL seekoff(off_type _Off, ios_base::seekdir _Way,
ios_base::openmode = ios_base::in | ios_base::out) override {
fpos_t _Fileposition;
if (_Mysb::gptr() == &_Mychar
&& _Way == ios_base::cur
&& !_Pcvt) {
_Off -= static_cast<off_type>(sizeof(_Elem));
}
if (!_Myfile || !_Endwrite()
|| ((_Off != 0 || _Way != ios_base::cur) && _CSTD _fseeki64(_Myfile, _Off, _Way) != 0)
|| _CSTD fgetpos(_Myfile, &_Fileposition) != 0) {
return pos_type(-1);
}
_Reset_back();
return pos_type(_State, _Fileposition);
}
virtual pos_type __CLR_OR_THIS_CALL seekpos(
pos_type _Pos, ios_base::openmode = ios_base::in | ios_base::out) override {
off_type _Off = static_cast<off_type>(_Pos);
if (!_Myfile || !_Endwrite() || _CSTD fsetpos(_Myfile, &_Off) != 0) {
return pos_type(-1);
}
_State = _Pos.state();
_Reset_back();
return pos_type(_State, _Off);
}
virtual _Mysb* __CLR_OR_THIS_CALL setbuf(_Elem* _Buffer, streamsize _Count) override {
int _Mode;
if (!_Buffer && _Count == 0) {
_Mode = _IONBF;
} else {
_Mode = _IOFBF;
}
const size_t _Size = static_cast<size_t>(_Count) * sizeof(_Elem);
if (!_Myfile || _CSTD setvbuf(_Myfile, reinterpret_cast<char*>(_Buffer), _Mode, _Size) != 0) {
return nullptr;
}
_Init(_Myfile, _Openfl);
return this;
}
virtual int __CLR_OR_THIS_CALL sync() override {
if (!_Myfile || _Traits::eq_int_type(_Traits::eof(), overflow()) || 0 <= _CSTD fflush(_Myfile)) {
return 0;
}
return -1;
}
virtual void __CLR_OR_THIS_CALL imbue(const locale& _Loc) override {
_Initcvt(_STD use_facet<_Cvt>(_Loc));
}
void _Init(FILE* _File, _Initfl _Which) {
using _State_type = typename _Traits::state_type;
__PURE_APPDOMAIN_GLOBAL static _State_type _Stinit;
_Closef = _Which == _Openfl;
_Wrotesome = false;
_Mysb::_Init();
if (_File && sizeof(_Elem) == 1) {
_Elem** _Pb = nullptr;
_Elem** _Pn = nullptr;
int* _Nr = nullptr;
::_get_stream_buffer_pointers(
_File, reinterpret_cast<char***>(&_Pb), reinterpret_cast<char***>(&_Pn), &_Nr);
int* _Nw = _Nr;
_Mysb::_Init(_Pb, _Pn, _Nr, _Pb, _Pn, _Nw);
}
_Myfile = _File;
_State = _Stinit;
_Pcvt = nullptr;
}
bool _Endwrite() {
if (!_Pcvt || !_Wrotesome) {
return true;
}
if (_Traits::eq_int_type(_Traits::eof(), overflow())) {
return false;
}
constexpr size_t _Codecvt_temp_buf = 32;
char _Str[_Codecvt_temp_buf];
char* _Dest;
switch (_Pcvt->unshift(_State, _Str, _Str + _Codecvt_temp_buf, _Dest)) {
case codecvt_base::ok:
_Wrotesome = false;
case codecvt_base::partial:
{
const auto _Count = static_cast<size_t>(_Dest - _Str);
if (0 < _Count && _Count != static_cast<size_t>(_CSTD fwrite(_Str, 1, _Count, _Myfile))) {
return false;
}
return !_Wrotesome;
}
case codecvt_base::noconv:
_Wrotesome = false;
return true;
default:
return false;
}
}
void _Initcvt(const _Cvt& _Newcvt) {
if (_Newcvt.always_noconv()) {
_Pcvt = nullptr;
} else {
_Pcvt = _STD addressof(_Newcvt);
_Mysb::_Init();
}
}
private:
const _Cvt* _Pcvt;
_Elem _Mychar;
bool _Wrotesome;
typename _Traits::state_type _State;
bool _Closef;
FILE* _Myfile;
void _Reset_back() {
if (_Mysb::eback() == &_Mychar) {
_Mysb::setg(_Set_eback, _Set_eback, _Set_egptr);
}
}
void _Set_back() {
if (_Mysb::eback() != &_Mychar) {
_Set_eback = _Mysb::eback();
_Set_egptr = _Mysb::egptr();
}
_Mysb::setg(&_Mychar, &_Mychar, &_Mychar + 1);
}
_Elem* _Set_eback;
_Elem* _Set_egptr;
};
template <class _Elem, class _Traits>
void swap(basic_filebuf<_Elem, _Traits>& _Left, basic_filebuf<_Elem, _Traits>& _Right) {
_Left.swap(_Right);
}
template <class _Elem, class _Traits>
class basic_ifstream : public basic_istream<_Elem, _Traits> {
public:
using _Mybase = basic_istream<_Elem, _Traits>;
using _Myfb = basic_filebuf<_Elem, _Traits>;
using _Myios = basic_ios<_Elem, _Traits>;
basic_ifstream() : _Mybase(_STD addressof(_Filebuffer)) {}
explicit basic_ifstream(
const char* _Filename, ios_base::openmode _Mode = ios_base::in, int _Prot = ios_base::_Default_open_prot)
: _Mybase(_STD addressof(_Filebuffer)) {
if (!_Filebuffer.open(_Filename, _Mode | ios_base::in, _Prot)) {
_Myios::setstate(ios_base::failbit);
}
}
explicit basic_ifstream(
const string& _Str, ios_base::openmode _Mode = ios_base::in, int _Prot = ios_base::_Default_open_prot)
: basic_ifstream(_Str.c_str(), _Mode, _Prot) {}
explicit basic_ifstream(
const wchar_t* _Filename, ios_base::openmode _Mode = ios_base::in, int _Prot = ios_base::_Default_open_prot)
: _Mybase(_STD addressof(_Filebuffer)) {
if (!_Filebuffer.open(_Filename, _Mode | ios_base::in, _Prot)) {
_Myios::setstate(ios_base::failbit);
}
}
explicit basic_ifstream(
const wstring& _Str, ios_base::openmode _Mode = ios_base::in, int _Prot = ios_base::_Default_open_prot)
: basic_ifstream(_Str.c_str(), _Mode, _Prot) {}
#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
template <class _Path_ish = experimental::filesystem::path>
explicit basic_ifstream(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::in,
int _Prot = ios_base::_Default_open_prot)
: basic_ifstream(_Path.c_str(), _Mode, _Prot) {}
#endif
#if _HAS_CXX17
template <int = 0, class _Path_ish = filesystem::path>
explicit basic_ifstream(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::in,
int _Prot = ios_base::_Default_open_prot)
: basic_ifstream(_Path.c_str(), _Mode, _Prot) {}
#endif
#ifdef _NATIVE_WCHAR_T_DEFINED
explicit basic_ifstream(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::in,
int _Prot = ios_base::_Default_open_prot)
: _Mybase(_STD addressof(_Filebuffer)) {
if (_Filebuffer.open(_Filename, _Mode | ios_base::in, _Prot) == 0) {
_Myios::setstate(ios_base::failbit);
}
}
#endif
explicit basic_ifstream(FILE* _File) : _Mybase(_STD addressof(_Filebuffer)), _Filebuffer(_File) {}
basic_ifstream(basic_ifstream&& _Right) : _Mybase(_STD addressof(_Filebuffer)) {
_Assign_rv(_STD move(_Right));
}
basic_ifstream& operator=(basic_ifstream&& _Right) {
_Assign_rv(_STD move(_Right));
return *this;
}
void _Assign_rv(basic_ifstream&& _Right) {
if (this != _STD addressof(_Right)) {
_Filebuffer.close();
this->swap(_Right);
}
}
void swap(basic_ifstream& _Right) {
if (this != _STD addressof(_Right)) {
_Mybase::swap(_Right);
_Filebuffer.swap(_Right._Filebuffer);
}
}
basic_ifstream(const basic_ifstream&) = delete;
basic_ifstream& operator=(const basic_ifstream&) = delete;
void open(
const wchar_t* _Filename, ios_base::openmode _Mode = ios_base::in, int _Prot = ios_base::_Default_open_prot) {
if (_Filebuffer.open(_Filename, _Mode | ios_base::in, _Prot)) {
_Myios::clear();
} else {
_Myios::setstate(ios_base::failbit);
}
}
void open(const wstring& _Str, ios_base::openmode _Mode = ios_base::in, int _Prot = ios_base::_Default_open_prot) {
open(_Str.c_str(), _Mode, _Prot);
}
#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
template <class _Path_ish = experimental::filesystem::path>
void open(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::in,
int _Prot = ios_base::_Default_open_prot) {
open(_Path.c_str(), _Mode, _Prot);
}
#endif
#if _HAS_CXX17
template <int = 0, class _Path_ish = filesystem::path>
void open(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::in,
int _Prot = ios_base::_Default_open_prot) {
open(_Path.c_str(), _Mode, _Prot);
}
#endif
#if _HAS_OLD_IOSTREAMS_MEMBERS
void open(const wchar_t* _Filename, ios_base::open_mode _Mode) {
open(_Filename, static_cast<ios_base::openmode>(_Mode));
}
#endif
#ifdef _NATIVE_WCHAR_T_DEFINED
void open(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::in,
int _Prot = ios_base::_Default_open_prot) {
if (_Filebuffer.open(_Filename, _Mode | ios_base::in, _Prot) == 0) {
_Myios::setstate(ios_base::failbit);
} else {
_Myios::clear();
}
}
#if _HAS_OLD_IOSTREAMS_MEMBERS
void open(const unsigned short* _Filename, ios_base::open_mode _Mode) {
open(_Filename, static_cast<ios_base::openmode>(_Mode));
}
#endif
#endif
virtual __CLR_OR_THIS_CALL ~basic_ifstream() noexcept {}
_NODISCARD _Myfb* rdbuf() const {
return const_cast<_Myfb*>(_STD addressof(_Filebuffer));
}
_NODISCARD bool is_open() const {
return _Filebuffer.is_open();
}
void open(
const char* _Filename, ios_base::openmode _Mode = ios_base::in, int _Prot = ios_base::_Default_open_prot) {
if (_Filebuffer.open(_Filename, _Mode | ios_base::in, _Prot)) {
_Myios::clear();
} else {
_Myios::setstate(ios_base::failbit);
}
}
void open(const string& _Str, ios_base::openmode _Mode = ios_base::in, int _Prot = ios_base::_Default_open_prot) {
open(_Str.c_str(), _Mode, _Prot);
}
#if _HAS_OLD_IOSTREAMS_MEMBERS
void open(const char* _Filename, ios_base::open_mode _Mode) {
open(_Filename, static_cast<ios_base::openmode>(_Mode));
}
#endif
void close() {
if (!_Filebuffer.close()) {
_Myios::setstate(ios_base::failbit);
}
}
private:
_Myfb _Filebuffer;
};
template <class _Elem, class _Traits>
void swap(basic_ifstream<_Elem, _Traits>& _Left, basic_ifstream<_Elem, _Traits>& _Right) {
_Left.swap(_Right);
}
template <class _Elem, class _Traits>
class basic_ofstream : public basic_ostream<_Elem, _Traits> {
public:
using _Mybase = basic_ostream<_Elem, _Traits>;
using _Myfb = basic_filebuf<_Elem, _Traits>;
using _Myios = basic_ios<_Elem, _Traits>;
basic_ofstream() : _Mybase(_STD addressof(_Filebuffer)) {}
explicit basic_ofstream(const char* _Filename, ios_base::openmode _Mode = ios_base::out,
int _Prot = ios_base::_Default_open_prot)
: _Mybase(_STD addressof(_Filebuffer)) {
if (!_Filebuffer.open(_Filename, _Mode | ios_base::out, _Prot)) {
_Myios::setstate(ios_base::failbit);
}
}
explicit basic_ofstream(
const string& _Str, ios_base::openmode _Mode = ios_base::out, int _Prot = ios_base::_Default_open_prot)
: basic_ofstream(_Str.c_str(), _Mode, _Prot) {}
explicit basic_ofstream(
const wchar_t* _Filename, ios_base::openmode _Mode = ios_base::out, int _Prot = ios_base::_Default_open_prot)
: _Mybase(_STD addressof(_Filebuffer)) {
if (!_Filebuffer.open(_Filename, _Mode | ios_base::out, _Prot)) {
_Myios::setstate(ios_base::failbit);
}
}
explicit basic_ofstream(
const wstring& _Str, ios_base::openmode _Mode = ios_base::out, int _Prot = ios_base::_Default_open_prot)
: basic_ofstream(_Str.c_str(), _Mode, _Prot) {}
#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
template <class _Path_ish = experimental::filesystem::path>
explicit basic_ofstream(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::out,
int _Prot = ios_base::_Default_open_prot)
: basic_ofstream(_Path.c_str(), _Mode, _Prot) {}
#endif
#if _HAS_CXX17
template <int = 0, class _Path_ish = filesystem::path>
explicit basic_ofstream(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::out,
int _Prot = ios_base::_Default_open_prot)
: basic_ofstream(_Path.c_str(), _Mode, _Prot) {}
#endif
#ifdef _NATIVE_WCHAR_T_DEFINED
explicit basic_ofstream(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::out,
int _Prot = ios_base::_Default_open_prot)
: _Mybase(_STD addressof(_Filebuffer)) {
if (_Filebuffer.open(_Filename, _Mode | ios_base::out, _Prot) == 0) {
_Myios::setstate(ios_base::failbit);
}
}
#endif
explicit basic_ofstream(FILE* _File) : _Mybase(_STD addressof(_Filebuffer)), _Filebuffer(_File) {}
basic_ofstream(basic_ofstream&& _Right) : _Mybase(_STD addressof(_Filebuffer)) {
_Assign_rv(_STD move(_Right));
}
basic_ofstream& operator=(basic_ofstream&& _Right) {
_Assign_rv(_STD move(_Right));
return *this;
}
void _Assign_rv(basic_ofstream&& _Right) {
if (this != _STD addressof(_Right)) {
_Filebuffer.close();
this->swap(_Right);
}
}
void swap(basic_ofstream& _Right) {
if (this != _STD addressof(_Right)) {
_Mybase::swap(_Right);
_Filebuffer.swap(_Right._Filebuffer);
}
}
basic_ofstream(const basic_ofstream&) = delete;
basic_ofstream& operator=(const basic_ofstream&) = delete;
void open(
const wchar_t* _Filename, ios_base::openmode _Mode = ios_base::out, int _Prot = ios_base::_Default_open_prot) {
if (_Filebuffer.open(_Filename, _Mode | ios_base::out, _Prot)) {
_Myios::clear();
} else {
_Myios::setstate(ios_base::failbit);
}
}
void open(const wstring& _Str, ios_base::openmode _Mode = ios_base::out, int _Prot = ios_base::_Default_open_prot) {
open(_Str.c_str(), _Mode, _Prot);
}
#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
template <class _Path_ish = experimental::filesystem::path>
void open(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::out,
int _Prot = ios_base::_Default_open_prot) {
open(_Path.c_str(), _Mode, _Prot);
}
#endif
#if _HAS_CXX17
template <int = 0, class _Path_ish = filesystem::path>
void open(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::out,
int _Prot = ios_base::_Default_open_prot) {
open(_Path.c_str(), _Mode, _Prot);
}
#endif
#if _HAS_OLD_IOSTREAMS_MEMBERS
void open(const wchar_t* _Filename, ios_base::open_mode _Mode) {
open(_Filename, static_cast<ios_base::openmode>(_Mode));
}
#endif
#ifdef _NATIVE_WCHAR_T_DEFINED
void open(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::out,
int _Prot = ios_base::_Default_open_prot) {
if (_Filebuffer.open(_Filename, _Mode | ios_base::out, _Prot) == 0) {
_Myios::setstate(ios_base::failbit);
} else {
_Myios::clear();
}
}
#if _HAS_OLD_IOSTREAMS_MEMBERS
void open(const unsigned short* _Filename, ios_base::open_mode _Mode) {
open(_Filename, static_cast<ios_base::openmode>(_Mode));
}
#endif
#endif
virtual __CLR_OR_THIS_CALL ~basic_ofstream() noexcept {}
_NODISCARD _Myfb* rdbuf() const {
return const_cast<_Myfb*>(_STD addressof(_Filebuffer));
}
_NODISCARD bool is_open() const {
return _Filebuffer.is_open();
}
void open(
const char* _Filename, ios_base::openmode _Mode = ios_base::out, int _Prot = ios_base::_Default_open_prot) {
if (_Filebuffer.open(_Filename, _Mode | ios_base::out, _Prot)) {
_Myios::clear();
} else {
_Myios::setstate(ios_base::failbit);
}
}
void open(const string& _Str, ios_base::openmode _Mode = ios_base::out, int _Prot = ios_base::_Default_open_prot) {
open(_Str.c_str(), _Mode, _Prot);
}
#if _HAS_OLD_IOSTREAMS_MEMBERS
void open(const char* _Filename, ios_base::open_mode _Mode) {
open(_Filename, static_cast<ios_base::openmode>(_Mode));
}
#endif
void close() {
if (!_Filebuffer.close()) {
_Myios::setstate(ios_base::failbit);
}
}
private:
_Myfb _Filebuffer;
};
template <class _Elem, class _Traits>
void swap(basic_ofstream<_Elem, _Traits>& _Left, basic_ofstream<_Elem, _Traits>& _Right) {
_Left.swap(_Right);
}
template <class _Elem, class _Traits>
class basic_fstream : public basic_iostream<_Elem, _Traits> {
public:
using _Mybase = basic_iostream<_Elem, _Traits>;
using _Myfb = basic_filebuf<_Elem, _Traits>;
using _Myios = basic_ios<_Elem, _Traits>;
using char_type = _Elem;
using traits_type = _Traits;
using int_type = typename _Traits::int_type;
using pos_type = typename _Traits::pos_type;
using off_type = typename _Traits::off_type;
basic_fstream() : _Mybase(_STD addressof(_Filebuffer)) {}
explicit basic_fstream(const char* _Filename, ios_base::openmode _Mode = ios_base::in | ios_base::out,
int _Prot = ios_base::_Default_open_prot)
: _Mybase(_STD addressof(_Filebuffer)) {
if (!_Filebuffer.open(_Filename, _Mode, _Prot)) {
_Myios::setstate(ios_base::failbit);
}
}
explicit basic_fstream(const string& _Str, ios_base::openmode _Mode = ios_base::in | ios_base::out,
int _Prot = ios_base::_Default_open_prot)
: basic_fstream(_Str.c_str(), _Mode, _Prot) {}
explicit basic_fstream(const wchar_t* _Filename, ios_base::openmode _Mode = ios_base::in | ios_base::out,
int _Prot = ios_base::_Default_open_prot)
: _Mybase(_STD addressof(_Filebuffer)) {
if (!_Filebuffer.open(_Filename, _Mode, _Prot)) {
_Myios::setstate(ios_base::failbit);
}
}
explicit basic_fstream(const wstring& _Str, ios_base::openmode _Mode = ios_base::in | ios_base::out,
int _Prot = ios_base::_Default_open_prot)
: basic_fstream(_Str.c_str(), _Mode, _Prot) {}
#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
template <class _Path_ish = experimental::filesystem::path>
explicit basic_fstream(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::in | ios_base::out,
int _Prot = ios_base::_Default_open_prot)
: basic_fstream(_Path.c_str(), _Mode, _Prot) {}
#endif
#if _HAS_CXX17
template <int = 0, class _Path_ish = filesystem::path>
explicit basic_fstream(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::in | ios_base::out,
int _Prot = ios_base::_Default_open_prot)
: basic_fstream(_Path.c_str(), _Mode, _Prot) {}
#endif
#ifdef _NATIVE_WCHAR_T_DEFINED
explicit basic_fstream(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::in | ios_base::out,
int _Prot = ios_base::_Default_open_prot)
: _Mybase(_STD addressof(_Filebuffer)) {
if (_Filebuffer.open(_Filename, _Mode, _Prot) == 0) {
_Myios::setstate(ios_base::failbit);
}
}
#endif
explicit basic_fstream(FILE* _File) : _Mybase(_STD addressof(_Filebuffer)), _Filebuffer(_File) {}
basic_fstream(basic_fstream&& _Right) : _Mybase(_STD addressof(_Filebuffer)) {
_Assign_rv(_STD move(_Right));
}
basic_fstream& operator=(basic_fstream&& _Right) {
_Assign_rv(_STD move(_Right));
return *this;
}
void _Assign_rv(basic_fstream&& _Right) {
if (this != _STD addressof(_Right)) {
_Filebuffer.close();
this->swap(_Right);
}
}
void swap(basic_fstream& _Right) {
if (this != _STD addressof(_Right)) {
_Mybase::swap(_Right);
_Filebuffer.swap(_Right._Filebuffer);
}
}
basic_fstream(const basic_fstream&) = delete;
basic_fstream& operator=(const basic_fstream&) = delete;
void open(const wchar_t* _Filename, ios_base::openmode _Mode = ios_base::in | ios_base::out,
int _Prot = ios_base::_Default_open_prot) {
if (_Filebuffer.open(_Filename, _Mode, _Prot)) {
_Myios::clear();
} else {
_Myios::setstate(ios_base::failbit);
}
}
void open(const wstring& _Str, ios_base::openmode _Mode = ios_base::in | ios_base::out,
int _Prot = ios_base::_Default_open_prot) {
open(_Str.c_str(), _Mode, _Prot);
}
#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
template <class _Path_ish = experimental::filesystem::path>
void open(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::in | ios_base::out,
int _Prot = ios_base::_Default_open_prot) {
open(_Path.c_str(), _Mode, _Prot);
}
#endif
#if _HAS_CXX17
template <int = 0, class _Path_ish = filesystem::path>
void open(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::in | ios_base::out,
int _Prot = ios_base::_Default_open_prot) {
open(_Path.c_str(), _Mode, _Prot);
}
#endif
#if _HAS_OLD_IOSTREAMS_MEMBERS
void open(const wchar_t* _Filename, ios_base::open_mode _Mode) {
open(_Filename, static_cast<ios_base::openmode>(_Mode));
}
#endif
#ifdef _NATIVE_WCHAR_T_DEFINED
void open(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::in | ios_base::out,
int _Prot = ios_base::_Default_open_prot) {
if (_Filebuffer.open(_Filename, _Mode, _Prot) == 0) {
_Myios::setstate(ios_base::failbit);
} else {
_Myios::clear();
}
}
#if _HAS_OLD_IOSTREAMS_MEMBERS
void open(const unsigned short* _Filename, ios_base::open_mode _Mode) {
open(_Filename, static_cast<ios_base::openmode>(_Mode));
}
#endif
#endif
virtual __CLR_OR_THIS_CALL ~basic_fstream() noexcept {}
_NODISCARD _Myfb* rdbuf() const {
return const_cast<_Myfb*>(_STD addressof(_Filebuffer));
}
_NODISCARD bool is_open() const {
return _Filebuffer.is_open();
}
void open(const char* _Filename, ios_base::openmode _Mode = ios_base::in | ios_base::out,
int _Prot = ios_base::_Default_open_prot) {
if (_Filebuffer.open(_Filename, _Mode, _Prot)) {
_Myios::clear();
} else {
_Myios::setstate(ios_base::failbit);
}
}
void open(const string& _Str, ios_base::openmode _Mode = ios_base::in | ios_base::out,
int _Prot = ios_base::_Default_open_prot) {
open(_Str.c_str(), _Mode, _Prot);
}
#if _HAS_OLD_IOSTREAMS_MEMBERS
void open(const char* _Filename, ios_base::open_mode _Mode) {
open(_Filename, static_cast<ios_base::openmode>(_Mode));
}
#endif
void close() {
if (!_Filebuffer.close()) {
_Myios::setstate(ios_base::failbit);
}
}
private:
_Myfb _Filebuffer;
};
template <class _Elem, class _Traits>
void swap(basic_fstream<_Elem, _Traits>& _Left, basic_fstream<_Elem, _Traits>& _Right) {
_Left.swap(_Right);
}
_STD_END
#pragma pop_macro("new")
_STL_RESTORE_CLANG_WARNINGS
#pragma warning(pop)
#pragma pack(pop)
#endif
#endif