[Vala] How to extend IOStream in Vala?
- From: Paul Jakma <paul jakma org>
- To: vala-list gnome org
- Subject: [Vala] How to extend IOStream in Vala?
- Date: Mon, 21 Nov 2011 10:50:31 +0000 (GMT)
Hi,
I want to extend IOStream, to create a memory channel based IO stream, by
wrapping around some modified Memory{In,Out}putStreams. However, it
doesn't seem to be possible, because the input_stream and output_stream
properties of IOStream are read-only. I get this warning if I try to set
them from my extending class:
MemoryIOStream.vala:44.5-44.23: error: Property
`GLib.IOStream.input_stream' is read-only
If I try to define these fields in my extending class, i.e.:
public InputStream input_stream { public get; private set; }
public OutputStream output_stream { public get; private set; }
I get a warning that I'm hiding the visibility of the inherited
property[1]:
warning: MemoryIOStream.output_stream hides inherited property
`GLib.IOStream.output_stream'. Use the `new' keyword if hiding was
intentional
and then, if I use Object (input_stream : ..., output_stream ...) to set
these properties I get a runtime error from GLib:
(process:16186): GLib-GObject-WARNING **: g_object_newv: property
`input-stream' of object class `MemoryIOStream' is not writable
(process:16186): GLib-GObject-WARNING **: g_object_newv: property
`output-stream' of object class `MemoryIOStream' is not writable
So clearly, it's the base class property being invoked (the code is
accessing via the base type of IOStream). OTOH, if I set them with
'output_stream = ....', then I get a crash as the properties are never
set, if the object is invoked via the IOStream type. If I add the 'new'
keyword, it gets rid of the hiding warning, but doesn't make any other
discernible difference.
My problem then is that I don't see how I can extend IOStream reliably,
when there doesn't seem to be any way to set or fully override the base
class's properties. Is there any way? Or does the Vala VAPI for IOStream
need to be modified to allow the properties to be set by child classes? Or
is that not even possible with extensions of classes and properties?
1. Incidentally, I couldn't find the 'new' modifier for properties
documented anywhere.
regards,
--
Paul Jakma paul jakma org twitter: @pjakma PGP: 64A2FF6A
Fortune:
The only thing that experience teaches us is that experience teaches us nothing.
-- Andre Maurois (Emile Herzog)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]