File indexing completed on 2025-01-30 09:35:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef BOOST_FILESYSTEM_FSTREAM_HPP
0014 #define BOOST_FILESYSTEM_FSTREAM_HPP
0015
0016 #include <boost/filesystem/config.hpp>
0017 #include <boost/filesystem/path.hpp>
0018 #include <cstddef>
0019 #include <iosfwd>
0020 #include <fstream>
0021
0022 #include <boost/filesystem/detail/header.hpp> // must be the last #include
0023
0024 #if defined(BOOST_WINDOWS_API)
0025
0026
0027 #if (defined(_CPPLIB_VER) && _CPPLIB_VER >= 405 && !defined(_STLPORT_VERSION)) || \
0028 (defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 7000 && defined(_LIBCPP_HAS_OPEN_WITH_WCHAR))
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 #define BOOST_FILESYSTEM_C_STR(p) p.c_str()
0040 #else
0041
0042 #define BOOST_FILESYSTEM_C_STR(p) p.string().c_str()
0043 #endif
0044 #endif
0045
0046 #if !defined(BOOST_FILESYSTEM_C_STR)
0047 #define BOOST_FILESYSTEM_C_STR(p) p.c_str()
0048 #endif
0049
0050 #if defined(BOOST_MSVC)
0051 #pragma warning(push)
0052
0053 #pragma warning(disable : 4250)
0054 #endif
0055
0056 namespace boost {
0057 namespace filesystem {
0058
0059
0060
0061
0062
0063 template< class Char, class Traits = std::char_traits< Char > >
0064 class basic_filebuf :
0065 public std::basic_filebuf< Char, Traits >
0066 {
0067 private:
0068 typedef std::basic_filebuf< Char, Traits > base_type;
0069
0070 public:
0071 BOOST_DEFAULTED_FUNCTION(basic_filebuf(), {})
0072
0073 #if !defined(BOOST_FILESYSTEM_DETAIL_NO_CXX11_MOVABLE_FSTREAMS)
0074 #if !defined(BOOST_NO_CXX11_DEFAULTED_MOVES)
0075 basic_filebuf(basic_filebuf&&) = default;
0076 basic_filebuf& operator= (basic_filebuf&&) = default;
0077 #else
0078 basic_filebuf(basic_filebuf&& that) :
0079 base_type(static_cast< base_type&& >(that)) {}
0080
0081 basic_filebuf& operator= (basic_filebuf&& that)
0082 {
0083 *static_cast< base_type* >(this) = static_cast< base_type&& >(that);
0084 return *this;
0085 }
0086 #endif
0087 #endif
0088
0089 BOOST_DELETED_FUNCTION(basic_filebuf(basic_filebuf const&))
0090 BOOST_DELETED_FUNCTION(basic_filebuf const& operator= (basic_filebuf const&))
0091
0092 public:
0093 basic_filebuf* open(path const& p, std::ios_base::openmode mode)
0094 {
0095 return base_type::open(BOOST_FILESYSTEM_C_STR(p), mode) ? this : NULL;
0096 }
0097 };
0098
0099
0100
0101
0102
0103 template< class Char, class Traits = std::char_traits< Char > >
0104 class basic_ifstream :
0105 public std::basic_ifstream< Char, Traits >
0106 {
0107 private:
0108 typedef std::basic_ifstream< Char, Traits > base_type;
0109
0110 public:
0111 BOOST_DEFAULTED_FUNCTION(basic_ifstream(), {})
0112
0113
0114
0115
0116 explicit basic_ifstream(path const& p) :
0117 base_type(BOOST_FILESYSTEM_C_STR(p), std::ios_base::in) {}
0118
0119 basic_ifstream(path const& p, std::ios_base::openmode mode) :
0120 base_type(BOOST_FILESYSTEM_C_STR(p), mode) {}
0121
0122 #if !defined(BOOST_FILESYSTEM_DETAIL_NO_CXX11_MOVABLE_FSTREAMS)
0123 basic_ifstream(basic_ifstream&& that) :
0124 base_type(static_cast< base_type&& >(that)) {}
0125
0126 basic_ifstream& operator= (basic_ifstream&& that)
0127 {
0128 *static_cast< base_type* >(this) = static_cast< base_type&& >(that);
0129 return *this;
0130 }
0131 #endif
0132
0133 BOOST_DELETED_FUNCTION(basic_ifstream(basic_ifstream const&))
0134 BOOST_DELETED_FUNCTION(basic_ifstream const& operator= (basic_ifstream const&))
0135
0136 public:
0137 void open(path const& p)
0138 {
0139 base_type::open(BOOST_FILESYSTEM_C_STR(p), std::ios_base::in);
0140 }
0141
0142 void open(path const& p, std::ios_base::openmode mode)
0143 {
0144 base_type::open(BOOST_FILESYSTEM_C_STR(p), mode);
0145 }
0146 };
0147
0148
0149
0150
0151
0152 template< class Char, class Traits = std::char_traits< Char > >
0153 class basic_ofstream :
0154 public std::basic_ofstream< Char, Traits >
0155 {
0156 private:
0157 typedef std::basic_ofstream< Char, Traits > base_type;
0158
0159 public:
0160 BOOST_DEFAULTED_FUNCTION(basic_ofstream(), {})
0161
0162
0163
0164
0165 explicit basic_ofstream(path const& p) :
0166 base_type(BOOST_FILESYSTEM_C_STR(p), std::ios_base::out) {}
0167
0168 basic_ofstream(path const& p, std::ios_base::openmode mode) :
0169 base_type(BOOST_FILESYSTEM_C_STR(p), mode) {}
0170
0171 #if !defined(BOOST_FILESYSTEM_DETAIL_NO_CXX11_MOVABLE_FSTREAMS)
0172 basic_ofstream(basic_ofstream&& that) :
0173 base_type(static_cast< base_type&& >(that)) {}
0174
0175 basic_ofstream& operator= (basic_ofstream&& that)
0176 {
0177 *static_cast< base_type* >(this) = static_cast< base_type&& >(that);
0178 return *this;
0179 }
0180 #endif
0181
0182 BOOST_DELETED_FUNCTION(basic_ofstream(basic_ofstream const&))
0183 BOOST_DELETED_FUNCTION(basic_ofstream const& operator= (basic_ofstream const&))
0184
0185 public:
0186 void open(path const& p)
0187 {
0188 base_type::open(BOOST_FILESYSTEM_C_STR(p), std::ios_base::out);
0189 }
0190
0191 void open(path const& p, std::ios_base::openmode mode)
0192 {
0193 base_type::open(BOOST_FILESYSTEM_C_STR(p), mode);
0194 }
0195 };
0196
0197
0198
0199
0200
0201 template< class Char, class Traits = std::char_traits< Char > >
0202 class basic_fstream :
0203 public std::basic_fstream< Char, Traits >
0204 {
0205 private:
0206 typedef std::basic_fstream< Char, Traits > base_type;
0207
0208 public:
0209 BOOST_DEFAULTED_FUNCTION(basic_fstream(), {})
0210
0211
0212
0213
0214 explicit basic_fstream(path const& p) :
0215 base_type(BOOST_FILESYSTEM_C_STR(p), std::ios_base::in | std::ios_base::out) {}
0216
0217 basic_fstream(path const& p, std::ios_base::openmode mode) :
0218 base_type(BOOST_FILESYSTEM_C_STR(p), mode) {}
0219
0220 #if !defined(BOOST_FILESYSTEM_DETAIL_NO_CXX11_MOVABLE_FSTREAMS)
0221 basic_fstream(basic_fstream&& that) :
0222 base_type(static_cast< base_type&& >(that)) {}
0223
0224 basic_fstream& operator= (basic_fstream&& that)
0225 {
0226 *static_cast< base_type* >(this) = static_cast< base_type&& >(that);
0227 return *this;
0228 }
0229 #endif
0230
0231 BOOST_DELETED_FUNCTION(basic_fstream(basic_fstream const&))
0232 BOOST_DELETED_FUNCTION(basic_fstream const& operator= (basic_fstream const&))
0233
0234 public:
0235 void open(path const& p)
0236 {
0237 base_type::open(BOOST_FILESYSTEM_C_STR(p), std::ios_base::in | std::ios_base::out);
0238 }
0239
0240 void open(path const& p, std::ios_base::openmode mode)
0241 {
0242 base_type::open(BOOST_FILESYSTEM_C_STR(p), mode);
0243 }
0244 };
0245
0246
0247
0248
0249
0250 typedef basic_filebuf< char > filebuf;
0251 typedef basic_ifstream< char > ifstream;
0252 typedef basic_ofstream< char > ofstream;
0253 typedef basic_fstream< char > fstream;
0254
0255 typedef basic_filebuf< wchar_t > wfilebuf;
0256 typedef basic_ifstream< wchar_t > wifstream;
0257 typedef basic_ofstream< wchar_t > wofstream;
0258 typedef basic_fstream< wchar_t > wfstream;
0259
0260 }
0261 }
0262
0263 #if defined(BOOST_MSVC)
0264 #pragma warning(pop)
0265 #endif
0266
0267 #include <boost/filesystem/detail/footer.hpp>
0268
0269 #endif