fstream.hpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. // boost/filesystem/fstream.hpp ------------------------------------------------------//
  2. // Copyright Beman Dawes 2002
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // See http://www.boost.org/LICENSE_1_0.txt
  5. // Library home page: http://www.boost.org/libs/filesystem
  6. //--------------------------------------------------------------------------------------//
  7. #ifndef BOOST_FILESYSTEM3_FSTREAM_HPP
  8. #define BOOST_FILESYSTEM3_FSTREAM_HPP
  9. #include <boost/config.hpp>
  10. # if defined( BOOST_NO_STD_WSTRING )
  11. # error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
  12. # endif
  13. #include <boost/filesystem/path.hpp>
  14. #include <iosfwd>
  15. #include <fstream>
  16. #include <boost/config/abi_prefix.hpp> // must be the last #include
  17. // on Windows, except for standard libaries known to have wchar_t overloads for
  18. // file stream I/O, use path::string() to get a narrow character c_str()
  19. #if defined(BOOST_WINDOWS_API) \
  20. && (!defined(_CPPLIB_VER) || _CPPLIB_VER < 405 || defined(_STLPORT_VERSION))
  21. // !Dinkumware || early Dinkumware || STLPort masquerading as Dinkumware
  22. # define BOOST_FILESYSTEM_C_STR string().c_str() // use narrow, since wide not available
  23. #else // use the native c_str, which will be narrow on POSIX, wide on Windows
  24. # define BOOST_FILESYSTEM_C_STR c_str()
  25. #endif
  26. #if defined(BOOST_MSVC)
  27. #pragma warning(push)
  28. // 'boost::filesystem::basic_fstream<charT>' : inherits 'std::basic_istream<_Elem,_Traits>::std::basic_istream<_Elem,_Traits>::_Add_vtordisp1' via dominance
  29. #pragma warning(disable: 4250)
  30. #endif
  31. namespace boost
  32. {
  33. namespace filesystem
  34. {
  35. //--------------------------------------------------------------------------------------//
  36. // basic_filebuf //
  37. //--------------------------------------------------------------------------------------//
  38. template < class charT, class traits = std::char_traits<charT> >
  39. class basic_filebuf : public std::basic_filebuf<charT,traits>
  40. {
  41. private: // disallow copying
  42. basic_filebuf(const basic_filebuf&);
  43. const basic_filebuf& operator=(const basic_filebuf&);
  44. public:
  45. basic_filebuf() {}
  46. virtual ~basic_filebuf() {}
  47. basic_filebuf<charT,traits>*
  48. open(const path& p, std::ios_base::openmode mode)
  49. {
  50. return std::basic_filebuf<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode)
  51. ? this : 0;
  52. }
  53. };
  54. //--------------------------------------------------------------------------------------//
  55. // basic_ifstream //
  56. //--------------------------------------------------------------------------------------//
  57. template < class charT, class traits = std::char_traits<charT> >
  58. class basic_ifstream : public std::basic_ifstream<charT,traits>
  59. {
  60. private: // disallow copying
  61. basic_ifstream(const basic_ifstream&);
  62. const basic_ifstream& operator=(const basic_ifstream&);
  63. public:
  64. basic_ifstream() {}
  65. // use two signatures, rather than one signature with default second
  66. // argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416)
  67. explicit basic_ifstream(const path& p)
  68. : std::basic_ifstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in) {}
  69. basic_ifstream(const path& p, std::ios_base::openmode mode)
  70. : std::basic_ifstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, mode) {}
  71. void open(const path& p)
  72. { std::basic_ifstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in); }
  73. void open(const path& p, std::ios_base::openmode mode)
  74. { std::basic_ifstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode); }
  75. virtual ~basic_ifstream() {}
  76. };
  77. //--------------------------------------------------------------------------------------//
  78. // basic_ofstream //
  79. //--------------------------------------------------------------------------------------//
  80. template < class charT, class traits = std::char_traits<charT> >
  81. class basic_ofstream : public std::basic_ofstream<charT,traits>
  82. {
  83. private: // disallow copying
  84. basic_ofstream(const basic_ofstream&);
  85. const basic_ofstream& operator=(const basic_ofstream&);
  86. public:
  87. basic_ofstream() {}
  88. // use two signatures, rather than one signature with default second
  89. // argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416)
  90. explicit basic_ofstream(const path& p)
  91. : std::basic_ofstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, std::ios_base::out) {}
  92. basic_ofstream(const path& p, std::ios_base::openmode mode)
  93. : std::basic_ofstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, mode) {}
  94. void open(const path& p)
  95. { std::basic_ofstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, std::ios_base::out); }
  96. void open(const path& p, std::ios_base::openmode mode)
  97. { std::basic_ofstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode); }
  98. virtual ~basic_ofstream() {}
  99. };
  100. //--------------------------------------------------------------------------------------//
  101. // basic_fstream //
  102. //--------------------------------------------------------------------------------------//
  103. template < class charT, class traits = std::char_traits<charT> >
  104. class basic_fstream : public std::basic_fstream<charT,traits>
  105. {
  106. private: // disallow copying
  107. basic_fstream(const basic_fstream&);
  108. const basic_fstream & operator=(const basic_fstream&);
  109. public:
  110. basic_fstream() {}
  111. // use two signatures, rather than one signature with default second
  112. // argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416)
  113. explicit basic_fstream(const path& p)
  114. : std::basic_fstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR,
  115. std::ios_base::in | std::ios_base::out) {}
  116. basic_fstream(const path& p, std::ios_base::openmode mode)
  117. : std::basic_fstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, mode) {}
  118. void open(const path& p)
  119. { std::basic_fstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR,
  120. std::ios_base::in | std::ios_base::out); }
  121. void open(const path& p, std::ios_base::openmode mode)
  122. { std::basic_fstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode); }
  123. virtual ~basic_fstream() {}
  124. };
  125. //--------------------------------------------------------------------------------------//
  126. // typedefs //
  127. //--------------------------------------------------------------------------------------//
  128. typedef basic_filebuf<char> filebuf;
  129. typedef basic_ifstream<char> ifstream;
  130. typedef basic_ofstream<char> ofstream;
  131. typedef basic_fstream<char> fstream;
  132. typedef basic_filebuf<wchar_t> wfilebuf;
  133. typedef basic_ifstream<wchar_t> wifstream;
  134. typedef basic_ofstream<wchar_t> wofstream;
  135. typedef basic_fstream<wchar_t> wfstream;
  136. } // namespace filesystem
  137. } // namespace boost
  138. #if defined(BOOST_MSVC)
  139. #pragma warning(pop)
  140. #endif
  141. #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
  142. #endif // BOOST_FILESYSTEM3_FSTREAM_HPP