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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,dbbbb21ed7f581b X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!news.belwue.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Operation can be dispatching in only one type Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <025105f2-5571-400e-a66f-ef1c3dc9ef32@g27g2000yqn.googlegroups.com> Date: Fri, 13 Nov 2009 21:34:25 +0100 Message-ID: <1fgkluza4covm.5lfcsusar8cy$.dlg@40tude.net> NNTP-Posting-Date: 13 Nov 2009 21:34:26 CET NNTP-Posting-Host: 2d0d8655.newsspool3.arcor-online.net X-Trace: DXC=J56;nmeARHQmG86`U=_nC_McF=Q^Z^V3X4Fo<]lROoRQ8kF On Fri, 13 Nov 2009 12:12:18 -0800 (PST), xorque wrote: > I'm trying to write an archive/directory abstraction in a similar vein > to PhysicsFS > but am at a bit of a loss as to how to design the archiver interface: > > with Path; > > package Archiver is > > type Archiver_t is abstract tagged limited private; > type Archiver_Class_Access_t is access Archiver_t'Class; > > procedure Init > (Archiver : out Archiver_t) is abstract; > > function Can_Mount > (Archiver : in Archiver_t; > Path : in Path.Real_t) return Boolean is abstract; > > type File_t is abstract tagged limited private; > type File_Class_Access_t is access File_t'Class; > > procedure Open > (Archiver : in Archiver_t; > Path : in Path.Virtual_t; > File : out File_t) is abstract; > > procedure Close > (File : in out File_t) is abstract; > > private > > type Archiver_t is abstract tagged limited null record; > > type File_t is abstract tagged limited null record; > > end Archiver; > > The idea of the above is that the main part of the library only deals with > archivers and "files" (which might only really be pointers to entries in Zip > files, for example) by 'Class. > > The problem with the above is that: > > archiver.ads:18:13: operation can be dispatching in only one type > > Hopefully someone here knows a better way to handle this. Ada does not support multiple dispatch of this form. For simplicity consider it does not support MD at all. According to your code Open is doubly dispatching in Archiver_t and File_t arguments. That does not work (unfortunately). You have to choose one and make another class-wide. E.g. procedure Open (Archiver : Archiver_t'Class; -- Class-wide Path : Virtual_t; File : in out File_t) is abstract; This would be a primitive operation of File_t only. P.S. If you indeed have to do MD, you should emulate it manually, by dispatching within Open to some primitive operation of Archiver_t. P.P.S. Do not use access types unless you need them. P.P.P.S. Replace tagged limited with Ada.Finalization.Limited_Controlled, sooner or later you almost certainly will need finalization and initialization. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de