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.");
66 %typemap(out) wxInputStream* {
67 wxPyInputStream * _ptr = NULL;
70 _ptr = new wxPyInputStream($1);
72 $result = wxPyConstructObject(_ptr, wxT("wxPyInputStream"), $owner);
76 //---------------------------------------------------------------------------
86 %rename(InputStream) wxPyInputStream;
91 wxPyInputStream(PyObject* p) {
92 wxInputStream* wxis = wxPyCBInputStream::create(p);
94 return new wxPyInputStream(wxis);
104 PyObject* read(int size=-1);
105 PyObject* readline(int size=-1);
106 PyObject* readlines(int sizehint=-1);
107 void seek(int offset, int whence=0);
113 void truncate(int size=-1);
114 void write(wxString data);
115 void writelines(wxStringPtrList);
123 bool Ungetch(char c);
125 long SeekI(long pos, wxSeekMode mode = wxFromStart);
131 // TODO: make a more fully implemented file interface...
132 class wxOutputStream {
137 wxString* read(int size=-1);
138 wxString* readline(int size=-1);
139 wxStringPtrList* readlines(int sizehint=-1);
140 void seek(int offset, int whence=0);
144 void truncate(int size=-1);
145 void write(wxString data);
146 void writelines(wxStringPtrList);
150 void write(PyObject* obj) {
151 // We use only strings for the streams, not unicode
152 PyObject* str = PyObject_Str(obj);
154 PyErr_SetString(PyExc_TypeError, "Unable to convert to string");
157 self->Write(PyString_AS_STRING(str),
158 PyString_GET_SIZE(str));
165 //---------------------------------------------------------------------------
167 wxPyPtrTypeMap_Add("wxInputStream", "wxPyInputStream");
169 //---------------------------------------------------------------------------