aboutsummaryrefslogtreecommitdiffstats
path: root/alc/compat.h
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-09-22 12:23:41 -0700
committerChris Robinson <[email protected]>2019-09-22 12:23:41 -0700
commit95996effaf04c87b7091c904e6545bc1e5e25aee (patch)
tree70068093db98249b3fb33dc3c52b6079630bcd46 /alc/compat.h
parent9c95f62e95a76059548762f2e7d2e9bb0e8d4631 (diff)
Move the ifstream wrapper to common
Diffstat (limited to 'alc/compat.h')
-rw-r--r--alc/compat.h66
1 files changed, 0 insertions, 66 deletions
diff --git a/alc/compat.h b/alc/compat.h
index f2e10513..960b4b94 100644
--- a/alc/compat.h
+++ b/alc/compat.h
@@ -1,72 +1,6 @@
#ifndef AL_COMPAT_H
#define AL_COMPAT_H
-#ifdef _WIN32
-
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-
-#include <array>
-#include <string>
-#include <fstream>
-
-
-namespace al {
-
-// Windows' std::ifstream fails with non-ANSI paths since the standard only
-// specifies names using const char* (or std::string). MSVC has a non-standard
-// extension using const wchar_t* (or std::wstring?) to handle Unicode paths,
-// but not all Windows compilers support it. So we have to make our own istream
-// that accepts UTF-8 paths and forwards to Unicode-aware I/O functions.
-class filebuf final : public std::streambuf {
- std::array<char_type,4096> mBuffer;
- HANDLE mFile{INVALID_HANDLE_VALUE};
-
- int_type underflow() override;
- pos_type seekoff(off_type offset, std::ios_base::seekdir whence, std::ios_base::openmode mode) override;
- pos_type seekpos(pos_type pos, std::ios_base::openmode mode) override;
-
-public:
- filebuf() = default;
- ~filebuf() override;
-
- bool open(const wchar_t *filename, std::ios_base::openmode mode);
- bool open(const char *filename, std::ios_base::openmode mode);
-
- bool is_open() const noexcept { return mFile != INVALID_HANDLE_VALUE; }
-};
-
-// Inherit from std::istream to use our custom streambuf
-class ifstream final : public std::istream {
- filebuf mStreamBuf;
-
-public:
- ifstream(const wchar_t *filename, std::ios_base::openmode mode = std::ios_base::in);
- ifstream(const std::wstring &filename, std::ios_base::openmode mode = std::ios_base::in)
- : ifstream(filename.c_str(), mode) { }
- ifstream(const char *filename, std::ios_base::openmode mode = std::ios_base::in);
- ifstream(const std::string &filename, std::ios_base::openmode mode = std::ios_base::in)
- : ifstream(filename.c_str(), mode) { }
- ~ifstream() override;
-
- bool is_open() const noexcept { return mStreamBuf.is_open(); }
-};
-
-} // namespace al
-
-#else /* _WIN32 */
-
-#include <fstream>
-
-namespace al {
-
-using filebuf = std::filebuf;
-using ifstream = std::ifstream;
-
-} // namespace al
-
-#endif /* _WIN32 */
-
#include <string>
struct PathNamePair { std::string path, fname; };