File indexing completed on 2025-01-18 09:38:51
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_IOSTREAMS_FILE_DESCRIPTOR_HPP_INCLUDED
0012 #define BOOST_IOSTREAMS_FILE_DESCRIPTOR_HPP_INCLUDED
0013
0014 #if defined(_MSC_VER)
0015 # pragma once
0016 #endif
0017
0018 #include <string>
0019 #include <boost/cstdint.hpp> // intmax_t.
0020 #include <boost/iostreams/categories.hpp> // tags.
0021 #include <boost/iostreams/detail/config/auto_link.hpp>
0022 #include <boost/iostreams/detail/config/dyn_link.hpp>
0023 #include <boost/iostreams/detail/config/windows_posix.hpp>
0024 #include <boost/iostreams/detail/file_handle.hpp>
0025 #include <boost/iostreams/detail/ios.hpp> // openmode, seekdir, int types.
0026 #include <boost/iostreams/detail/path.hpp>
0027 #include <boost/iostreams/positioning.hpp>
0028 #include <boost/shared_ptr.hpp>
0029
0030
0031 #if defined(BOOST_MSVC)
0032 # pragma warning(push)
0033 # pragma warning(disable:4251)
0034 #endif
0035 #include <boost/config/abi_prefix.hpp>
0036
0037 namespace boost { namespace iostreams {
0038
0039
0040 class file_descriptor_source;
0041 class file_descriptor_sink;
0042 namespace detail { struct file_descriptor_impl; }
0043
0044 enum file_descriptor_flags
0045 {
0046 never_close_handle = 0,
0047 close_handle = 3
0048 };
0049
0050 class BOOST_IOSTREAMS_DECL file_descriptor {
0051 public:
0052 friend class file_descriptor_source;
0053 friend class file_descriptor_sink;
0054 typedef detail::file_handle handle_type;
0055 typedef char char_type;
0056 struct category
0057 : seekable_device_tag,
0058 closable_tag
0059 { };
0060
0061
0062 file_descriptor();
0063
0064
0065 file_descriptor(handle_type fd, file_descriptor_flags);
0066 #ifdef BOOST_IOSTREAMS_WINDOWS
0067 file_descriptor(int fd, file_descriptor_flags);
0068 #endif
0069
0070 #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
0071
0072 explicit file_descriptor(handle_type fd, bool close_on_exit = false);
0073 #ifdef BOOST_IOSTREAMS_WINDOWS
0074 explicit file_descriptor(int fd, bool close_on_exit = false);
0075 #endif
0076 #endif
0077
0078
0079 explicit file_descriptor( const std::string& path,
0080 BOOST_IOS::openmode mode =
0081 BOOST_IOS::in | BOOST_IOS::out );
0082
0083
0084 explicit file_descriptor( const char* path,
0085 BOOST_IOS::openmode mode =
0086 BOOST_IOS::in | BOOST_IOS::out );
0087
0088
0089 template<typename Path>
0090 explicit file_descriptor( const Path& path,
0091 BOOST_IOS::openmode mode =
0092 BOOST_IOS::in | BOOST_IOS::out )
0093 {
0094 init();
0095 open(detail::path(path), mode);
0096 }
0097
0098
0099 file_descriptor(const file_descriptor& other);
0100
0101
0102 void open(handle_type fd, file_descriptor_flags);
0103 #ifdef BOOST_IOSTREAMS_WINDOWS
0104 void open(int fd, file_descriptor_flags);
0105 #endif
0106
0107 #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
0108
0109 void open(handle_type fd, bool close_on_exit = false);
0110 #ifdef BOOST_IOSTREAMS_WINDOWS
0111 void open(int fd, bool close_on_exit = false);
0112 #endif
0113 #endif
0114
0115
0116 void open( const std::string& path,
0117 BOOST_IOS::openmode mode =
0118 BOOST_IOS::in | BOOST_IOS::out );
0119
0120
0121 void open( const char* path,
0122 BOOST_IOS::openmode mode =
0123 BOOST_IOS::in | BOOST_IOS::out );
0124
0125
0126 template<typename Path>
0127 void open( const Path& path,
0128 BOOST_IOS::openmode mode =
0129 BOOST_IOS::in | BOOST_IOS::out )
0130 { open(detail::path(path), mode); }
0131
0132 bool is_open() const;
0133 void close();
0134 std::streamsize read(char_type* s, std::streamsize n);
0135 std::streamsize write(const char_type* s, std::streamsize n);
0136 std::streampos seek(stream_offset off, BOOST_IOS::seekdir way);
0137 handle_type handle() const;
0138 private:
0139 void init();
0140
0141
0142 void open( const detail::path& path,
0143 BOOST_IOS::openmode,
0144 BOOST_IOS::openmode = BOOST_IOS::openmode(0) );
0145
0146 typedef detail::file_descriptor_impl impl_type;
0147 shared_ptr<impl_type> pimpl_;
0148 };
0149
0150 class BOOST_IOSTREAMS_DECL file_descriptor_source : private file_descriptor {
0151 public:
0152 #ifdef BOOST_IOSTREAMS_WINDOWS
0153 typedef void* handle_type;
0154 #else
0155 typedef int handle_type;
0156 #endif
0157 typedef char char_type;
0158 struct category
0159 : input_seekable,
0160 device_tag,
0161 closable_tag
0162 { };
0163 using file_descriptor::is_open;
0164 using file_descriptor::close;
0165 using file_descriptor::read;
0166 using file_descriptor::seek;
0167 using file_descriptor::handle;
0168
0169
0170 file_descriptor_source() { }
0171
0172
0173 explicit file_descriptor_source(handle_type fd, file_descriptor_flags);
0174 #ifdef BOOST_IOSTREAMS_WINDOWS
0175 explicit file_descriptor_source(int fd, file_descriptor_flags);
0176 #endif
0177
0178 #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
0179
0180 explicit file_descriptor_source(handle_type fd, bool close_on_exit = false);
0181 #ifdef BOOST_IOSTREAMS_WINDOWS
0182 explicit file_descriptor_source(int fd, bool close_on_exit = false);
0183 #endif
0184 #endif
0185
0186
0187 explicit file_descriptor_source( const std::string& path,
0188 BOOST_IOS::openmode mode = BOOST_IOS::in );
0189
0190
0191 explicit file_descriptor_source( const char* path,
0192 BOOST_IOS::openmode mode = BOOST_IOS::in );
0193
0194
0195 template<typename Path>
0196 explicit file_descriptor_source( const Path& path,
0197 BOOST_IOS::openmode mode = BOOST_IOS::in )
0198 { open(detail::path(path), mode); }
0199
0200
0201 file_descriptor_source(const file_descriptor_source& other);
0202
0203
0204 void open(handle_type fd, file_descriptor_flags);
0205 #ifdef BOOST_IOSTREAMS_WINDOWS
0206 void open(int fd, file_descriptor_flags);
0207 #endif
0208
0209 #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
0210
0211 void open(handle_type fd, bool close_on_exit = false);
0212 #ifdef BOOST_IOSTREAMS_WINDOWS
0213 void open(int fd, bool close_on_exit = false);
0214 #endif
0215 #endif
0216
0217
0218 void open(const std::string& path, BOOST_IOS::openmode mode = BOOST_IOS::in);
0219
0220
0221 void open(const char* path, BOOST_IOS::openmode mode = BOOST_IOS::in);
0222
0223
0224 template<typename Path>
0225 void open(const Path& path, BOOST_IOS::openmode mode = BOOST_IOS::in);
0226 private:
0227
0228
0229 void open(const detail::path& path, BOOST_IOS::openmode);
0230 };
0231
0232 class BOOST_IOSTREAMS_DECL file_descriptor_sink : private file_descriptor {
0233 public:
0234 #ifdef BOOST_IOSTREAMS_WINDOWS
0235 typedef void* handle_type;
0236 #else
0237 typedef int handle_type;
0238 #endif
0239 typedef char char_type;
0240 struct category
0241 : output_seekable,
0242 device_tag,
0243 closable_tag
0244 { };
0245 using file_descriptor::is_open;
0246 using file_descriptor::close;
0247 using file_descriptor::write;
0248 using file_descriptor::seek;
0249 using file_descriptor::handle;
0250
0251
0252 file_descriptor_sink() { }
0253
0254
0255 file_descriptor_sink(handle_type fd, file_descriptor_flags);
0256 #ifdef BOOST_IOSTREAMS_WINDOWS
0257 file_descriptor_sink(int fd, file_descriptor_flags);
0258 #endif
0259
0260 #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
0261
0262 explicit file_descriptor_sink(handle_type fd, bool close_on_exit = false);
0263 #ifdef BOOST_IOSTREAMS_WINDOWS
0264 explicit file_descriptor_sink(int fd, bool close_on_exit = false);
0265 #endif
0266 #endif
0267
0268
0269 explicit file_descriptor_sink( const std::string& path,
0270 BOOST_IOS::openmode mode = BOOST_IOS::out );
0271
0272
0273 explicit file_descriptor_sink( const char* path,
0274 BOOST_IOS::openmode mode = BOOST_IOS::out );
0275
0276
0277 template<typename Path>
0278 explicit file_descriptor_sink( const Path& path,
0279 BOOST_IOS::openmode mode = BOOST_IOS::out )
0280 { open(detail::path(path), mode); }
0281
0282
0283 file_descriptor_sink(const file_descriptor_sink& other);
0284
0285
0286 void open(handle_type fd, file_descriptor_flags);
0287 #ifdef BOOST_IOSTREAMS_WINDOWS
0288 void open(int fd, file_descriptor_flags);
0289 #endif
0290
0291 #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
0292
0293 void open(handle_type fd, bool close_on_exit = false);
0294 #ifdef BOOST_IOSTREAMS_WINDOWS
0295 void open(int fd, bool close_on_exit = false);
0296 #endif
0297 #endif
0298
0299
0300 void open( const std::string& path,
0301 BOOST_IOS::openmode mode = BOOST_IOS::out );
0302
0303
0304 void open( const char* path,
0305 BOOST_IOS::openmode mode = BOOST_IOS::out );
0306
0307
0308 template<typename Path>
0309 void open( const Path& path,
0310 BOOST_IOS::openmode mode = BOOST_IOS::out )
0311 { open(detail::path(path), mode); }
0312 private:
0313
0314
0315 void open(const detail::path& path, BOOST_IOS::openmode);
0316 };
0317
0318 } }
0319
0320 #include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
0321 #if defined(BOOST_MSVC)
0322 # pragma warning(pop)
0323 #endif
0324
0325 #endif