]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_streams.i
Merge recent wxPython changes from 2.8 branch to HEAD
[wxWidgets.git] / wxPython / src / _streams.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _streams.i
3 // Purpose: SWIG typemaps and wrappers for wxInputStream
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 25-Sept-2000
8 // RCS-ID: $Id$
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 // Not a %module
14
15
16 //---------------------------------------------------------------------------
17
18 %{
19 #include "wx/wxPython/pyistream.h"
20 %}
21
22 //---------------------------------------------------------------------------
23 %newgroup
24
25
26 // Typemaps for wxInputStream
27 //
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
32 // to give to it.
33
34 %typemap(in) wxInputStream& (wxPyInputStream* temp, bool created) {
35 if (wxPyConvertSwigPtr($input, (void **)&temp, wxT("wxPyInputStream"))) {
36 $1 = temp->m_wxis;
37 created = false;
38 } else {
39 PyErr_Clear(); // clear the failure of the wxPyConvert above
40 $1 = wxPyCBInputStream_create($input, false);
41 if ($1 == NULL) {
42 PyErr_SetString(PyExc_TypeError, "Expected wx.InputStream or Python file-like object.");
43 SWIG_fail;
44 }
45 created = true;
46 }
47 }
48 %typemap(freearg) wxInputStream& { if (created$argnum) delete $1; }
49
50
51 %typemap(in) wxInputStream* (wxPyInputStream* temp) {
52 if (wxPyConvertSwigPtr($input, (void **)&temp, wxT("wxPyInputStream"))) {
53 $1 = wxPyCBInputStream_copy((wxPyCBInputStream*)temp->m_wxis);
54 } else {
55 PyErr_Clear(); // clear the failure of the wxPyConvert above
56 $1 = wxPyCBInputStream_create($input, true);
57 if ($1 == NULL) {
58 PyErr_SetString(PyExc_TypeError, "Expected wx.InputStream or Python file-like object.");
59 SWIG_fail;
60 }
61 }
62 }
63
64 %typemap(out) wxInputStream* {
65 wxPyInputStream * _ptr = NULL;
66 if ($1)
67 _ptr = new wxPyInputStream($1);
68 $result = wxPyConstructObject(_ptr, wxT("wxPyInputStream"), $owner);
69 }
70
71
72 //---------------------------------------------------------------------------
73 // Typemaps for wxOutputStream. We only need in by reference and out by
74 // pointer in this one.
75
76
77 %typemap(in) wxOutputStream& (wxPyOutputStream* temp, bool created) {
78 if (wxPyConvertSwigPtr($input, (void **)&temp, wxT("wxPyOutputStream"))) {
79 $1 = temp->m_wxos;
80 created = false;
81 } else {
82 PyErr_Clear(); // clear the failure of the wxPyConvert above
83 $1 = wxPyCBOutputStream_create($input, false);
84 if ($1 == NULL) {
85 PyErr_SetString(PyExc_TypeError, "Expected wx.OutputStream or Python file-like object.");
86 SWIG_fail;
87 }
88 created = true;
89 }
90 }
91 %typemap(freearg) wxOutputStream& { if (created$argnum) delete $1; }
92
93
94 %typemap(out) wxOutputStream* {
95 wxPyOutputStream * _ptr = NULL;
96 if ($1)
97 _ptr = new wxPyOutputStream($1);
98 $result = wxPyConstructObject(_ptr, wxT("wxPyOutputStream"), $owner);
99 }
100
101 //---------------------------------------------------------------------------
102
103 enum wxSeekMode
104 {
105 wxFromStart,
106 wxFromCurrent,
107 wxFromEnd
108 };
109
110
111 %rename(InputStream) wxPyInputStream;
112 class wxPyInputStream
113 {
114 public:
115 %extend {
116 wxPyInputStream(PyObject* p) {
117 wxInputStream* wxis = wxPyCBInputStream::create(p);
118 if (wxis)
119 return new wxPyInputStream(wxis);
120 else
121 return NULL;
122 }
123 }
124 ~wxPyInputStream();
125
126 void close();
127 void flush();
128 bool eof();
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);
133 int tell();
134
135 char Peek();
136 char GetC();
137 size_t LastRead();
138 bool CanRead();
139 bool Eof();
140 bool Ungetch(char c);
141
142 long SeekI(long pos, wxSeekMode mode = wxFromStart);
143 long TellI();
144 };
145
146
147
148
149 %rename(OutputStream) wxPyOutputStream;
150 class wxPyOutputStream
151 {
152 public:
153 %extend {
154 wxPyOutputStream(PyObject* p) {
155 wxOutputStream* wxis = wxPyCBOutputStream::create(p);
156 if (wxis)
157 return new wxPyOutputStream(wxis);
158 else
159 return NULL;
160 }
161 }
162 ~wxPyOutputStream();
163
164 void close();
165 void flush();
166 bool eof();
167 void seek(int offset, int whence=0);
168 int tell();
169
170 void write(PyObject* data);
171 //void writelines(wxStringArray& arr);
172
173 void PutC(char c);
174 size_t LastWrite();
175 unsigned long SeekO(unsigned long pos, wxSeekMode mode = wxFromStart);
176 unsigned long TellO();
177 };
178
179
180 //---------------------------------------------------------------------------
181 %init %{
182 wxPyPtrTypeMap_Add("wxInputStream", "wxPyInputStream");
183 wxPyPtrTypeMap_Add("wxOutputStream", "wxPyOutputStream");
184 %}
185 //---------------------------------------------------------------------------