]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/streams.i
reSWIGged
[wxWidgets.git] / wxPython / src / streams.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: streams.i
3 // Purpose: SWIG definitions of the wxFileSystem family of classes
4 //
5 // Author: Joerg Baumann and Robin Dunn
6 //
7 // Created: 25-Sept-2000
8 // RCS-ID: $Id$
9 // Copyright: (c) 2000 by Joerg Baumann
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 %module streams
14
15 %{
16 #include "helpers.h"
17 #include "pyistream.h"
18 #include <wx/stream.h>
19 #include <wx/list.h>
20 %}
21
22 //----------------------------------------------------------------------
23
24 %include typemaps.i
25 %include my_typemaps.i
26
27 // Import some definitions of other classes, etc.
28 %import _defs.i
29
30 %pragma(python) code = "import wx"
31
32 //----------------------------------------------------------------------
33 // typemaps for wxInputStream
34
35
36 %typemap(python,in) wxInputStream * (wxPyInputStream* temp, bool created) {
37 if (SWIG_GetPtrObj($source, (void **) &temp, "_wxPyInputStream_p") == 0) {
38 $target = temp->m_wxis;
39 created = FALSE;
40 } else {
41 $target = wxPyCBInputStream_create($source, FALSE);
42 if ($target == NULL) {
43 PyErr_SetString(PyExc_TypeError,"Expected _wxInputStream_p or Python file-like object.");
44 return NULL;
45 }
46 created = TRUE;
47 }
48 }
49
50 %typemap(python, freearg) wxInputStream * {
51 if (created)
52 delete $source;
53 }
54
55
56 // typemaps for wxInputStream
57 %typemap(python,out) wxInputStream* {
58 wxPyInputStream * _ptr = NULL;
59
60 if ($source) {
61 _ptr = new wxPyInputStream($source);
62 }
63 $target = wxPyConstructObject(_ptr, wxT("wxInputStream"), TRUE);
64 }
65
66 //----------------------------------------------------------------------
67
68
69 // // wxStringPtrList* to python list of strings typemap
70 // %typemap(python, out) wxStringPtrList* {
71 // if ($source) {
72 // $target = PyList_New($source->GetCount());
73 // wxStringPtrList::Node *node = $source->GetFirst();
74 // for (int i=0; node; i++) {
75 // wxString *s = node->GetData();
76 // #if wxUSE_UNICODE
77 // PyList_SetItem($target, i, PyUnicode_FromUnicode(s->c_str(), s->Len()));
78 // #else
79 // PyList_SetItem($target, i, PyString_FromStringAndSize(s->c_str(), s->Len()));
80 // #endif
81 // node = node->GetNext();
82 // delete s;
83 // }
84 // delete $source;
85 // }
86 // else
87 // $target=0;
88 // }
89
90 enum wxSeekMode
91 {
92 wxFromStart,
93 wxFromCurrent,
94 wxFromEnd
95 };
96
97
98
99 %name(wxInputStream) class wxPyInputStream {
100 public:
101 %addmethods {
102 wxPyInputStream(PyObject* p) {
103 wxInputStream* wxis = wxPyCBInputStream::create(p);
104 if (wxis)
105 return new wxPyInputStream(wxis);
106 else
107 return NULL;
108 }
109 }
110 void close();
111 void flush();
112 bool eof();
113 PyObject* read(int size=-1);
114 PyObject* readline(int size=-1);
115 PyObject* readlines(int sizehint=-1);
116 void seek(int offset, int whence=0);
117 int tell();
118
119 /*
120 bool isatty();
121 int fileno();
122 void truncate(int size=-1);
123 void write(wxString data);
124 void writelines(wxStringPtrList);
125 */
126
127 char Peek();
128 char GetC();
129 size_t LastRead();
130 bool CanRead();
131 bool Eof();
132 bool Ungetch(char c);
133
134 long SeekI(long pos, wxSeekMode mode = wxFromStart);
135 long TellI();
136 }
137
138
139
140 // TODO: make a more fully implemented file interface...
141 class wxOutputStream {
142 public:
143 /*
144 void close();
145 void flush();
146 wxString* read(int size=-1);
147 wxString* readline(int size=-1);
148 wxStringPtrList* readlines(int sizehint=-1);
149 void seek(int offset, int whence=0);
150 int tell();
151 bool isatty();
152 int fileno();
153 void truncate(int size=-1);
154 void write(wxString data);
155 void writelines(wxStringPtrList);
156 */
157
158 %addmethods {
159 void write(PyObject* obj) {
160 // We use only strings for the streams, not unicode
161 PyObject* str = PyObject_Str(obj);
162 if (! str) {
163 PyErr_SetString(PyExc_TypeError, "Unable to convert to string");
164 return;
165 }
166 self->Write(PyString_AS_STRING(str),
167 PyString_GET_SIZE(str));
168 Py_DECREF(str);
169 }
170 }
171 };
172
173
174 // restore except and typemaps
175 %typemap(python,out) wxStringPtrList*;
176 %typemap(python,out) wxPyInputStream*;
177
178
179 //----------------------------------------------------------------------
180
181 %init %{
182 wxPyPtrTypeMap_Add("wxInputStream", "wxPyInputStream");
183 %}
184
185 //----------------------------------------------------------------------