]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/src/pyistream.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Classes for managing wxInputStream <--> Python streams
7 // Created: 25-Sept-2000
9 // Copyright: (c) 2000 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
17 //----------------------------------------------------------------------
18 // Handling of wxInputStreams by Joerg Baumann
19 // See stream.i for implementations
21 // list class for return list of strings, e.g. readlines()
22 WX_DECLARE_LIST(wxString
, wxStringPtrList
);
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
{
29 // underlying wxInputStream
30 wxInputStream
* m_wxis
;
33 wxPyInputStream(wxInputStream
* wxis
) : m_wxis(wxis
) {}
36 // python file object interface for input files (most of it)
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);
49 void truncate(int size=-1);
50 void write(wxString data);
51 void writelines(wxStringPtrList);
54 // wxInputStream methods that may come in handy...
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
; }
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; }
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
{
75 virtual size_t GetSize() const;
78 static wxPyCBInputStream
* create(PyObject
*py
, bool block
=TRUE
);
81 // can only be created via the factory
82 wxPyCBInputStream(PyObject
*r
, PyObject
*s
, PyObject
*t
, bool block
);
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;
91 static PyObject
* getMethod(PyObject
* py
, char* name
);
99 //----------------------------------------------------------------------