]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_streams.i
Source cleaning.
[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 %typemap(in) wxInputStream* (wxPyInputStream* temp, bool created) {
28 if (wxPyConvertSwigPtr($input, (void **)&temp, wxT("wxPyInputStream"))) {
29 $1 = temp->m_wxis;
30 created = false;
31 } else {
32 PyErr_Clear(); // clear the failure of the wxPyConvert above
33 $1 = wxPyCBInputStream_create($input, false);
34 if ($1 == NULL) {
35 PyErr_SetString(PyExc_TypeError, "Expected wxInputStream or Python file-like object.");
36 SWIG_fail;
37 }
38 created = true;
39 }
40 }
41 %typemap(freearg) wxInputStream* {
42 if (created$argnum)
43 delete $1;
44 }
45
46
47 %typemap(in) wxInputStream& = wxInputStream*;
48 %typemap(freearg) wxInputStream& = wxInputStream*;
49
50
51 %typemap(out) wxInputStream* {
52 wxPyInputStream * _ptr = NULL;
53
54 if ($1) {
55 _ptr = new wxPyInputStream($1);
56 }
57 $result = wxPyConstructObject(_ptr, wxT("wxPyInputStream"), $owner);
58 }
59
60
61 //---------------------------------------------------------------------------
62
63 enum wxSeekMode
64 {
65 wxFromStart,
66 wxFromCurrent,
67 wxFromEnd
68 };
69
70
71 %rename(InputStream) wxPyInputStream;
72 class wxPyInputStream
73 {
74 public:
75 %extend {
76 wxPyInputStream(PyObject* p) {
77 wxInputStream* wxis = wxPyCBInputStream::create(p);
78 if (wxis)
79 return new wxPyInputStream(wxis);
80 else
81 return NULL;
82 }
83 }
84 ~wxPyInputStream();
85
86 void close();
87 void flush();
88 bool eof();
89 PyObject* read(int size=-1);
90 PyObject* readline(int size=-1);
91 PyObject* readlines(int sizehint=-1);
92 void seek(int offset, int whence=0);
93 int tell();
94
95 /*
96 bool isatty();
97 int fileno();
98 void truncate(int size=-1);
99 void write(wxString data);
100 void writelines(wxStringPtrList);
101 */
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();
112 };
113
114
115
116 // TODO: make a more fully implemented file interface...
117 class wxOutputStream {
118 public:
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
134 %extend {
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);
145 }
146 }
147 };
148
149
150 //---------------------------------------------------------------------------
151 %init %{
152 wxPyPtrTypeMap_Add("wxInputStream", "wxPyInputStream");
153 %}
154 //---------------------------------------------------------------------------