From: tmoran@acm.org
Subject: Re: Streams Quandry in Ada95
Date: Wed, 13 Dec 2000 18:49:28 GMT
Date: 2000-12-13T18:49:28+00:00 [thread overview]
Message-ID: <YwPZ5.25237$M5.917159@news1.frmt1.sfba.home.com> (raw)
In-Reply-To: 3A37B3C3.86CFCF66@home.com
>So how do I write a procedure that says:
>
>procedure Pump(In_Str, Out_Str: Any_Stream_Derived_From Audio_Stream);
procedure Pump(In_Str, Out_Str: in out Audio_Stream'Class);
>I can avoid the abstract problem by deriving from Audio_Stream and providing
>no-op primitives for the abstract primitives. But if other streams derive from this,
>they may forget to override those no-op primitives (though I could cheat and
>raise exceptions... leading to run-time checks).
Forget the no-ops, just make the primitives of the abstract Audio_Stream
themselves abstract. Then anybody deriving a new non-abstract kind of
Audio_Stream will be *required by the compiler* to supply overrides for
the abstract primitives.
Thus
type Raw_Sample_Type is range 0 .. 127; -- or whatever
type Audio_Stream is abstract tagged null record;
function Get(Data : Audio_Stream) return Raw_Sample_Type is abstract;
procedure Put(Sample : in Raw_Sample_Type; Data : in out Audio_Stream)
is abstract;
procedure Pump(In_Str, Out_Str: in out Audio_Stream'Class);
...
procedure Pump(In_Str, Out_Str: in out Audio_Stream'Class) is
Sample : Raw_Sample_Type;
begin
loop
Sample := Get(In_Str);
Put(Sample, Out_Str);
end loop;
end Pump;
Is this the sort of thing you want to do?
next prev parent reply other threads:[~2000-12-13 18:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <3A370548.B8AF2579@home.com>
2000-12-13 16:27 ` Streams Quandry in Ada95 Stephen Leake
2000-12-13 17:39 ` Warren W. Gay VE3WWG
2000-12-13 18:49 ` tmoran [this message]
2000-12-13 20:04 ` Warren W. Gay VE3WWG
2000-12-14 2:35 ` Streams Quandry in Ada95 (SOLVED) Warren W. Gay VE3WWG
2000-12-14 12:08 ` Streams Quandry in Ada95 Robert Dewar
2000-12-14 14:19 ` Warren W. Gay VE3WWG
2000-12-14 21:43 ` Sergey Koshcheyev
2000-12-13 18:58 ` Anders Gidenstam
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox