123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- #ifndef BOOST_IOSTREAMS_FILE_DESCRIPTOR_HPP_INCLUDED
- #define BOOST_IOSTREAMS_FILE_DESCRIPTOR_HPP_INCLUDED
- #if defined(_MSC_VER)
- # pragma once
- #endif
- #include <string>
- #include <boost/cstdint.hpp> // intmax_t.
- #include <boost/iostreams/categories.hpp> // tags.
- #include <boost/iostreams/detail/config/auto_link.hpp>
- #include <boost/iostreams/detail/config/dyn_link.hpp>
- #include <boost/iostreams/detail/config/windows_posix.hpp>
- #include <boost/iostreams/detail/file_handle.hpp>
- #include <boost/iostreams/detail/ios.hpp> // openmode, seekdir, int types.
- #include <boost/iostreams/detail/path.hpp>
- #include <boost/iostreams/positioning.hpp>
- #include <boost/shared_ptr.hpp>
- #if defined(BOOST_MSVC)
- # pragma warning(push)
- # pragma warning(disable:4251)
- #endif
- #include <boost/config/abi_prefix.hpp>
- namespace boost { namespace iostreams {
- class file_descriptor_source;
- class file_descriptor_sink;
- namespace detail { struct file_descriptor_impl; }
- enum file_descriptor_flags
- {
- never_close_handle = 0,
- close_handle = 3
- };
- class BOOST_IOSTREAMS_DECL file_descriptor {
- public:
- friend class file_descriptor_source;
- friend class file_descriptor_sink;
- typedef detail::file_handle handle_type;
- typedef char char_type;
- struct category
- : seekable_device_tag,
- closable_tag
- { };
-
- file_descriptor();
-
- file_descriptor(handle_type fd, file_descriptor_flags);
- #ifdef BOOST_IOSTREAMS_WINDOWS
- file_descriptor(int fd, file_descriptor_flags);
- #endif
- #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
-
- explicit file_descriptor(handle_type fd, bool close_on_exit = false);
- #ifdef BOOST_IOSTREAMS_WINDOWS
- explicit file_descriptor(int fd, bool close_on_exit = false);
- #endif
- #endif
-
- explicit file_descriptor( const std::string& path,
- BOOST_IOS::openmode mode =
- BOOST_IOS::in | BOOST_IOS::out );
-
- explicit file_descriptor( const char* path,
- BOOST_IOS::openmode mode =
- BOOST_IOS::in | BOOST_IOS::out );
-
- template<typename Path>
- explicit file_descriptor( const Path& path,
- BOOST_IOS::openmode mode =
- BOOST_IOS::in | BOOST_IOS::out )
- {
- init();
- open(detail::path(path), mode);
- }
-
- file_descriptor(const file_descriptor& other);
-
- void open(handle_type fd, file_descriptor_flags);
- #ifdef BOOST_IOSTREAMS_WINDOWS
- void open(int fd, file_descriptor_flags);
- #endif
- #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
-
- void open(handle_type fd, bool close_on_exit = false);
- #ifdef BOOST_IOSTREAMS_WINDOWS
- void open(int fd, bool close_on_exit = false);
- #endif
- #endif
-
- void open( const std::string& path,
- BOOST_IOS::openmode mode =
- BOOST_IOS::in | BOOST_IOS::out );
-
- void open( const char* path,
- BOOST_IOS::openmode mode =
- BOOST_IOS::in | BOOST_IOS::out );
-
- template<typename Path>
- void open( const Path& path,
- BOOST_IOS::openmode mode =
- BOOST_IOS::in | BOOST_IOS::out )
- { open(detail::path(path), mode); }
- bool is_open() const;
- void close();
- std::streamsize read(char_type* s, std::streamsize n);
- std::streamsize write(const char_type* s, std::streamsize n);
- std::streampos seek(stream_offset off, BOOST_IOS::seekdir way);
- handle_type handle() const;
- private:
- void init();
-
- void open( const detail::path& path,
- BOOST_IOS::openmode,
- BOOST_IOS::openmode = BOOST_IOS::openmode(0) );
- typedef detail::file_descriptor_impl impl_type;
- shared_ptr<impl_type> pimpl_;
- };
- class BOOST_IOSTREAMS_DECL file_descriptor_source : private file_descriptor {
- public:
- #ifdef BOOST_IOSTREAMS_WINDOWS
- typedef void* handle_type;
- #else
- typedef int handle_type;
- #endif
- typedef char char_type;
- struct category
- : input_seekable,
- device_tag,
- closable_tag
- { };
- using file_descriptor::is_open;
- using file_descriptor::close;
- using file_descriptor::read;
- using file_descriptor::seek;
- using file_descriptor::handle;
-
- file_descriptor_source() { }
-
- explicit file_descriptor_source(handle_type fd, file_descriptor_flags);
- #ifdef BOOST_IOSTREAMS_WINDOWS
- explicit file_descriptor_source(int fd, file_descriptor_flags);
- #endif
- #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
-
- explicit file_descriptor_source(handle_type fd, bool close_on_exit = false);
- #ifdef BOOST_IOSTREAMS_WINDOWS
- explicit file_descriptor_source(int fd, bool close_on_exit = false);
- #endif
- #endif
-
- explicit file_descriptor_source( const std::string& path,
- BOOST_IOS::openmode mode = BOOST_IOS::in );
-
- explicit file_descriptor_source( const char* path,
- BOOST_IOS::openmode mode = BOOST_IOS::in );
-
- template<typename Path>
- explicit file_descriptor_source( const Path& path,
- BOOST_IOS::openmode mode = BOOST_IOS::in )
- { open(detail::path(path), mode); }
-
- file_descriptor_source(const file_descriptor_source& other);
-
- void open(handle_type fd, file_descriptor_flags);
- #ifdef BOOST_IOSTREAMS_WINDOWS
- void open(int fd, file_descriptor_flags);
- #endif
- #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
-
- void open(handle_type fd, bool close_on_exit = false);
- #ifdef BOOST_IOSTREAMS_WINDOWS
- void open(int fd, bool close_on_exit = false);
- #endif
- #endif
-
- void open(const std::string& path, BOOST_IOS::openmode mode = BOOST_IOS::in);
-
- void open(const char* path, BOOST_IOS::openmode mode = BOOST_IOS::in);
-
- template<typename Path>
- void open(const Path& path, BOOST_IOS::openmode mode = BOOST_IOS::in);
- private:
-
- void open(const detail::path& path, BOOST_IOS::openmode);
- };
- class BOOST_IOSTREAMS_DECL file_descriptor_sink : private file_descriptor {
- public:
- #ifdef BOOST_IOSTREAMS_WINDOWS
- typedef void* handle_type;
- #else
- typedef int handle_type;
- #endif
- typedef char char_type;
- struct category
- : output_seekable,
- device_tag,
- closable_tag
- { };
- using file_descriptor::is_open;
- using file_descriptor::close;
- using file_descriptor::write;
- using file_descriptor::seek;
- using file_descriptor::handle;
-
- file_descriptor_sink() { }
-
- file_descriptor_sink(handle_type fd, file_descriptor_flags);
- #ifdef BOOST_IOSTREAMS_WINDOWS
- file_descriptor_sink(int fd, file_descriptor_flags);
- #endif
- #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
-
- explicit file_descriptor_sink(handle_type fd, bool close_on_exit = false);
- #ifdef BOOST_IOSTREAMS_WINDOWS
- explicit file_descriptor_sink(int fd, bool close_on_exit = false);
- #endif
- #endif
-
- explicit file_descriptor_sink( const std::string& path,
- BOOST_IOS::openmode mode = BOOST_IOS::out );
-
- explicit file_descriptor_sink( const char* path,
- BOOST_IOS::openmode mode = BOOST_IOS::out );
-
- template<typename Path>
- explicit file_descriptor_sink( const Path& path,
- BOOST_IOS::openmode mode = BOOST_IOS::out )
- { open(detail::path(path), mode); }
-
- file_descriptor_sink(const file_descriptor_sink& other);
-
- void open(handle_type fd, file_descriptor_flags);
- #ifdef BOOST_IOSTREAMS_WINDOWS
- void open(int fd, file_descriptor_flags);
- #endif
- #if defined(BOOST_IOSTREAMS_USE_DEPRECATED)
-
- void open(handle_type fd, bool close_on_exit = false);
- #ifdef BOOST_IOSTREAMS_WINDOWS
- void open(int fd, bool close_on_exit = false);
- #endif
- #endif
-
- void open( const std::string& path,
- BOOST_IOS::openmode mode = BOOST_IOS::out );
-
- void open( const char* path,
- BOOST_IOS::openmode mode = BOOST_IOS::out );
-
- template<typename Path>
- void open( const Path& path,
- BOOST_IOS::openmode mode = BOOST_IOS::out )
- { open(detail::path(path), mode); }
- private:
-
- void open(const detail::path& path, BOOST_IOS::openmode);
- };
- } }
- #include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
- #if defined(BOOST_MSVC)
- # pragma warning(pop)
- #endif
- #endif
|