1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG typemaps and wrappers for wxInputStream
7 // Created: 25-Sept-2000
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
19 #include "wx/wxPython/pyistream.h"
22 //---------------------------------------------------------------------------
26 // Typemaps for wxInputStream
28 // We assume that input params taking a wxInputStream& will *not* take
29 // ownership of the stream and so we manage it in the typemaps. On the other
30 // hand, when a paramter expects a wxInputStream* then it does take ownership
31 // (such as wxFSFile) and so the typemap will make a copy of the stream object
34 %typemap(in) wxInputStream& (wxPyInputStream* temp, bool created) {
35 if (wxPyConvertSwigPtr($input, (void **)&temp, wxT("wxPyInputStream"))) {
39 PyErr_Clear(); // clear the failure of the wxPyConvert above
40 $1 = wxPyCBInputStream_create($input, false);
42 PyErr_SetString(PyExc_TypeError, "Expected wx.InputStream or Python file-like object.");
48 %typemap(freearg) wxInputStream& { if (created$argnum) delete $1; }
51 %typemap(in) wxInputStream* (wxPyInputStream* temp) {
52 if (wxPyConvertSwigPtr($input, (void **)&temp, wxT("wxPyInputStream"))) {
53 $1 = wxPyCBInputStream_copy((wxPyCBInputStream*)temp->m_wxis);
55 PyErr_Clear(); // clear the failure of the wxPyConvert above
56 $1 = wxPyCBInputStream_create($input, true);
58 PyErr_SetString(PyExc_TypeError, "Expected wx.InputStream or Python file-like object.");
64 %typemap(out) wxInputStream* {
65 wxPyInputStream * _ptr = NULL;
67 _ptr = new wxPyInputStream($1);
68 $result = wxPyConstructObject(_ptr, wxT("wxPyInputStream"), $owner);
72 //---------------------------------------------------------------------------
73 // Typemaps for wxOutputStream. We only need in by reference and out by
74 // pointer in this one.
77 %typemap(in) wxOutputStream& (wxPyOutputStream* temp, bool created) {
78 if (wxPyConvertSwigPtr($input, (void **)&temp, wxT("wxPyOutputStream"))) {
82 PyErr_Clear(); // clear the failure of the wxPyConvert above
83 $1 = wxPyCBOutputStream_create($input, false);
85 PyErr_SetString(PyExc_TypeError, "Expected wx.OutputStream or Python file-like object.");
91 %typemap(freearg) wxOutputStream& { if (created$argnum) delete $1; }
94 %typemap(out) wxOutputStream* {
95 wxPyOutputStream * _ptr = NULL;
97 _ptr = new wxPyOutputStream($1);
98 $result = wxPyConstructObject(_ptr, wxT("wxPyOutputStream"), $owner);
101 //---------------------------------------------------------------------------
111 %rename(InputStream) wxPyInputStream;
112 class wxPyInputStream
116 wxPyInputStream(PyObject* p) {
117 wxInputStream* wxis = wxPyCBInputStream::create(p);
119 return new wxPyInputStream(wxis);
129 PyObject* read(int size=-1);
130 PyObject* readline(int size=-1);
131 PyObject* readlines(int sizehint=-1);
132 void seek(int offset, int whence=0);
140 bool Ungetch(char c);
142 long SeekI(long pos, wxSeekMode mode = wxFromStart);
149 %rename(OutputStream) wxPyOutputStream;
150 class wxPyOutputStream
154 wxPyOutputStream(PyObject* p) {
155 wxOutputStream* wxis = wxPyCBOutputStream::create(p);
157 return new wxPyOutputStream(wxis);
167 void seek(int offset, int whence=0);
170 void write(PyObject* data);
171 //void writelines(wxStringArray& arr);
175 unsigned long SeekO(unsigned long pos, wxSeekMode mode = wxFromStart);
176 unsigned long TellO();
180 //---------------------------------------------------------------------------
182 wxPyPtrTypeMap_Add("wxInputStream", "wxPyInputStream");
183 wxPyPtrTypeMap_Add("wxOutputStream", "wxPyOutputStream");
185 //---------------------------------------------------------------------------