From: Shark8 <OneWingedShark@gmail.com>
Subject: Re: On packages hierarchy
Date: Tue, 29 Jul 2014 12:44:21 -0600
Date: 2014-07-29T12:44:21-06:00 [thread overview]
Message-ID: <bYRBv.185567$el1.140134@fx26.iad> (raw)
In-Reply-To: <lr84h7$j2k$1@speranza.aioe.org>
On 29-Jul-14 06:36, Victor Porton wrote:
> My raptor stream is derived from some my base class.
Why?
Is there some reason it needs to be exposed to the rest of the binding?
If so, why does it need to be exposed separately from the derivation of
Root_Stream_Type? This is to say given a derivation from
Root_Stream_Type, why not have all parameters that need that type use
that type?
Is it because you want some uniformity of interface?
In that case you could have the "base class" be an interface rather than
a tagged type -- in fact you could do both: have a base-interface from
which your normal raptor-types are rooted in an abstract type and have
the limited types derive from the interface. Ex:
package test is
Type Raptor is limited interface;
-- All common operations of all raptor-types go here.
Procedure First_Stub(Input: Raptor) is abstract;
Type Raptor_Base is abstract new Raptor with null record;
Type Raptor_Stream is new Ada.Streams.Root_Stream_Type and
Raptor with
null record;
Overriding
Procedure First_Stub(Input: Raptor_Stream) is null;
Overriding
procedure Read
(Stream : in out Raptor_Stream;
Item : out Stream_Element_Array;
Last : out Stream_Element_Offset)
is null;
Overriding
procedure Write
(Stream : in out Raptor_Stream;
Item : Stream_Element_Array)
is null;
end test;
> Due no multiple type inheritance in Ada, it cannot be also derived from
> Root_Stream_Type. So I need a wrapper type.
Why expose the raptor-stream at all?
A lot of your problems seem to stem from trying to build from the
low-level thin-binding to the high-level thick-binding while trying to
keep [and expose] the low-level/thin-binding; try going the other way:
*Design the high-level binding first, /then/ in the hidden
implementation/bodies implement-and-use the low-level binding.*
As a trivial example, consider OpenGL's gl_enum type and all the
functions that use it with restrictions best used/expressed as
full-blown types:
package GL_Example is
GL_MAX_LIGHTS : constant := 8;
-- Light is a biased-representation of 1..8.
-- May be implementation dependant, can be rectified with
-- an expression function in the implementation call.
Type Light_Number is range 1..GL_MAX_LIGHTS with size => 3;
-- Safe_Float disallows non-numeric values.
SubType Safe_Float is Float range Float'First..Float'Last;
-- Enumeration of Open_GL's parameters for glLightf
Type Light_Parameters is
(SPOT_EXPONENT, SPOT_CUTOFF, CONSTANT_ATTENUATION,
LINEAR_ATTENUATION, QUADRATIC_ATTENUATION);
-- Thick Binding function.
Procedure Light( Light_No : Light_Number;
Parameter : Light_Parameters;
Value : Safe_Float
) with Inline;
end GL_Example;
package body GL_Example is
-- GL Types
Type GL_Enum is new Interfaces.Unsigned_32;
Type GL_Float is new Interfaces.IEEE_Float_32
Range Interfaces.IEEE_Float_32'Range;
-- Conversions
Function Convert is new Unchecked_Conversion
(Source => Light_Number, Target => GL_Enum);
Function Convert is new Unchecked_Conversion
(Source => Light_Parameters, Target => GL_Enum);
Function Convert is new Unchecked_Conversion
(Source => Safe_Float, Target => GL_Float);
-- Imported (thin-binding) functions
procedure glLightf (light, pname : GL_Enum; param : GL_Float)
with Import, Convention => stdcall, External_Name => "glLightf";
-- Thick-binding bodies
Procedure Light (Light_No : Light_Number;
Parameter : Light_Parameters;
Value : Safe_Float
) is
begin
glLightf( Convert(Light_No), Convert(Parameter),
Convert(Value) );
end Light;
end GL_Example;
next prev parent reply other threads:[~2014-07-29 18:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-28 13:41 On packages hierarchy Victor Porton
2014-07-28 16:03 ` Shark8
2014-07-28 16:35 ` Victor Porton
2014-07-28 23:24 ` Shark8
2014-07-29 12:36 ` Victor Porton
2014-07-29 18:44 ` Shark8 [this message]
2014-07-29 19:42 ` Simon Wright
2014-07-29 21:26 ` Shark8
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox