8 #ifndef BOOST_NOWIDE_FSTREAM_HPP_INCLUDED 9 #define BOOST_NOWIDE_FSTREAM_HPP_INCLUDED 12 #include <boost/nowide/filebuf.hpp> 23 static std::ios_base::openmode mode() {
return std::ios_base::in; }
24 static std::ios_base::openmode mode_modifier() {
return mode(); }
25 template<
typename CharType,
typename Traits>
27 typedef std::basic_istream<CharType, Traits> type;
32 static std::ios_base::openmode mode() {
return std::ios_base::out; }
33 static std::ios_base::openmode mode_modifier() {
return mode(); }
34 template<
typename CharType,
typename Traits>
36 typedef std::basic_ostream<CharType, Traits> type;
39 struct StreamTypeInOut
41 static std::ios_base::openmode mode() {
return std::ios_base::in | std::ios_base::out; }
42 static std::ios_base::openmode mode_modifier() {
return std::ios_base::openmode(); }
43 template<
typename CharType,
typename Traits>
45 typedef std::basic_iostream<CharType, Traits> type;
56 template<
typename CharType,
typename Traits,
typename T_StreamType>
59 template<
typename Path,
typename Result>
60 struct enable_if_path;
67 template<
typename CharType,
typename Traits = std::
char_traits<CharType> >
76 explicit basic_ifstream(
const char* file_name, std::ios_base::openmode mode = std::ios_base::in)
78 open(file_name, mode);
80 #if BOOST_NOWIDE_USE_WCHAR_OVERLOADS 81 explicit basic_ifstream(
const wchar_t* file_name, std::ios_base::openmode mode = std::ios_base::in)
83 open(file_name, mode);
87 explicit basic_ifstream(
const std::string& file_name, std::ios_base::openmode mode = std::ios_base::in)
89 open(file_name, mode);
92 template<
typename Path>
94 const Path& file_name,
97 open(file_name, mode);
99 using fstream_impl::open;
100 using fstream_impl::is_open;
101 using fstream_impl::close;
102 using fstream_impl::rdbuf;
103 #if BOOST_NOWIDE_CXX11 104 using fstream_impl::swap;
111 fstream_impl::operator=(std::move(rhs));
121 template<
typename CharType,
typename Traits = std::
char_traits<CharType> >
129 explicit basic_ofstream(
const char* file_name, std::ios_base::openmode mode = std::ios_base::out)
131 open(file_name, mode);
133 #if BOOST_NOWIDE_USE_WCHAR_OVERLOADS 134 explicit basic_ofstream(
const wchar_t* file_name, std::ios_base::openmode mode = std::ios_base::out)
136 open(file_name, mode);
139 explicit basic_ofstream(
const std::string& file_name, std::ios_base::openmode mode = std::ios_base::out)
141 open(file_name, mode);
143 template<
typename Path>
145 const Path& file_name,
148 open(file_name, mode);
151 using fstream_impl::open;
152 using fstream_impl::is_open;
153 using fstream_impl::close;
154 using fstream_impl::rdbuf;
155 #if BOOST_NOWIDE_CXX11 156 using fstream_impl::swap;
163 fstream_impl::operator=(std::move(rhs));
170 #pragma warning(push) 171 #pragma warning(disable : 4250) // <class> : inherits <method> via dominance 173 template<
typename CharType,
typename Traits = std::
char_traits<CharType> >
185 std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out)
187 open(file_name, mode);
189 #if BOOST_NOWIDE_USE_WCHAR_OVERLOADS 191 std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out)
193 open(file_name, mode);
197 std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out)
199 open(file_name, mode);
201 template<
typename Path>
204 std::ios_base::in | std::ios_base::out)
206 open(file_name, mode);
209 using fstream_impl::open;
210 using fstream_impl::is_open;
211 using fstream_impl::close;
212 using fstream_impl::rdbuf;
213 #if BOOST_NOWIDE_CXX11 214 using fstream_impl::swap;
221 fstream_impl::operator=(std::move(rhs));
226 #if BOOST_NOWIDE_CXX11 227 template<
typename CharType,
typename Traits>
232 template<
typename CharType,
typename Traits>
233 void swap(basic_ifstream<CharType, Traits>& lhs, basic_ifstream<CharType, Traits>& rhs)
237 template<
typename CharType,
typename Traits>
238 void swap(basic_ofstream<CharType, Traits>& lhs, basic_ofstream<CharType, Traits>& rhs)
242 template<
typename CharType,
typename Traits>
243 void swap(basic_fstream<CharType, Traits>& lhs, basic_fstream<CharType, Traits>& rhs)
252 typedef basic_filebuf<char>
filebuf;
278 template<
typename CharType,
typename Traits,
typename T_StreamType>
280 public T_StreamType::template stream_base<CharType, Traits>::type
284 typedef typename T_StreamType::template stream_base<CharType, Traits>::type stream_base;
287 using stream_base::setstate;
288 using stream_base::clear;
291 using base_buf_holder::buf_;
296 #if BOOST_NOWIDE_CXX11 302 stream_base(std::move(other))
304 this->set_rdbuf(rdbuf());
308 base_buf_holder::operator=(std::move(rhs));
309 stream_base::operator=(std::move(rhs));
314 stream_base::swap(other);
315 rdbuf()->swap(*other.rdbuf());
319 void open(
const std::string& file_name, std::ios_base::openmode mode = T_StreamType::mode())
321 open(file_name.c_str(), mode);
323 template<
typename Path>
325 std::ios_base::openmode mode = T_StreamType::mode())
327 open(file_name.c_str(), mode);
329 void open(
const char* file_name, std::ios_base::openmode mode = T_StreamType::mode())
331 if(!rdbuf()->open(file_name, mode | T_StreamType::mode_modifier()))
332 setstate(std::ios_base::failbit);
336 #if BOOST_NOWIDE_USE_WCHAR_OVERLOADS 337 void open(
const wchar_t* file_name, std::ios_base::openmode mode = T_StreamType::mode())
339 if(!rdbuf()->open(file_name, mode | T_StreamType::mode_modifier()))
340 setstate(std::ios_base::failbit);
347 return rdbuf()->is_open();
351 return rdbuf()->is_open();
355 if(!rdbuf()->close())
356 setstate(std::ios_base::failbit);
361 return const_cast<internal_buffer_type*>(&buf_);
378 template<
typename U, U& (U::*)(), U (U::*)() const>
381 static one test(Check<U, &U::make_preferred, &U::filename>*);
383 static two test(...);
388 value =
sizeof(test<T>(0)) ==
sizeof(one)
391 template<
bool B,
typename T>
400 template<
typename Path,
typename Result>
Definition: fstream.hpp:279
basic_ifstream< char > ifstream
Definition: fstream.hpp:257
basic_filebuf< char > filebuf
Convenience typedef.
Definition: filebuf.hpp:458
Same as std::basic_ifstream<char> but accepts UTF-8 strings under Windows.
Definition: fstream.hpp:68
basic_ofstream< char > ofstream
Definition: fstream.hpp:262
This forward declaration defines the basic_filebuf type.
Definition: filebuf.hpp:40
Definition: fstream.hpp:370
Same as std::basic_fstream<char> but accepts UTF-8 strings under Windows.
Definition: fstream.hpp:177
Same as std::basic_ofstream<char> but accepts UTF-8 strings under Windows.
Definition: fstream.hpp:122
basic_fstream< char > fstream
Definition: fstream.hpp:267
Definition: fstream.hpp:392
SFINAE trait which has a member "type = Result" if the Path is a *::filesystem::path.
Definition: fstream.hpp:401
Definition: fstream.hpp:274