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
27 %typemap(in) wxInputStream* (wxPyInputStream* temp, bool created) {
28 if (wxPyConvertSwigPtr($input, (void **)&temp, wxT("wxPyInputStream"))) {
32 PyErr_Clear(); // clear the failure of the wxPyConvert above
33 $1 = wxPyCBInputStream_create($input, False);
35 PyErr_SetString(PyExc_TypeError, "Expected wxInputStream or Python file-like object.");
41 %typemap(freearg) wxInputStream* {
47 %typemap(in) wxInputStream& = wxInputStream*;
48 %typemap(freearg) wxInputStream& = wxInputStream*;
51 %typemap(out) wxInputStream* {
52 wxPyInputStream * _ptr = NULL;
55 _ptr = new wxPyInputStream($1);
57 $result = wxPyConstructObject(_ptr, wxT("wxPyInputStream"), True);
61 //---------------------------------------------------------------------------
72 %name(InputStream) class wxPyInputStream {
75 wxPyInputStream(PyObject* p) {
76 wxInputStream* wxis = wxPyCBInputStream::create(p);
78 return new wxPyInputStream(wxis);
87 PyObject* read(int size=-1);
88 PyObject* readline(int size=-1);
89 PyObject* readlines(int sizehint=-1);
90 void seek(int offset, int whence=0);
96 void truncate(int size=-1);
97 void write(wxString data);
98 void writelines(wxStringPtrList);
106 bool Ungetch(char c);
108 long SeekI(long pos, wxSeekMode mode = wxFromStart);
114 // TODO: make a more fully implemented file interface...
115 class wxOutputStream {
120 wxString* read(int size=-1);
121 wxString* readline(int size=-1);
122 wxStringPtrList* readlines(int sizehint=-1);
123 void seek(int offset, int whence=0);
127 void truncate(int size=-1);
128 void write(wxString data);
129 void writelines(wxStringPtrList);
133 void write(PyObject* obj) {
134 // We use only strings for the streams, not unicode
135 PyObject* str = PyObject_Str(obj);
137 PyErr_SetString(PyExc_TypeError, "Unable to convert to string");
140 self->Write(PyString_AS_STRING(str),
141 PyString_GET_SIZE(str));
148 //---------------------------------------------------------------------------
150 wxPyPtrTypeMap_Add("wxInputStream", "wxPyInputStream");
152 //---------------------------------------------------------------------------