From bfabc7f47cf9f57e51c6f4c7173c58df52c365e7 Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin <vadim@wxwidgets.org>
Date: Wed, 3 Jul 2013 00:26:38 +0000
Subject: [PATCH] Extract wxPipeInputStream and wxPipeOutputStream in a header.

No real changes, just put these classes in a private header. They're still not
part of the public API but at least it will be easier to reuse them inside the
library itself in the upcoming commits.

See #10258.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74336 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 include/wx/msw/private/pipestream.h  | 51 ++++++++++++++++++++++++++++
 include/wx/private/pipestream.h      | 30 ++++++++++++++++
 include/wx/unix/pipe.h               | 36 --------------------
 include/wx/unix/private/pipestream.h | 38 +++++++++++++++++++++
 src/msw/utilsexc.cpp                 | 41 +---------------------
 src/unix/utilsunx.cpp                |  2 ++
 6 files changed, 122 insertions(+), 76 deletions(-)
 create mode 100644 include/wx/msw/private/pipestream.h
 create mode 100644 include/wx/private/pipestream.h
 create mode 100644 include/wx/unix/private/pipestream.h

diff --git a/include/wx/msw/private/pipestream.h b/include/wx/msw/private/pipestream.h
new file mode 100644
index 0000000000..839084d817
--- /dev/null
+++ b/include/wx/msw/private/pipestream.h
@@ -0,0 +1,51 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        wx/msw/private/pipestream.h
+// Purpose:     MSW wxPipeInputStream and wxPipeOutputStream declarations
+// Author:      Vadim Zeitlin
+// Created:     2013-06-08 (extracted from src/msw/utilsexc.cpp)
+// RCS-ID:      $Id$
+// Copyright:   (c) 2013 Vadim Zeitlin <vadim@wxwidgets.org>
+// Licence:     wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_MSW_PRIVATE_PIPESTREAM_H_
+#define _WX_MSW_PRIVATE_PIPESTREAM_H_
+
+class wxPipeInputStream : public wxInputStream
+{
+public:
+    wxEXPLICIT wxPipeInputStream(HANDLE hInput);
+    virtual ~wxPipeInputStream();
+
+    // returns true if the pipe is still opened
+    bool IsOpened() const { return m_hInput != INVALID_HANDLE_VALUE; }
+
+    // returns true if there is any data to be read from the pipe
+    virtual bool CanRead() const;
+
+protected:
+    virtual size_t OnSysRead(void *buffer, size_t len);
+
+protected:
+    HANDLE m_hInput;
+
+    wxDECLARE_NO_COPY_CLASS(wxPipeInputStream);
+};
+
+class wxPipeOutputStream: public wxOutputStream
+{
+public:
+    wxEXPLICIT wxPipeOutputStream(HANDLE hOutput);
+    virtual ~wxPipeOutputStream() { Close(); }
+    bool Close();
+
+protected:
+    size_t OnSysWrite(const void *buffer, size_t len);
+
+protected:
+    HANDLE m_hOutput;
+
+    wxDECLARE_NO_COPY_CLASS(wxPipeOutputStream);
+};
+
+#endif // _WX_MSW_PRIVATE_PIPESTREAM_H_
diff --git a/include/wx/private/pipestream.h b/include/wx/private/pipestream.h
new file mode 100644
index 0000000000..4cf5c30cc7
--- /dev/null
+++ b/include/wx/private/pipestream.h
@@ -0,0 +1,30 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        wx/private/pipestream.h
+// Purpose:     Declares wxPipeInputStream and wxPipeOutputStream.
+// Author:      Vadim Zeitlin
+// Modified by: Rob Bresalier
+// Created:     2013-04-27
+// RCS-ID:      $Id$
+// Copyright:   (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
+//              (c) 2013 Rob Bresalier
+// Licence:     wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_PRIVATE_PIPESTREAM_H_
+#define _WX_PRIVATE_PIPESTREAM_H_
+
+#include "wx/platform.h"
+
+// wxPipeInputStream is a platform-dependent input stream class (i.e. deriving,
+// possible indirectly, from wxInputStream) for reading from a pipe, i.e. a
+// pipe FD under Unix or a pipe HANDLE under MSW. It provides a single extra
+// IsOpened() method.
+//
+// wxPipeOutputStream is similar but has no additional methods at all.
+#ifdef __UNIX__
+    #include "wx/unix/private/pipestream.h"
+#elif defined(__WINDOWS__) && !defined(__WXWINCE__)
+    #include "wx/msw/private/pipestream.h"
+#endif
+
+#endif // _WX_PRIVATE_PIPESTREAM_H_
diff --git a/include/wx/unix/pipe.h b/include/wx/unix/pipe.h
index e4799024ed..1a33302259 100644
--- a/include/wx/unix/pipe.h
+++ b/include/wx/unix/pipe.h
@@ -98,41 +98,5 @@ private:
     int m_fds[2];
 };
 
