C++ Utilities  4.14.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
nativefilestream.h
Go to the documentation of this file.
1 #ifndef IOUTILITIES_NATIVE_FILE_STREAM
2 #define IOUTILITIES_NATIVE_FILE_STREAM
3 
4 #include "../global.h"
5 
6 #ifndef PLATFORM_MINGW
7 #include <fstream>
8 #else
9 #include <ext/stdio_filebuf.h>
10 #include <iostream>
11 #include <memory>
12 #include <string>
13 #endif
14 
15 namespace IoUtilities {
16 
17 #if !defined(PLATFORM_MINGW) || !defined(CPP_UTILITIES_USE_NATIVE_FILE_BUFFER)
18 
19 typedef std::fstream NativeFileStream;
20 
21 #else
22 
23 class CPP_UTILITIES_EXPORT NativeFileStream : public std::iostream {
24 public:
27 
28  bool is_open() const;
29  void open(const std::string &path, std::ios_base::openmode flags);
30  void close();
31 
32 private:
33  std::unique_ptr<__gnu_cxx::stdio_filebuf<char>> m_filebuf;
34  std::__c_file m_cfile;
35 };
36 
37 inline bool NativeFileStream::is_open() const
38 {
39  return m_filebuf && m_filebuf->is_open();
40 }
41 
42 #endif
43 } // namespace IoUtilities
44 
45 #endif // IOUTILITIES_NATIVE_FILE_STREAM
Contains utility classes helping to read and write streams.
Definition: binaryreader.h:10
std::fstream NativeFileStream
#define CPP_UTILITIES_EXPORT
Marks the symbol to be exported by the c++utilities library.