diff options
-rw-r--r-- | libbutl/fdstream.cxx | 8 | ||||
-rw-r--r-- | libbutl/fdstream.ixx | 56 | ||||
-rw-r--r-- | libbutl/fdstream.mxx | 74 | ||||
-rw-r--r-- | tests/cpfile/driver.cxx | 4 | ||||
-rw-r--r-- | tests/fdstream/driver.cxx | 6 |
5 files changed, 105 insertions, 43 deletions
diff --git a/libbutl/fdstream.cxx b/libbutl/fdstream.cxx index 9bc62d9..053ef13 100644 --- a/libbutl/fdstream.cxx +++ b/libbutl/fdstream.cxx @@ -785,13 +785,13 @@ namespace butl // ifdstream:: ifdstream (const char* f, openmode m, iostate e) - : ifdstream (f, translate_mode (m | in), e) // Delegate. + : ifdstream (f, translate_mode (m | in), e) { } ifdstream:: ifdstream (const char* f, fdopen_mode m, iostate e) - : ifdstream (fdopen (f, m | fdopen_mode::in), e) // Delegate. + : ifdstream (fdopen (f, m | fdopen_mode::in), e) { } @@ -886,13 +886,13 @@ namespace butl // ofdstream:: ofdstream (const char* f, openmode m, iostate e) - : ofdstream (f, translate_mode (m | out), e) // Delegate. + : ofdstream (f, translate_mode (m | out), e) { } ofdstream:: ofdstream (const char* f, fdopen_mode m, iostate e) - : ofdstream (fdopen (f, m | fdopen_mode::out), e) // Delegate. + : ofdstream (fdopen (f, m | fdopen_mode::out), e) { } diff --git a/libbutl/fdstream.ixx b/libbutl/fdstream.ixx index 5c325b0..531f196 100644 --- a/libbutl/fdstream.ixx +++ b/libbutl/fdstream.ixx @@ -63,7 +63,7 @@ namespace butl inline ifdstream:: ifdstream (iostate e) - : ifdstream (auto_fd (), e) // Delegate. + : ifdstream (auto_fd (), e) { } @@ -79,25 +79,43 @@ namespace butl inline ifdstream:: ifdstream (const std::string& f, openmode m, iostate e) - : ifdstream (f.c_str (), m, e) // Delegate. + : ifdstream (f.c_str (), m, e) { } inline ifdstream:: ifdstream (const path& f, openmode m, iostate e) - : ifdstream (f.string (), m, e) // Delegate. + : ifdstream (f.string (), m, e) { } inline ifdstream:: ifdstream (const std::string& f, fdopen_mode m, iostate e) - : ifdstream (f.c_str (), m, e) // Delegate. + : ifdstream (f.c_str (), m, e) { } inline ifdstream:: ifdstream (const path& f, fdopen_mode m, iostate e) - : ifdstream (f.string (), m, e) // Delegate. + : ifdstream (f.string (), m, e) + { + } + + inline ifdstream:: + ifdstream (const char* f, iostate e) + : ifdstream (f, in, e) + { + } + + inline ifdstream:: + ifdstream (const std::string& f, iostate e) + : ifdstream (f, in, e) + { + } + + inline ifdstream:: + ifdstream (const path& f, iostate e) + : ifdstream (f, in, e) { } @@ -165,7 +183,7 @@ namespace butl inline ofdstream:: ofdstream (iostate e) - : ofdstream (auto_fd (), e) // Delegate. + : ofdstream (auto_fd (), e) { } @@ -179,25 +197,43 @@ namespace butl inline ofdstream:: ofdstream (const std::string& f, openmode m, iostate e) - : ofdstream (f.c_str (), m, e) // Delegate. + : ofdstream (f.c_str (), m, e) { } inline ofdstream:: ofdstream (const path& f, openmode m, iostate e) - : ofdstream (f.string (), m, e) // Delegate. + : ofdstream (f.string (), m, e) { } inline ofdstream:: ofdstream (const std::string& f, fdopen_mode m, iostate e) - : ofdstream (f.c_str (), m, e) // Delegate. + : ofdstream (f.c_str (), m, e) { } inline ofdstream:: ofdstream (const path& f, fdopen_mode m, iostate e) - : ofdstream (f.string (), m, e) // Delegate. + : ofdstream (f.string (), m, e) + { + } + + inline ofdstream:: + ofdstream (const char* f, iostate e) + : ofdstream (f, out, e) + { + } + + inline ofdstream:: + ofdstream (const std::string& f, iostate e) + : ofdstream (f, out, e) + { + } + + inline ofdstream:: + ofdstream (const path& f, iostate e) + : ofdstream (f, out, e) { } diff --git a/libbutl/fdstream.mxx b/libbutl/fdstream.mxx index a3d9039..49c5dae 100644 --- a/libbutl/fdstream.mxx +++ b/libbutl/fdstream.mxx @@ -442,44 +442,57 @@ LIBBUTL_MODEXPORT namespace butl // Create an unopened object. // explicit - ifdstream (iostate e = badbit | failbit); + ifdstream (iostate = badbit | failbit); explicit ifdstream (auto_fd&&, - iostate e = badbit | failbit, + iostate = badbit | failbit, std::uint64_t pos = 0); ifdstream (auto_fd&&, fdstream_mode m, - iostate e = badbit | failbit, + iostate = badbit | failbit, std::uint64_t pos = 0); explicit ifdstream (const char*, - openmode = in, - iostate e = badbit | failbit); + iostate = badbit | failbit); explicit ifdstream (const std::string&, - openmode = in, - iostate e = badbit | failbit); + iostate = badbit | failbit); explicit ifdstream (const path&, - openmode = in, - iostate e = badbit | failbit); + iostate = badbit | failbit); + + // @@ In some implementations (for example, MSVC), iostate and openmode + // (and/or their respective constants) are not distinct enough which + // causes overload resolution errors. + // + ifdstream (const char*, + openmode, + iostate /*= badbit | failbit*/); + + ifdstream (const std::string&, + openmode, + iostate /*= badbit | failbit*/); + + ifdstream (const path&, + openmode, + iostate /*= badbit | failbit*/); ifdstream (const char*, fdopen_mode, - iostate e = badbit | failbit); + iostate = badbit | failbit); ifdstream (const std::string&, fdopen_mode, - iostate e = badbit | failbit); + iostate = badbit | failbit); ifdstream (const path&, fdopen_mode, - iostate e = badbit | failbit); + iostate = badbit | failbit); ~ifdstream () override; @@ -548,44 +561,57 @@ LIBBUTL_MODEXPORT namespace butl // Create an unopened object. // explicit - ofdstream (iostate e = badbit | failbit); + ofdstream (iostate = badbit | failbit); explicit ofdstream (auto_fd&&, - iostate e = badbit | failbit, + iostate = badbit | failbit, std::uint64_t pos = 0); ofdstream (auto_fd&&, fdstream_mode m, - iostate e = badbit | failbit, + iostate = badbit | failbit, std::uint64_t pos = 0); explicit ofdstream (const char*, - openmode = out, - iostate e = badbit | failbit); + iostate = badbit | failbit); explicit ofdstream (const std::string&, - openmode = out, - iostate e = badbit | failbit); + iostate = badbit | failbit); explicit ofdstream (const path&, - openmode = out, - iostate e = badbit | failbit); + iostate = badbit | failbit); + + // @@ In some implementations (for example, MSVC), iostate and openmode + // (and/or their respective constants) are not distinct enough which + // causes overload resolution errors. + // + ofdstream (const char*, + openmode, + iostate /*= badbit | failbit*/); + + ofdstream (const std::string&, + openmode, + iostate /*= badbit | failbit*/); + + ofdstream (const path&, + openmode, + iostate /*= badbit | failbit*/); ofdstream (const char*, fdopen_mode, - iostate e = badbit | failbit); + iostate = badbit | failbit); ofdstream (const std::string&, fdopen_mode, - iostate e = badbit | failbit); + iostate = badbit | failbit); ofdstream (const path&, fdopen_mode, - iostate e = badbit | failbit); + iostate = badbit | failbit); ~ofdstream () override; diff --git a/tests/cpfile/driver.cxx b/tests/cpfile/driver.cxx index 5576a4f..e2ecc04 100644 --- a/tests/cpfile/driver.cxx +++ b/tests/cpfile/driver.cxx @@ -36,7 +36,7 @@ static const char text3[] = "XAB\r\n9"; static string from_file (const path& f) { - ifdstream ifs (f, ios::binary); + ifdstream ifs (f, fdopen_mode::binary); string s (ifs.read_text ()); ifs.close (); // Not to miss failed close of the underlying file descriptor. return s; @@ -45,7 +45,7 @@ from_file (const path& f) static void to_file (const path& f, const char* s) { - ofdstream ofs (f, ios::binary); + ofdstream ofs (f, fdopen_mode::binary); ofs << s; ofs.close (); } diff --git a/tests/fdstream/driver.cxx b/tests/fdstream/driver.cxx index 58b7012..748259e 100644 --- a/tests/fdstream/driver.cxx +++ b/tests/fdstream/driver.cxx @@ -92,7 +92,7 @@ static duration write_time (const path& p, const T& s, size_t n) { timestamp t (system_clock::now ()); - S os (p.string (), ofstream::out); + S os (p.string ()); os.exceptions (S::failbit | S::badbit); for (size_t i (0); i < n; ++i) @@ -114,7 +114,7 @@ read_time (const path& p, const T& s, size_t n) vector<T> v (n); timestamp t (system_clock::now ()); - S is (p.string (), ofstream::in); + S is (p.string ()); is.exceptions (S::failbit | S::badbit); for (auto& ve: v) @@ -701,7 +701,7 @@ main (int argc, const char* argv[]) // Seek for read in the binary mode. // { - ifdstream is (f, ios::binary); + ifdstream is (f, fdopen_mode::binary); char c; is.get (c); |