1 #############################################################################
3 ## Purpose: XS for Wx::*Stream wrappers (using tie)
4 ## Author: Mattia Barbon
7 ## RCS-ID: $Id: Stream.xs 2059 2007-06-21 19:37:14Z mbarbon $
8 ## Copyright: (c) 2001-2003, 2007 Mattia Barbon
9 ## Licence: This program is free software; you can redistribute it and/or
10 ## modify it under the same terms as Perl itself
11 #############################################################################
13 #include <wx/wfstream.h>
15 MODULE=Wx PACKAGE=Wx::Stream
18 TIEHANDLE( package, var )
22 RETVAL = newSViv( 0 ); // as usual: XSUBpp mortalizes it for us...
23 sv_setref_pv( RETVAL, CHAR_P package, var );
27 MODULE=Wx PACKAGE=Wx::InputStream
30 Wx_InputStream::READ( buf, len, offset = 0 )
37 if( THIS->Eof() ) { SvOK_off( buf ); XSRETURN_IV( 0 ); }
39 maxlen = SvPOK( buf ) ? SvCUR( buf ) : 0;
43 if( abs( offset ) > maxlen )
47 offset = maxlen + offset;
50 char* buffer = SvGROW( buf, (UV)offset + len + 1 );
53 Zero( buffer + maxlen, offset - maxlen, char );
55 RETVAL = THIS->Read( buffer, len ).LastRead();
56 SvCUR_set( buf, offset + RETVAL );
61 Wx_InputStream::GETC()
63 char value = THIS->GetC();
64 RETVAL = newSVpvn( &value, 1 );
69 Wx_InputStream::SEEK( position, whence )
73 static wxSeekMode s_whence[] = { wxFromStart, wxFromCurrent, wxFromEnd };
75 if( whence < 0 || whence > 2 )
76 RETVAL = &PL_sv_undef;
77 off_t offset = THIS->SeekI( position, s_whence[whence] );
78 RETVAL = newSViv( offset );
83 Wx_InputStream::TELL()
85 off_t offset = THIS->TellI();
86 RETVAL = newSViv( offset );
91 Wx_InputStream::READLINE()
97 if( THIS->Eof() ) { XSRETURN_UNDEF; }
98 RETVAL = newSViv( 0 );
99 buff = SvPV_nolen( RETVAL );
101 while( THIS->CanRead() && THIS->Read( &c, 1 ).LastRead() != 0 )
103 if( SvLEN( RETVAL ) <= off )
105 buff = SvGROW( RETVAL, off + 15 );
109 if( c == '\n' ) break;
111 SvCUR_set( RETVAL, off );
114 MODULE=Wx PACKAGE=Wx::OutputStream
117 Wx_OutputStream::WRITE( buf, len = -1, offset = 0 )
122 IV maxlen = sv_len( buf );
123 const char* buffer = SvPV_nolen( buf );
125 if( abs( offset ) > maxlen )
136 buffer += maxlen + offset;
140 len = ( len >= maxlen ) ? maxlen : len;
142 RETVAL = THIS->Write( buffer, len ).LastWrite();
148 Wx_OutputStream::SEEK( position, whence )
152 static wxSeekMode s_whence[] = { wxFromStart, wxFromCurrent, wxFromEnd };
154 if( whence < 0 || whence > 2 )
155 RETVAL = &PL_sv_undef;
156 off_t offset = THIS->SeekO( position, s_whence[whence] );
157 RETVAL = newSViv( offset );
162 Wx_OutputStream::TELL()
164 off_t offset = THIS->TellO();
165 RETVAL = newSViv( offset );