123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- package io
- to_reader :: proc(s: Stream) -> (r: Reader, ok: bool = true) #optional_ok {
- r.stream = s
- if s.stream_vtable == nil || s.impl_read == nil {
- ok = false
- }
- return
- }
- to_writer :: proc(s: Stream) -> (w: Writer, ok: bool = true) #optional_ok {
- w.stream = s
- if s.stream_vtable == nil || s.impl_write == nil {
- ok = false
- }
- return
- }
- to_closer :: proc(s: Stream) -> (c: Closer, ok: bool = true) #optional_ok {
- c.stream = s
- if s.stream_vtable == nil || s.impl_close == nil {
- ok = false
- }
- return
- }
- to_flusher :: proc(s: Stream) -> (f: Flusher, ok: bool = true) #optional_ok {
- f.stream = s
- if s.stream_vtable == nil || s.impl_flush == nil {
- ok = false
- }
- return
- }
- to_seeker :: proc(s: Stream) -> (seeker: Seeker, ok: bool = true) #optional_ok {
- seeker.stream = s
- if s.stream_vtable == nil || s.impl_seek == nil {
- ok = false
- }
- return
- }
- to_read_writer :: proc(s: Stream) -> (r: Read_Writer, ok: bool = true) #optional_ok {
- r.stream = s
- if s.stream_vtable == nil || s.impl_read == nil || s.impl_write == nil {
- ok = false
- }
- return
- }
- to_read_closer :: proc(s: Stream) -> (r: Read_Closer, ok: bool = true) #optional_ok {
- r.stream = s
- if s.stream_vtable == nil || s.impl_read == nil || s.impl_close == nil {
- ok = false
- }
- return
- }
- to_read_write_closer :: proc(s: Stream) -> (r: Read_Write_Closer, ok: bool = true) #optional_ok {
- r.stream = s
- if s.stream_vtable == nil || s.impl_read == nil || s.impl_write == nil || s.impl_close == nil {
- ok = false
- }
- return
- }
- to_read_write_seeker :: proc(s: Stream) -> (r: Read_Write_Seeker, ok: bool = true) #optional_ok {
- r.stream = s
- if s.stream_vtable == nil || s.impl_read == nil || s.impl_write == nil || s.impl_seek == nil {
- ok = false
- }
- return
- }
- to_write_flusher :: proc(s: Stream) -> (w: Write_Flusher, ok: bool = true) #optional_ok {
- w.stream = s
- if s.stream_vtable == nil || s.impl_write == nil || s.impl_flush == nil {
- ok = false
- }
- return
- }
- to_write_flush_closer :: proc(s: Stream) -> (w: Write_Flush_Closer, ok: bool = true) #optional_ok {
- w.stream = s
- if s.stream_vtable == nil || s.impl_write == nil || s.impl_flush == nil || s.impl_close == nil {
- ok = false
- }
- return
- }
- to_reader_at :: proc(s: Stream) -> (r: Reader_At, ok: bool = true) #optional_ok {
- r.stream = s
- if s.stream_vtable == nil || s.impl_read_at == nil {
- ok = false
- }
- return
- }
- to_writer_at :: proc(s: Stream) -> (w: Writer_At, ok: bool = true) #optional_ok {
- w.stream = s
- if s.stream_vtable == nil || s.impl_write_at == nil {
- ok = false
- }
- return
- }
- to_reader_from :: proc(s: Stream) -> (r: Reader_From, ok: bool = true) #optional_ok {
- r.stream = s
- if s.stream_vtable == nil || s.impl_read_from == nil {
- ok = false
- }
- return
- }
- to_writer_to :: proc(s: Stream) -> (w: Writer_To, ok: bool = true) #optional_ok {
- w.stream = s
- if s.stream_vtable == nil || s.impl_write_to == nil {
- ok = false
- }
- return
- }
- to_write_closer :: proc(s: Stream) -> (w: Write_Closer, ok: bool = true) #optional_ok {
- w.stream = s
- if s.stream_vtable == nil || s.impl_write == nil || s.impl_close == nil {
- ok = false
- }
- return
- }
- to_write_seeker :: proc(s: Stream) -> (w: Write_Seeker, ok: bool = true) #optional_ok {
- w.stream = s
- if s.stream_vtable == nil || s.impl_write == nil || s.impl_seek == nil {
- ok = false
- }
- return
- }
- to_byte_reader :: proc(s: Stream) -> (b: Byte_Reader, ok: bool = true) #optional_ok {
- b.stream = s
- if s.stream_vtable == nil || s.impl_read_byte == nil {
- ok = false
- if s.stream_vtable != nil && s.impl_read != nil {
- ok = true
- }
- }
- return
- }
- to_byte_scanner :: proc(s: Stream) -> (b: Byte_Scanner, ok: bool = true) #optional_ok {
- b.stream = s
- if s.stream_vtable != nil {
- if s.impl_unread_byte == nil {
- ok = false
- return
- }
- if s.impl_read_byte != nil {
- ok = true
- } else if s.impl_read != nil {
- ok = true
- } else {
- ok = false
- }
- }
- return
- }
- to_byte_writer :: proc(s: Stream) -> (b: Byte_Writer, ok: bool = true) #optional_ok {
- b.stream = s
- if s.stream_vtable == nil || s.impl_write_byte == nil {
- ok = false
- if s.stream_vtable != nil && s.impl_write != nil {
- ok = true
- }
- }
- return
- }
- to_rune_reader :: proc(s: Stream) -> (r: Rune_Reader, ok: bool = true) #optional_ok {
- r.stream = s
- if s.stream_vtable == nil || s.impl_read_rune == nil {
- ok = false
- if s.stream_vtable != nil && s.impl_read != nil {
- ok = true
- }
- }
- return
- }
- to_rune_scanner :: proc(s: Stream) -> (r: Rune_Scanner, ok: bool = true) #optional_ok {
- r.stream = s
- if s.stream_vtable != nil {
- if s.impl_unread_rune == nil {
- ok = false
- return
- }
- if s.impl_read_rune != nil {
- ok = true
- } else if s.impl_read != nil {
- ok = true
- } else {
- ok = false
- }
- } else {
- ok = false
- }
- return
- }
|