]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_streams.i
added a test to check how exception handling works with Win32 SEH; corrected copyright
[wxWidgets.git] / wxPython / src / _streams.i
CommitLineData
c368d904 1/////////////////////////////////////////////////////////////////////////////
d14a1e28
RD
2// Name: _streams.i
3// Purpose: SWIG typemaps and wrappers for wxInputStream
c368d904 4//
d14a1e28 5// Author: Robin Dunn
c368d904
RD
6//
7// Created: 25-Sept-2000
8// RCS-ID: $Id$
d14a1e28 9// Copyright: (c) 2003 by Total Control Software
c368d904
RD
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
d14a1e28 13// Not a %module
c368d904 14
c368d904 15
d14a1e28 16//---------------------------------------------------------------------------
c368d904 17
d14a1e28
RD
18%{
19#include "wx/wxPython/pyistream.h"
20%}
c368d904 21
d14a1e28
RD
22//---------------------------------------------------------------------------
23%newgroup
c368d904 24
c368d904 25
c368d904 26// typemaps for wxInputStream
d14a1e28
RD
27%typemap(in) wxInputStream* (wxPyInputStream* temp, bool created) {
28 if (wxPyConvertSwigPtr($input, (void **)&temp, wxT("wxPyInputStream"))) {
29 $1 = temp->m_wxis;
a72f4631 30 created = false;
f74ff5ef 31 } else {
d14a1e28 32 PyErr_Clear(); // clear the failure of the wxPyConvert above
a72f4631 33 $1 = wxPyCBInputStream_create($input, false);
d14a1e28
RD
34 if ($1 == NULL) {
35 PyErr_SetString(PyExc_TypeError, "Expected wxInputStream or Python file-like object.");
36 SWIG_fail;
c368d904 37 }
a72f4631 38 created = true;
c368d904
RD
39 }
40}
d14a1e28
RD
41%typemap(freearg) wxInputStream* {
42 if (created$argnum)
43 delete $1;
f74ff5ef
RD
44}
45
c368d904 46
d14a1e28
RD
47%typemap(in) wxInputStream& = wxInputStream*;
48%typemap(freearg) wxInputStream& = wxInputStream*;
49
50
51%typemap(out) wxInputStream* {
c368d904
RD
52 wxPyInputStream * _ptr = NULL;
53
d14a1e28
RD
54 if ($1) {
55 _ptr = new wxPyInputStream($1);
c368d904 56 }
5f21cfa9 57 $result = wxPyConstructObject(_ptr, wxT("wxPyInputStream"), $owner);
c368d904
RD
58}
59
d14a1e28
RD
60
61//---------------------------------------------------------------------------
c368d904 62
1e4a197e
RD
63enum wxSeekMode
64{
65 wxFromStart,
66 wxFromCurrent,
67 wxFromEnd
68};
c368d904 69
c368d904 70
1b8c7ba6
RD
71%rename(InputStream) wxPyInputStream;
72class wxPyInputStream
73{
c368d904 74public:
d14a1e28 75 %extend {
c368d904 76 wxPyInputStream(PyObject* p) {
f74ff5ef
RD
77 wxInputStream* wxis = wxPyCBInputStream::create(p);
78 if (wxis)
79 return new wxPyInputStream(wxis);
c368d904
RD
80 else
81 return NULL;
82 }
83 }
f464a4f2
RD
84 ~wxPyInputStream();
85
c368d904
RD
86 void close();
87 void flush();
88 bool eof();
a541c325
RD
89 PyObject* read(int size=-1);
90 PyObject* readline(int size=-1);
91 PyObject* readlines(int sizehint=-1);
c368d904
RD
92 void seek(int offset, int whence=0);
93 int tell();
f74ff5ef 94
c368d904
RD
95 /*
96 bool isatty();
97 int fileno();
98 void truncate(int size=-1);
99 void write(wxString data);
100 void writelines(wxStringPtrList);
101 */
1e4a197e
RD
102
103 char Peek();
104 char GetC();
105 size_t LastRead();
106 bool CanRead();
107 bool Eof();
108 bool Ungetch(char c);
109
110 long SeekI(long pos, wxSeekMode mode = wxFromStart);
111 long TellI();
d14a1e28 112};
c368d904
RD
113
114
115
116// TODO: make a more fully implemented file interface...
117class wxOutputStream {
118public:
119 /*
120 void close();
121 void flush();
122 wxString* read(int size=-1);
123 wxString* readline(int size=-1);
124 wxStringPtrList* readlines(int sizehint=-1);
125 void seek(int offset, int whence=0);
126 int tell();
127 bool isatty();
128 int fileno();
129 void truncate(int size=-1);
130 void write(wxString data);
131 void writelines(wxStringPtrList);
132 */
133
d14a1e28 134 %extend {
a541c325
RD
135 void write(PyObject* obj) {
136 // We use only strings for the streams, not unicode
137 PyObject* str = PyObject_Str(obj);
138 if (! str) {
139 PyErr_SetString(PyExc_TypeError, "Unable to convert to string");
140 return;
141 }
142 self->Write(PyString_AS_STRING(str),
143 PyString_GET_SIZE(str));
144 Py_DECREF(str);
c368d904
RD
145 }
146 }
147};
148
149
d14a1e28 150//---------------------------------------------------------------------------
9416aa89
RD
151%init %{
152 wxPyPtrTypeMap_Add("wxInputStream", "wxPyInputStream");
153%}
d14a1e28 154//---------------------------------------------------------------------------