fstream.h | fstream.h | |||
---|---|---|---|---|
skipping to change at line 125 | skipping to change at line 125 | |||
basic_filebuf() : opened_(false) | basic_filebuf() : opened_(false) | |||
{ | { | |||
} | } | |||
~basic_filebuf() | ~basic_filebuf() | |||
{ | { | |||
} | } | |||
basic_filebuf *open(char const *s,std::ios_base::openmode mo de) | basic_filebuf *open(char const *s,std::ios_base::openmode mo de) | |||
{ | { | |||
reset_device(); | reset_device(); | |||
FILE *f = fopen(s,get_mode(mode)); | wchar_t const *smode = get_mode(mode); | |||
if(!smode) | ||||
return 0; | ||||
std::wstring name; | ||||
try { | ||||
name = convert(s); | ||||
} | ||||
catch(bad_utf const &) { | ||||
return 0; | ||||
} | ||||
FILE *f = _wfopen(name.c_str(),smode); | ||||
if(!f) | if(!f) | |||
return 0; | return 0; | |||
std::auto_ptr<io_device> dev(new details::stdio_iode v(f)); | std::auto_ptr<io_device> dev(new details::stdio_iode v(f)); | |||
device(dev); | device(dev); | |||
opened_ = true; | opened_ = true; | |||
return this; | return this; | |||
} | } | |||
basic_filebuf *close() | basic_filebuf *close() | |||
{ | { | |||
bool res = sync(); | bool res = sync(); | |||
reset_device(); | reset_device(); | |||
opened_ = false; | opened_ = false; | |||
return res ? this : 0; | return res ? this : 0; | |||
} | } | |||
bool is_open() const | bool is_open() const | |||
{ | { | |||
return opened_; | return opened_; | |||
} | } | |||
private: | private: | |||
static char const *get_mode(std::ios_base::openmode mode) | static wchar_t const *get_mode(std::ios_base::openmode mode) | |||
{ | { | |||
if(mode==(std::ios_base::in)) | // | |||
return "r"; | // done according to n2914 table 106 27.9.1.4 | |||
if(mode==(std::ios_base::out)) | // | |||
return "w"; | ||||
if(mode==(std::ios_base::out | std::ios_base::trunc) | // note can't use switch case as overload operator c | |||
) | an't be used | |||
return "w"; | // in constant expression | |||
if(mode==(std::ios_base::out | std::ios_base::app)) | if(mode == (std::ios_base::out)) | |||
return "a"; | return L"w"; | |||
if(mode==(std::ios_base::out | std::ios_base::in)) | if(mode == (std::ios_base::out | std::ios_base::app) | |||
return "r+"; | ) | |||
if(mode==(std::ios_base::out | std::ios_base::trunc | return L"a"; | |||
| std::ios_base::in)) | if(mode == (std::ios_base::app)) | |||
return "w+"; | return L"a"; | |||
if(mode==(std::ios_base::out | std::ios_base::app | | if(mode == (std::ios_base::out | std::ios_base::trun | |||
std::ios_base::in)) | c)) | |||
return "a+"; | return L"w"; | |||
if(mode==(std::ios_base::binary | std::ios_base::in) | if(mode == (std::ios_base::in)) | |||
) | return L"r"; | |||
return "rb"; | if(mode == (std::ios_base::in | std::ios_base::out)) | |||
if(mode==(std::ios_base::binary | std::ios_base::out | return L"r+"; | |||
)) | if(mode == (std::ios_base::in | std::ios_base::out | | |||
return "wb"; | std::ios_base::trunc)) | |||
if(mode==(std::ios_base::binary | std::ios_base::out | return L"w+"; | |||
| std::ios_base::trunc)) | if(mode == (std::ios_base::in | std::ios_base::out | | |||
return "wb"; | std::ios_base::app)) | |||
if(mode==(std::ios_base::binary | std::ios_base::out | return L"a+"; | |||
| std::ios_base::app)) | if(mode == (std::ios_base::in | std::ios_base::app)) | |||
return "ab"; | return L"a+"; | |||
if(mode==(std::ios_base::binary | std::ios_base::out | if(mode == (std::ios_base::binary | std::ios_base::o | |||
| std::ios_base::in)) | ut)) | |||
return "r+b"; | return L"wb"; | |||
if(mode==(std::ios_base::binary | std::ios_base::out | if(mode == (std::ios_base::binary | std::ios_base::o | |||
| std::ios_base::trunc | std::ios_base::in)) | ut | std::ios_base::app)) | |||
return "w+b"; | return L"ab"; | |||
if(mode==(std::ios_base::binary | std::ios_base::out | if(mode == (std::ios_base::binary | std::ios_base::a | |||
| std::ios_base::app | std::ios_base::in)) | pp)) | |||
return "a+b"; | return L"ab"; | |||
return ""; | if(mode == (std::ios_base::binary | std::ios_base::o | |||
ut | std::ios_base::trunc)) | ||||
return L"wb"; | ||||
if(mode == (std::ios_base::binary | std::ios_base::i | ||||
n)) | ||||
return L"rb"; | ||||
if(mode == (std::ios_base::binary | std::ios_base::i | ||||
n | std::ios_base::out)) | ||||
return L"r+b"; | ||||
if(mode == (std::ios_base::binary | std::ios_base::i | ||||
n | std::ios_base::out | std::ios_base::trunc)) | ||||
return L"w+b"; | ||||
if(mode == (std::ios_base::binary | std::ios_base::i | ||||
n | std::ios_base::out | std::ios_base::app)) | ||||
return L"a+b"; | ||||
if(mode == (std::ios_base::binary | std::ios_base::i | ||||
n | std::ios_base::app)) | ||||
return L"a+b"; | ||||
return 0; | ||||
} | } | |||
bool opened_; | bool opened_; | |||
}; | }; | |||
#endif | #endif | |||
/// | /// | |||
/// Same as std::basic_ifstream<char> but accepts UTF-8 strings unde r Windows | /// Same as std::basic_ifstream<char> but accepts UTF-8 strings unde r Windows | |||
/// | /// | |||
End of changes. 3 change blocks. | ||||
41 lines changed or deleted | 69 lines changed or added | |||