]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/pyistream.h
Various changes needed to get up to date with current CVS
[wxWidgets.git] / wxPython / src / 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 // list class for return list of strings, e.g. readlines()
22 WX_DECLARE_LIST(wxString, wxStringPtrList);
23
24
25 // C++ class wxPyInputStream to act as base for python class wxInputStream
26 // You can use it in python like a python file object.
27 class wxPyInputStream {
28 public:
29 // underlying wxInputStream
30 wxInputStream* m_wxis;
31
32 public:
33 wxPyInputStream(wxInputStream* wxis) : m_wxis(wxis) {}
34 ~wxPyInputStream();
35
36 // python file object interface for input files (most of it)
37 void close();
38 void flush();
39 bool eof();
40 PyObject* read(int size=-1);
41 PyObject* readline(int size=-1);
42 PyObject* readlines(int sizehint=-1);
43 void seek(int offset, int whence=0);
44 int tell();
45
46 /* do these later?
47 bool isatty();
48 int fileno();
49 void truncate(int size=-1);
50 void write(wxString data);
51 void writelines(wxStringPtrList);
52 */
53
54 // wxInputStream methods that may come in handy...
55
56 char Peek() { if (m_wxis) return m_wxis->Peek(); else return -1; }
57 char GetC() { if (m_wxis) return m_wxis->GetC(); else return -1; }
58 size_t LastRead() { if (m_wxis) return m_wxis->LastRead(); else return 0; }
59 bool CanRead() { if (m_wxis) return m_wxis->CanRead(); else return FALSE; }
60 bool Eof() { if (m_wxis) return m_wxis->Eof(); else return FALSE; }
61 bool Ungetch(char c) { if (m_wxis) return m_wxis->Ungetch(c); else return FALSE; }
62
63 unsigned long SeekI(unsigned long pos, wxSeekMode mode)
64 { if (m_wxis) return m_wxis->SeekI(pos, mode); else return 0; }
65 unsigned long TellI() { if (m_wxis) return m_wxis->TellI(); else return 0; }
66 };
67
68
69
70 // This is a wxInputStream that wraps a Python file-like
71 // object and calls the Python methods as needed.
72 class wxPyCBInputStream : public wxInputStream {
73 public:
74 ~wxPyCBInputStream();
75 virtual size_t GetSize() const;
76
77 // factory function
78 static wxPyCBInputStream* create(PyObject *py, bool block=TRUE);
79
80 protected:
81 // can only be created via the factory
82 wxPyCBInputStream(PyObject *r, PyObject *s, PyObject *t, bool block);
83
84 // wxStreamBase methods
85 virtual size_t OnSysRead(void *buffer, size_t bufsize);
86 virtual size_t OnSysWrite(const void *buffer, size_t bufsize);
87 virtual off_t OnSysSeek(off_t off, wxSeekMode mode);
88 virtual off_t OnSysTell() const;
89
90 // helper
91 static PyObject* getMethod(PyObject* py, char* name);
92
93 PyObject* m_read;
94 PyObject* m_seek;
95 PyObject* m_tell;
96 bool m_block;
97 };
98
99 //----------------------------------------------------------------------
100 #endif