]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_streams.i
reSWIGged
[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
d14a1e28 71%name(InputStream) class wxPyInputStream {
c368d904 72public:
d14a1e28 73 %extend {
c368d904 74 wxPyInputStream(PyObject* p) {
f74ff5ef
RD
75 wxInputStream* wxis = wxPyCBInputStream::create(p);
76 if (wxis)
77 return new wxPyInputStream(wxis);
c368d904
RD
78 else
79 return NULL;
80 }
81 }
f464a4f2
RD
82 ~wxPyInputStream();
83
c368d904
RD
84 void close();
85 void flush();
86 bool eof();
a541c325
RD
87 PyObject* read(int size=-1);
88 PyObject* readline(int size=-1);
89 PyObject* readlines(int sizehint=-1);
c368d904
RD
90 void seek(int offset, int whence=0);
91 int tell();
f74ff5ef 92
c368d904
RD
93 /*
94 bool isatty();
95 int fileno();
96 void truncate(int size=-1);
97 void write(wxString data);
98 void writelines(wxStringPtrList);
99 */
1e4a197e
RD
100
101 char Peek();
102 char GetC();
103 size_t LastRead();
104 bool CanRead();
105 bool Eof();
106 bool Ungetch(char c);
107
108 long SeekI(long pos, wxSeekMode mode = wxFromStart);
109 long TellI();
d14a1e28 110};
c368d904
RD
111
112
113
114// TODO: make a more fully implemented file interface...
115class wxOutputStream {
116public:
117 /*
118 void close();
119 void flush();
120 wxString* read(int size=-1);
121 wxString* readline(int size=-1);
122 wxStringPtrList* readlines(int sizehint=-1);
123 void seek(int offset, int whence=0);
124 int tell();
125 bool isatty();
126 int fileno();
127 void truncate(int size=-1);
128 void write(wxString data);
129 void writelines(wxStringPtrList);
130 */
131
d14a1e28 132 %extend {
a541c325
RD
133 void write(PyObject* obj) {
134 // We use only strings for the streams, not unicode
135 PyObject* str = PyObject_Str(obj);
136 if (! str) {
137 PyErr_SetString(PyExc_TypeError, "Unable to convert to string");
138 return;
139 }
140 self->Write(PyString_AS_STRING(str),
141 PyString_GET_SIZE(str));
142 Py_DECREF(str);
c368d904
RD
143 }
144 }
145};
146
147
d14a1e28 148//---------------------------------------------------------------------------
9416aa89
RD
149%init %{
150 wxPyPtrTypeMap_Add("wxInputStream", "wxPyInputStream");
151%}
d14a1e28 152//---------------------------------------------------------------------------