From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.182.79.35 with SMTP id g3mr30623542obx.22.1441796930101; Wed, 09 Sep 2015 04:08:50 -0700 (PDT) X-Received: by 10.182.105.34 with SMTP id gj2mr130591obb.34.1441796930077; Wed, 09 Sep 2015 04:08:50 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!kq10no2202019igb.0!news-out.google.com!f6ni5575igi.0!nntp.google.com!kq10no2202013igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 9 Sep 2015 04:08:49 -0700 (PDT) In-Reply-To: <87y4ggm71k.fsf@adaheads.sparre-andersen.dk> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=155.210.217.198; posting-account=ZsBWjAoAAACn5uHwNWb19e60TrEtWbAD NNTP-Posting-Host: 155.210.217.198 References: <625c79d2-f5ed-4cd4-80ea-ea310e381017@googlegroups.com> <87y4ggm71k.fsf@adaheads.sparre-andersen.dk> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: working with diferent instances of the same generic interface From: Aitor Alcrudo Sangros Injection-Date: Wed, 09 Sep 2015 11:08:50 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:27748 Date: 2015-09-09T04:08:49-07:00 List-Id: El mi=E9rcoles, 9 de septiembre de 2015, 8:38:18 (UTC+2), Jacob Sparre Ande= rsen escribi=F3: > Aitor Alcrudo Sangros wrote: >=20 > > Hi, my google-fu can't find how to do this. I think it should be > > doable but I'm not 100% sure. I'm thankful if anyone helps. >=20 > Your examples don't compile. Please post a compilable version. >=20 > Also. It appears to me that you can omit using access types completely. >=20 > Greetings, >=20 > Jacob > --=20 > There only exist 10 kinds of people: Those who know binary > numbers and those who don't know binary numbers. Hi, I'm not really specifically tring to make that code work as is. What I = want to know is how can I work with different instances of the same generic= interface, doing things like iterating over a collection of them. This is = a minimal example of how I am (unsuccessfully ) tring to do so. Anyway this= code compiles, then has a runtime exception. with Ada.Containers.Vectors; with Ada.Text_IO; Use Ada.Text_IO; procedure test is =20 =20 package Intro is=20 type Data_type is interface;=20 generic=20 type Readable_Data is abstract new Data_type with private;=20 package Readable is=20 type Readable_Element is interface;=20 type Readable_Element_Access is access all Readable_Element'Class = ;=20 function Get_Values (this : Readable_Element ) return Readable_Dat= a'Class=20 is abstract;=20 end Readable;=20 type state is (OK,KO);=20 generic=20 with package Readable_Reporting is new Readable(<>);=20 use Readable_Reporting ;=20 package Reporting is=20 type Reporting_Element is interface and Readable_Element ;=20 type Reporting_Element_Access is access all Reporting_Element'Clas= s;=20 function Report (This :Reporting_Element ) return state is Abstra= ct;=20 overriding function Get_Values (this : Reporting_Element ) return= =20 Readable_Data'Class is abstract;=20 end Reporting;=20 end Intro;=20 -- use Intro; =20 =20 --ELEMENT A type SomeData is new Intro.Data_type with record=20 a :float;=20 end record;=20 =09 package Readable_Some is new Intro.Readable(=20 readable_data =3D>SomeData);=20 package Reporting_Some is new Intro.Reporting(Readable_Some);=20 type Element_type_A is new Readable_Some.Readable_Element=20 and Reporting_Some.Reporting_Element= =20 with record=20 data :SomeData :=3D SomeData'(a =3D> 0.0 );=20 end record;=20 type Element_type_A_Access is access all Element_type_A'Class; =20 overriding function Report(This : Element_Type_A ) return Intro.state is= ( Intro.KO); function Get_Values (this : Element_type_A ) return SomeData'Class is (this.data); =20 -- ELEMENT B =20 type OtherData is new Intro.Data_type with record=20 a :float;=20 end record;=20 package Readable_Other is new Intro.Readable(=20 readable_data =3D>OtherData);=20 package Reporting_Other is new Intro.Reporting(Readable_Other);=20 type Element_type_B is new Readable_Other.Readable_Element=20 and Reporting_Other.Reporting_Element= =20 with record=20 data :OtherData;=20 end record; =20 type Element_type_B_Access is access all Element_type_B'Class;=20 function Get_Values (this : Element_type_B ) return OtherData'Class is (this.data); function Report(This : Element_type_B ) return Intro.state is ( Intro.KO= ); =20 --MANAGER -- package Readable_basic is new Intro.Readable(Intro.Data_type );=20 package Reporting_basic is new Intro.Reporting(Readable_basic); use Reporting_basic; package Element_Vector is new Ada.Containers.Vectors (Natural,Reporting_basic.Reporting_Element_Ac= cess); use Element_Vector; =20 type Manager is tagged record =20 elements : Element_Vector.Vector; end record; procedure Add_Element(this : in out Manager ; Element : in Reporting_Element_Access ) is begin this.elements.Append(Element); end Add_Element; =20 Man : Manager; Elm1_ptr : Element_type_A_Access :=3D new Element_type_A; Elm2_ptr : Element_type_B_Access :=3D new Element_type_B; begin =20 Add_Element(Man,Reporting_basic.Reporting_Element_Access(Elm1_ptr)); Add_Element(Man,Reporting_basic.Reporting_Element_Access(Elm2_ptr)); put_Line("hello world"); =20 end test; The problem might be in how I am instancing the generic for manager (readab= le_basic and reporting_basic), but I can't use a box association or unconst= rained type in there.