C++ Utilities  4.6.1
Common C++ classes and routines used by my applications 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 <memory>
10 # include <string>
11 # include <iostream>
12 # include <ext/stdio_filebuf.h>
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 {
25 public:
27  ~NativeFileStream();
28 
29  bool is_open() const;
30  void open(const std::string &path, std::ios_base::openmode flags);
31  void close();
32 
33 private:
34  std::unique_ptr<__gnu_cxx::stdio_filebuf<char> > m_filebuf;
35  std::__c_file m_cfile;
36 };
37 
38 inline bool NativeFileStream::is_open() const
39 {
40  return m_filebuf && m_filebuf->is_open();
41 }
42 
43 #endif
44 
45 }
46 
47 #endif // IOUTILITIES_NATIVE_FILE_STREAM
48 
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.