Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:51

0001 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
0002 // (C) Copyright 2003-2007 Jonathan Turkanis
0003 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0004 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
0005 
0006 // See http://www.boost.org/libs/iostreams for documentation.
0007 
0008 // Inspired by fdstream.hpp, (C) Copyright Nicolai M. Josuttis 2001,
0009 // available at http://www.josuttis.com/cppcode/fdstream.html.
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 // Must come last.
0031 #if defined(BOOST_MSVC)
0032 # pragma warning(push)
0033 # pragma warning(disable:4251)  // Missing DLL interface for shared_ptr
0034 #endif
0035 #include <boost/config/abi_prefix.hpp>
0036 
0037 namespace boost { namespace iostreams {
0038 
0039 // Forward declarations
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     // Default constructor
0062     file_descriptor();
0063 
0064     // Constructors taking file desciptors
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     // Constructors taking file desciptors
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     // Constructor taking a std:: string
0079     explicit file_descriptor( const std::string& path,
0080                               BOOST_IOS::openmode mode =
0081                                   BOOST_IOS::in | BOOST_IOS::out );
0082 
0083     // Constructor taking a C-style string
0084     explicit file_descriptor( const char* path,
0085                               BOOST_IOS::openmode mode =
0086                                   BOOST_IOS::in | BOOST_IOS::out );
0087 
0088     // Constructor taking a Boost.Filesystem path
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     // Copy constructor
0099     file_descriptor(const file_descriptor& other);
0100 
0101     // open overloads taking file descriptors
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     // open overloads taking file descriptors
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     // open overload taking a std::string
0116     void open( const std::string& path,
0117                BOOST_IOS::openmode mode =
0118                    BOOST_IOS::in | BOOST_IOS::out );
0119 
0120     // open overload taking C-style string
0121     void open( const char* path,
0122                BOOST_IOS::openmode mode =
0123                    BOOST_IOS::in | BOOST_IOS::out );
0124 
0125     // open overload taking a Boost.Filesystem path
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     // open overload taking a detail::path
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;  // A.k.a HANDLE
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     // Default constructor
0170     file_descriptor_source() { }
0171 
0172     // Constructors taking file desciptors
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     // Constructors taking file desciptors
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     // Constructor taking a std:: string
0187     explicit file_descriptor_source( const std::string& path,
0188                                      BOOST_IOS::openmode mode = BOOST_IOS::in );
0189 
0190     // Constructor taking a C-style string
0191     explicit file_descriptor_source( const char* path,
0192                                      BOOST_IOS::openmode mode = BOOST_IOS::in );
0193 
0194     // Constructor taking a Boost.Filesystem path
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     // Copy constructor
0201     file_descriptor_source(const file_descriptor_source& other);
0202 
0203     // Constructors taking file desciptors
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     // open overloads taking file descriptors
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     // open overload taking a std::string
0218     void open(const std::string& path, BOOST_IOS::openmode mode = BOOST_IOS::in);
0219 
0220     // open overload taking C-style string
0221     void open(const char* path, BOOST_IOS::openmode mode = BOOST_IOS::in);
0222 
0223     // open overload taking a Boost.Filesystem path
0224     template<typename Path>
0225     void open(const Path& path, BOOST_IOS::openmode mode = BOOST_IOS::in);
0226 private:
0227 
0228     // open overload taking a detail::path
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;  // A.k.a HANDLE
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     // Default constructor
0252     file_descriptor_sink() { }
0253 
0254     // Constructors taking file desciptors
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     // Constructors taking file desciptors
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     // Constructor taking a std:: string
0269     explicit file_descriptor_sink( const std::string& path,
0270                                    BOOST_IOS::openmode mode = BOOST_IOS::out );
0271 
0272     // Constructor taking a C-style string
0273     explicit file_descriptor_sink( const char* path,
0274                                    BOOST_IOS::openmode mode = BOOST_IOS::out );
0275 
0276     // Constructor taking a Boost.Filesystem path
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     // Copy constructor
0283     file_descriptor_sink(const file_descriptor_sink& other);
0284 
0285     // open overloads taking file descriptors
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     // open overloads taking file descriptors
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     // open overload taking a std::string
0300     void open( const std::string& path, 
0301                BOOST_IOS::openmode mode = BOOST_IOS::out );
0302 
0303     // open overload taking C-style string
0304     void open( const char* path, 
0305                BOOST_IOS::openmode mode = BOOST_IOS::out );
0306 
0307     // open overload taking a Boost.Filesystem path
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     // open overload taking a detail::path
0315     void open(const detail::path& path, BOOST_IOS::openmode);
0316 };
0317 
0318 } } // End namespaces iostreams, boost.
0319 
0320 #include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
0321 #if defined(BOOST_MSVC)
0322 # pragma warning(pop)  // pops #pragma warning(disable:4251)
0323 #endif
0324 
0325 #endif // #ifndef BOOST_IOSTREAMS_FILE_DESCRIPTOR_HPP_INCLUDED