Boost logo

Boost-Commit :

From: Frank.Birbacher_at_[hidden]
Date: 2007-09-02 19:16:32


Author: birbacher
Date: 2007-09-02 19:16:32 EDT (Sun, 02 Sep 2007)
New Revision: 39109
URL: http://svn.boost.org/trac/boost/changeset/39109

Log:
first change: pimpl fully applied to IOStreams file_descriptor, tested on linux/gcc-4.1.2
Text files modified:
   sandbox-branches/birbacher/tmp_iostreams/boost/iostreams/device/file_descriptor.hpp | 41 +++---------------------
   sandbox-branches/birbacher/tmp_iostreams/libs/iostreams/src/file_descriptor.cpp | 65 ++++++++++++++++++++++++++++++++++++++++
   2 files changed, 71 insertions(+), 35 deletions(-)

Modified: sandbox-branches/birbacher/tmp_iostreams/boost/iostreams/device/file_descriptor.hpp
==============================================================================
--- sandbox-branches/birbacher/tmp_iostreams/boost/iostreams/device/file_descriptor.hpp (original)
+++ sandbox-branches/birbacher/tmp_iostreams/boost/iostreams/device/file_descriptor.hpp 2007-09-02 19:16:32 EDT (Sun, 02 Sep 2007)
@@ -39,57 +39,28 @@
         : seekable_device_tag,
           closable_tag
         { };
- file_descriptor() : pimpl_(new impl) { }
- explicit file_descriptor(int fd, bool close_on_exit = false)
- : pimpl_(new impl(fd, close_on_exit))
- { }
+ file_descriptor();
+ explicit file_descriptor(int fd, bool close_on_exit = false);
 #ifdef BOOST_IOSTREAMS_WINDOWS
- explicit file_descriptor(handle_type handle, bool close_on_exit = false)
- : pimpl_(new impl(handle, close_on_exit))
- { }
+ explicit file_descriptor(handle_type handle, bool close_on_exit = false);
 #endif
     explicit file_descriptor( const std::string& path,
                               BOOST_IOS::openmode mode =
                                   BOOST_IOS::in | BOOST_IOS::out,
                               BOOST_IOS::openmode base_mode =
- BOOST_IOS::in | BOOST_IOS::out )
- : pimpl_(new impl)
- { open(path, mode, base_mode); }
+ BOOST_IOS::in | BOOST_IOS::out );
     void open( const std::string& path,
                BOOST_IOS::openmode =
                    BOOST_IOS::in | BOOST_IOS::out,
                BOOST_IOS::openmode base_mode =
                    BOOST_IOS::in | BOOST_IOS::out );
- bool is_open() const { return pimpl_->flags_ != 0; }
+ bool is_open() const;
     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);
     void close();
 private:
- struct impl {
- impl() : fd_(-1), flags_(0) { }
- impl(int fd, bool close_on_exit)
- : fd_(fd), flags_(0)
- { if (close_on_exit) flags_ |= impl::close_on_exit; }
- #ifdef BOOST_IOSTREAMS_WINDOWS
- impl(handle_type handle, bool close_on_exit)
- : handle_(handle), flags_(has_handle)
- { if (close_on_exit) flags_ |= impl::close_on_exit; }
- #endif
- ~impl() {
- if (flags_ & close_on_exit) close_impl(*this);
- }
- enum flags {
- close_on_exit = 1,
- has_handle = 2,
- append = 4
- };
- int fd_;
- #ifdef BOOST_IOSTREAMS_WINDOWS
- handle_type handle_;
- #endif
- int flags_;
- };
+ struct impl;
     friend struct impl;
 
     static void close_impl(impl&);

Modified: sandbox-branches/birbacher/tmp_iostreams/libs/iostreams/src/file_descriptor.cpp
==============================================================================
--- sandbox-branches/birbacher/tmp_iostreams/libs/iostreams/src/file_descriptor.cpp (original)
+++ sandbox-branches/birbacher/tmp_iostreams/libs/iostreams/src/file_descriptor.cpp 2007-09-02 19:16:32 EDT (Sun, 02 Sep 2007)
@@ -49,8 +49,73 @@
 
 namespace boost { namespace iostreams {
 
+struct file_descriptor::impl {
+ impl()
+ : fd_(-1), flags_(0)
+ {}
+
+ impl(int fd, bool close_on_exit)
+ : fd_(fd), flags_(0)
+ {
+ if (close_on_exit) flags_ |= impl::close_on_exit;
+ }
+
+#ifdef BOOST_IOSTREAMS_WINDOWS
+ impl(handle_type handle, bool close_on_exit)
+ : handle_(handle), flags_(has_handle)
+ {
+ if (close_on_exit)
+ flags_ |= impl::close_on_exit;
+ }
+#endif
+
+ ~impl() {
+ if (flags_ & close_on_exit)
+ close_impl(*this);
+ }
+
+ enum flags {
+ close_on_exit = 1,
+ has_handle = 2,
+ append = 4
+ };
+
+ int fd_;
+#ifdef BOOST_IOSTREAMS_WINDOWS
+ handle_type handle_;
+#endif
+ int flags_;
+};
+
 //------------------Implementation of file_descriptor-------------------------//
 
+file_descriptor::file_descriptor()
+ : pimpl_(new impl)
+{}
+
+file_descriptor::file_descriptor(int fd, bool close_on_exit)
+ : pimpl_(new impl(fd, close_on_exit))
+{}
+
+#ifdef BOOST_IOSTREAMS_WINDOWS
+file_descriptor(handle_type handle, bool close_on_exit)
+ : pimpl_(new impl(handle, close_on_exit))
+{}
+#endif
+
+file_descriptor::file_descriptor( const std::string& path,
+ BOOST_IOS::openmode mode,
+ BOOST_IOS::openmode base_mode )
+ : pimpl_(new impl)
+{
+ open(path, mode, base_mode);
+}
+
+bool file_descriptor::is_open() const
+{
+ return pimpl_->flags_ != 0;
+}
+
 void file_descriptor::open
     ( const std::string& path, BOOST_IOS::openmode m,
       BOOST_IOS::openmode base )


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk