]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_streams.i
Avoid crash in SelectAll if there are no nodes besides the root
[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
d02ea46c
RD
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) {
d14a1e28
RD
35 if (wxPyConvertSwigPtr($input, (void **)&temp, wxT("wxPyInputStream"))) {
36 $1 = temp->m_wxis;
a72f4631 37 created = false;
f74ff5ef 38 } else {
d14a1e28 39 PyErr_Clear(); // clear the failure of the wxPyConvert above
a72f4631 40 $1 = wxPyCBInputStream_create($input, false);
d14a1e28 41 if ($1 == NULL) {
d02ea46c 42 PyErr_SetString(PyExc_TypeError, "Expected wx.InputStream or Python file-like object.");
d14a1e28 43 SWIG_fail;
c368d904 44 }
a72f4631 45 created = true;
c368d904
RD
46 }
47}
d02ea46c
RD
48%typemap(freearg) wxInputStream& { if (created$argnum) delete $1; }
49
f74ff5ef 50
d02ea46c
RD
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}
c368d904 63
d14a1e28
RD
64
65
66%typemap(out) wxInputStream* {
c368d904
RD
67 wxPyInputStream * _ptr = NULL;
68
d14a1e28
RD
69 if ($1) {
70 _ptr = new wxPyInputStream($1);
c368d904 71 }
5f21cfa9 72 $result = wxPyConstructObject(_ptr, wxT("wxPyInputStream"), $owner);
c368d904
RD
73}
74
d14a1e28
RD
75
76//---------------------------------------------------------------------------
c368d904 77
1e4a197e
RD
78enum wxSeekMode
79{
80 wxFromStart,
81 wxFromCurrent,
82 wxFromEnd
83};
c368d904 84
c368d904 85
1b8c7ba6
RD
86%rename(InputStream) wxPyInputStream;
87class wxPyInputStream
88{
c368d904 89public:
d14a1e28 90 %extend {
c368d904 91 wxPyInputStream(PyObject* p) {
f74ff5ef
RD
92 wxInputStream* wxis = wxPyCBInputStream::create(p);
93 if (wxis)
94 return new wxPyInputStream(wxis);
c368d904
RD
95 else
96 return NULL;
97 }
98 }
f464a4f2
RD
99 ~wxPyInputStream();
100
c368d904
RD
101 void close();
102 void flush();
103 bool eof();
a541c325
RD
104 PyObject* read(int size=-1);
105 PyObject* readline(int size=-1);
106 PyObject* readlines(int sizehint=-1);
c368d904
RD
107 void seek(int offset, int whence=0);
108 int tell();
f74ff5ef 109
c368d904
RD
110 /*
111 bool isatty();
112 int fileno();
113 void truncate(int size=-1);
114 void write(wxString data);
115 void writelines(wxStringPtrList);
116 */
1e4a197e
RD
117
118 char Peek();
119 char GetC();
120 size_t LastRead();
121 bool CanRead();
122 bool Eof();
123 bool Ungetch(char c);
124
125 long SeekI(long pos, wxSeekMode mode = wxFromStart);
126 long TellI();
d14a1e28 127};
c368d904
RD
128
129
130
131// TODO: make a more fully implemented file interface...
132class wxOutputStream {
133public:
134 /*
135 void close();
136 void flush();
137 wxString* read(int size=-1);
138 wxString* readline(int size=-1);
139 wxStringPtrList* readlines(int sizehint=-1);
140 void seek(int offset, int whence=0);
141 int tell();
142 bool isatty();
143 int fileno();
144 void truncate(int size=-1);
145 void write(wxString data);
146 void writelines(wxStringPtrList);
147 */
148
d14a1e28 149 %extend {
a541c325
RD
150 void write(PyObject* obj) {
151 // We use only strings for the streams, not unicode
152 PyObject* str = PyObject_Str(obj);
153 if (! str) {
154 PyErr_SetString(PyExc_TypeError, "Unable to convert to string");
155 return;
156 }
157 self->Write(PyString_AS_STRING(str),
158 PyString_GET_SIZE(str));
159 Py_DECREF(str);
c368d904
RD
160 }
161 }
23ed80cb 162 size_t LastWrite() const;
c368d904
RD
163};
164
165
d14a1e28 166//---------------------------------------------------------------------------
9416aa89
RD
167%init %{
168 wxPyPtrTypeMap_Add("wxInputStream", "wxPyInputStream");
169%}
d14a1e28 170//---------------------------------------------------------------------------