wxTinderbox build fix.
[wxWidgets.git] / wxPython / include / wx / wxPython / pyistream.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: pyistream.h
3 // Purpose: Classes for managing wxInputStream <--> Python streams
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 25-Sept-2000
8 // RCS-ID: $Id$
9 // Copyright: (c) 2000 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 #ifndef __PYISTREAM__
14 #define __PYISTREAM__
15
16
17 //----------------------------------------------------------------------
18 // Handling of wxInputStreams by Joerg Baumann
19 // See stream.i for implementations
20
21
22 // C++ class wxPyInputStream to act as base for python class wxInputStream
23 // You can use it in python like a python file object.
24 class wxPyInputStream {
25 public:
26 // underlying wxInputStream
27 wxInputStream* m_wxis;
28
29 public:
30 wxPyInputStream(wxInputStream* wxis) : m_wxis(wxis) {}
31 ~wxPyInputStream();
32
33 // python file object interface for input files (most of it)
34 void close();
35 void flush();
36 bool eof();
37 PyObject* read(int size=-1);
38 PyObject* readline(int size=-1);
39 PyObject* readlines(int sizehint=-1);
40 void seek(int offset, int whence=0);
41 int tell();
42
43 /* do these later?
44 bool isatty();
45 int fileno();
46 void truncate(int size=-1);
47 void write(wxString data);
48 void writelines(wxStringPtrList);
49 */
50
51 // wxInputStream methods that may come in handy...
52
53 char Peek() { if (m_wxis) return m_wxis->Peek(); else return -1; }
54 char GetC() { if (m_wxis) return m_wxis->GetC(); else return -1; }
55 size_t LastRead() { if (m_wxis) return m_wxis->LastRead(); else return 0; }
56 bool CanRead() { if (m_wxis) return m_wxis->CanRead(); else return false; }
57 bool Eof() { if (m_wxis) return m_wxis->Eof(); else return false; }
58 bool Ungetch(char c) { if (m_wxis) return m_wxis->Ungetch(c); else return false; }
59
60 unsigned long SeekI(unsigned long pos, wxSeekMode mode)
61 { if (m_wxis) return m_wxis->SeekI(pos, mode); else return 0; }
62 unsigned long TellI() { if (m_wxis) return m_wxis->TellI(); else return 0; }
63 };
64
65
66
67 // This is a wxInputStream that wraps a Python file-like
68 // object and calls the Python methods as needed.
69 class wxPyCBInputStream : public wxInputStream {
70 public:
71 ~wxPyCBInputStream();
72 virtual wxFileOffset GetLength() const;
73
74 // factory function
75 static wxPyCBInputStream* create(PyObject *py, bool block=true);
76
77 wxPyCBInputStream(const wxPyCBInputStream& other);
78
79 protected:
80 // can only be created via the factory
81 wxPyCBInputStream(PyObject *r, PyObject *s, PyObject *t, bool block);
82
83 // wxStreamBase methods
84 virtual size_t OnSysRead(void *buffer, size_t bufsize);
85 virtual size_t OnSysWrite(const void *buffer, size_t bufsize);
86 virtual wxFileOffset OnSysSeek(wxFileOffset off, wxSeekMode mode);
87 virtual wxFileOffset OnSysTell() const;
88
89 // helper
90 static PyObject* getMethod(PyObject* py, char* name);
91
92 PyObject* m_read;
93 PyObject* m_seek;
94 PyObject* m_tell;
95 bool m_block;
96 };
97
98 //----------------------------------------------------------------------
99 #endif