]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/streams.i
Changed #include order to correct a compilation error
[wxWidgets.git] / wxPython / src / streams.i
CommitLineData
c368d904
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: streams.i
3// Purpose: SWIG definitions of the wxFileSystem family of classes
4//
cbf60e09 5// Author: Joerg Baumann and Robin Dunn
c368d904
RD
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"
cbf60e09 17#include "pyistream.h"
c368d904
RD
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"
c368d904
RD
31
32//----------------------------------------------------------------------
33// typemaps for wxInputStream
f74ff5ef
RD
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 {
249a57f4 41 $target = wxPyCBInputStream_create($source, FALSE);
f74ff5ef
RD
42 if ($target == NULL) {
43 PyErr_SetString(PyExc_TypeError,"Expected _wxInputStream_p or Python file-like object.");
c368d904
RD
44 return NULL;
45 }
f74ff5ef 46 created = TRUE;
c368d904
RD
47 }
48}
49
f74ff5ef
RD
50%typemap(python, freearg) wxInputStream * {
51 if (created)
52 delete $source;
53}
54
c368d904
RD
55
56// typemaps for wxInputStream
57%typemap(python,out) wxInputStream* {
58 wxPyInputStream * _ptr = NULL;
59
60 if ($source) {
61 _ptr = new wxPyInputStream($source);
62 }
1e4a197e 63 $target = wxPyConstructObject(_ptr, wxT("wxInputStream"), TRUE);
c368d904
RD
64}
65
66//----------------------------------------------------------------------
67
c368d904 68
a541c325
RD
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// }
c368d904 89
1e4a197e
RD
90enum wxSeekMode
91{
92 wxFromStart,
93 wxFromCurrent,
94 wxFromEnd
95};
c368d904 96
c368d904
RD
97
98
99%name(wxInputStream) class wxPyInputStream {
100public:
101 %addmethods {
102 wxPyInputStream(PyObject* p) {
f74ff5ef
RD
103 wxInputStream* wxis = wxPyCBInputStream::create(p);
104 if (wxis)
105 return new wxPyInputStream(wxis);
c368d904
RD
106 else
107 return NULL;
108 }
109 }
110 void close();
111 void flush();
112 bool eof();
a541c325
RD
113 PyObject* read(int size=-1);
114 PyObject* readline(int size=-1);
115 PyObject* readlines(int sizehint=-1);
c368d904
RD
116 void seek(int offset, int whence=0);
117 int tell();
f74ff5ef 118
c368d904
RD
119 /*
120 bool isatty();
121 int fileno();
122 void truncate(int size=-1);
123 void write(wxString data);
124 void writelines(wxStringPtrList);
125 */
1e4a197e
RD
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();
c368d904
RD
136}
137
138
139
140// TODO: make a more fully implemented file interface...
141class wxOutputStream {
142public:
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 {
a541c325
RD
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);
c368d904
RD
169 }
170 }
171};
172
173
174// restore except and typemaps
175%typemap(python,out) wxStringPtrList*;
176%typemap(python,out) wxPyInputStream*;
c368d904
RD
177
178
9416aa89
RD
179//----------------------------------------------------------------------
180
181%init %{
182 wxPyPtrTypeMap_Add("wxInputStream", "wxPyInputStream");
183%}
184
185//----------------------------------------------------------------------