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 //---------------------------------------------------------------------------
71 %name(InputStream) class wxPyInputStream {
74 wxPyInputStream(PyObject* p) {
75 wxInputStream* wxis = wxPyCBInputStream::create(p);
77 return new wxPyInputStream(wxis);
86 PyObject* read(int size=-1);
87 PyObject* readline(int size=-1);
88 PyObject* readlines(int sizehint=-1);
89 void seek(int offset, int whence=0);
95 void truncate(int size=-1);
96 void write(wxString data);
97 void writelines(wxStringPtrList);
105 bool Ungetch(char c);
107 long SeekI(long pos, wxSeekMode mode = wxFromStart);
113 // TODO: make a more fully implemented file interface...
114 class wxOutputStream {
119 wxString* read(int size=-1);
120 wxString* readline(int size=-1);
121 wxStringPtrList* readlines(int sizehint=-1);
122 void seek(int offset, int whence=0);
126 void truncate(int size=-1);
127 void write(wxString data);
128 void writelines(wxStringPtrList);
132 void write(PyObject* obj) {
133 // We use only strings for the streams, not unicode
134 PyObject* str = PyObject_Str(obj);
136 PyErr_SetString(PyExc_TypeError, "Unable to convert to string");
139 self->Write(PyString_AS_STRING(str),
140 PyString_GET_SIZE(str));
147 //---------------------------------------------------------------------------
149 wxPyPtrTypeMap_Add("wxInputStream", "wxPyInputStream");
151 //---------------------------------------------------------------------------