2021-04-28 12:43:51 +08:00
|
|
|
#ifndef AL_FSTREAM_H
|
|
|
|
#define AL_FSTREAM_H
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
|
|
|
|
namespace al {
|
|
|
|
|
2023-02-04 15:03:54 +08:00
|
|
|
// Inherit from std::ifstream to accept UTF-8 filenames
|
|
|
|
class ifstream final : public std::ifstream {
|
2021-04-28 12:43:51 +08:00
|
|
|
public:
|
2023-02-04 15:03:54 +08:00
|
|
|
explicit ifstream(const char *filename, std::ios_base::openmode mode=std::ios_base::in);
|
|
|
|
explicit ifstream(const std::string &filename, std::ios_base::openmode mode=std::ios_base::in)
|
|
|
|
: ifstream{filename.c_str(), mode} { }
|
2021-04-28 12:43:51 +08:00
|
|
|
|
2023-02-04 15:03:54 +08:00
|
|
|
explicit ifstream(const wchar_t *filename, std::ios_base::openmode mode=std::ios_base::in)
|
|
|
|
: std::ifstream{filename, mode} { }
|
|
|
|
explicit ifstream(const std::wstring &filename, std::ios_base::openmode mode=std::ios_base::in)
|
|
|
|
: ifstream{filename.c_str(), mode} { }
|
2021-04-28 12:43:51 +08:00
|
|
|
|
2023-02-04 15:03:54 +08:00
|
|
|
void open(const char *filename, std::ios_base::openmode mode=std::ios_base::in);
|
|
|
|
void open(const std::string &filename, std::ios_base::openmode mode=std::ios_base::in)
|
|
|
|
{ open(filename.c_str(), mode); }
|
2021-04-28 12:43:51 +08:00
|
|
|
|
|
|
|
~ifstream() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace al
|
|
|
|
|
|
|
|
#else /* _WIN32 */
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
namespace al {
|
|
|
|
|
|
|
|
using ifstream = std::ifstream;
|
|
|
|
|
|
|
|
} // namespace al
|
|
|
|
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
|
|
|
#endif /* AL_FSTREAM_H */
|