-#if wxUSE_STREAMS && wxUSE_FILE
-
-#include "wx/wfstream.h"
-
-// ----------------------------------------------------------------------------
-// wxPipeInputStream: stream for reading from a pipe
-// ----------------------------------------------------------------------------
-
-class wxPipeInputStream : public wxFileInputStream
-{
-public:
-    wxPipeInputStream(int fd) : wxFileInputStream(fd) { }
-
-    // return TRUE if the pipe is still opened
-    bool IsOpened() const { return !Eof(); }
-
-    // return TRUE if we have anything to read, don't block
-    virtual bool CanRead() const;
-};
-
-// ----------------------------------------------------------------------------
-// wxPipeOutputStream: stream for writing to a pipe
-// ----------------------------------------------------------------------------
-
-class wxPipeOutputStream : public wxFileOutputStream
-{
-public:
-    wxPipeOutputStream(int fd) : wxFileOutputStream(fd) { }
-
-    // Override the base class version to ignore "pipe full" errors: this is
-    // not an error for this class.
-    size_t OnSysWrite(const void *buffer, size_t size);
-};
-
-#endif // wxUSE_STREAMS && wxUSE_FILE
-
 #endif // _WX_UNIX_PIPE_H_
 
diff --git a/include/wx/unix/private/pipestream.h b/include/wx/unix/private/pipestream.h
new file mode 100644
index 0000000000..e57b4d360e
--- /dev/null
+++ b/include/wx/unix/private/pipestream.h
@@ -0,0 +1,38 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        wx/unix/private/pipestream.h
+// Purpose:     Unix wxPipeInputStream and wxPipeOutputStream declarations
+// Author:      Vadim Zeitlin
+// Created:     2013-06-08 (extracted from wx/unix/pipe.h)
+// RCS-ID:      $Id$
+// Copyright:   (c) 2013 Vadim Zeitlin <vadim@wxwidgets.org>
+// Licence:     wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_UNIX_PRIVATE_PIPESTREAM_H_
+#define _WX_UNIX_PRIVATE_PIPESTREAM_H_
+
+#include "wx/wfstream.h"
+
+class wxPipeInputStream : public wxFileInputStream
+{
+public:
+    wxEXPLICIT wxPipeInputStream(int fd) : wxFileInputStream(fd) { }
+
+    // return true if the pipe is still opened
+    bool IsOpened() const { return !Eof(); }
+
+    // return true if we have anything to read, don't block
+    virtual bool CanRead() const;
+};
+
+class wxPipeOutputStream : public wxFileOutputStream
+{
+public:
+    wxPipeOutputStream(int fd) : wxFileOutputStream(fd) { }
+
+    // Override the base class version to ignore "pipe full" errors: this is
+    // not an error for this class.
+    size_t OnSysWrite(const void *buffer, size_t size);
+};
+
+#endif // _WX_UNIX_PRIVATE_PIPESTREAM_H_
diff --git a/src/msw/utilsexc.cpp b/src/msw/utilsexc.cpp
index 9c959de05e..cd4f5b86b2 100644
--- a/src/msw/utilsexc.cpp
+++ b/src/msw/utilsexc.cpp
@@ -201,46 +201,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxExecuteModule, wxModule)
 
 #if wxUSE_STREAMS && !defined(__WXWINCE__)
 
-// ----------------------------------------------------------------------------
-// wxPipeStreams
-// ----------------------------------------------------------------------------
-
-class wxPipeInputStream: public wxInputStream
-{
-public:
-    wxPipeInputStream(HANDLE hInput);
-    virtual ~wxPipeInputStream();
-
-    // returns true if the pipe is still opened
-    bool IsOpened() const { return m_hInput != INVALID_HANDLE_VALUE; }
-
-    // returns true if there is any data to be read from the pipe
-    virtual bool CanRead() const;
-
-protected:
-    size_t OnSysRead(void *buffer, size_t len);
-
-protected:
-    HANDLE m_hInput;
-
-    wxDECLARE_NO_COPY_CLASS(wxPipeInputStream);
-};
-
-class wxPipeOutputStream: public wxOutputStream
-{
-public:
-    wxPipeOutputStream(HANDLE hOutput);
-    virtual ~wxPipeOutputStream() { Close(); }
-    bool Close();
-
-protected:
-    size_t OnSysWrite(const void *buffer, size_t len);
-
-protected:
-    HANDLE m_hOutput;
-
-    wxDECLARE_NO_COPY_CLASS(wxPipeOutputStream);
-};
+#include "wx/private/pipestream.h"
 
 // define this to let wxexec.cpp know that we know what we're doing
 #define _WX_USED_BY_WXEXECUTE_
diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp
index bba1eb7be5..fb2854f847 100644
--- a/src/unix/utilsunx.cpp
+++ b/src/unix/utilsunx.cpp
@@ -63,6 +63,8 @@
 
 #if HAS_PIPE_STREAMS
 
+#include "wx/private/pipestream.h"
+
 // define this to let wxexec.cpp know that we know what we're doing
 #define _WX_USED_BY_WXEXECUTE_
 #include "../common/execcmn.cpp"
-- 
2.47.2