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 2002:a24:7a05:: with SMTP id a5-v6mr5452955itc.19.1528108165136; Mon, 04 Jun 2018 03:29:25 -0700 (PDT) X-Received: by 2002:a9d:520c:: with SMTP id e12-v6mr464647oth.11.1528108164930; Mon, 04 Jun 2018 03:29:24 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!85.12.16.70.MISMATCH!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.am4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!v8-v6no5009099itc.0!news-out.google.com!z3-v6ni521iti.0!nntp.google.com!u74-v6no5012512itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 4 Jun 2018 03:29:24 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=158.110.28.161; posting-account=9fwclgkAAAD6oQ5usUYhee1l39geVY99 NNTP-Posting-Host: 158.110.28.161 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <564cec8c-8da9-4e59-a687-5408fd3a429f@googlegroups.com> Subject: =?UTF-8?B?IlBsdWdpbsKwLWJhc2VkIGNvZGU=?= From: mockturtle Injection-Date: Mon, 04 Jun 2018 10:29:25 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 4112 X-Received-Body-CRC: 2347575442 Xref: reader02.eternal-september.org comp.lang.ada:52919 Date: 2018-06-04T03:29:24-07:00 List-Id: Dear.all,=20 I have a doubt about what it could be the best solution for some code that = I am writing. I am afraid that the introduction before the actual question= is a bit long. =20 ** The problem ** Let me use an example. Suppose I am writing a program to plot, say, a GANT= T chart. I want the user to be able to choose the output format (say, PDF,= SVG or even LaTeX) by giving a suitable option on the command line and I w= ant to be able to add new output format easily, maybe even load the "format= handler" as a dynamic library at run-time (so I do not need recompilation)= . (Incidentally, I did some experiments with the dynamic loading and it wo= rks) The structure I give to the code is as follows: first I define an interface= for an "abstract plotter," for example package Plotters is=20 type Abstract_Plotter is interface; procedure Line(P: Abstract_Plotter; X1,Y1, X2, Y2:Float)=20 is abstract; -- And so on... end Plotters; Every actual plotter will be a descendant of Abstract_Plotters, for example package Plotters.SVG is type SVG_Plotter is=20 new Abstract_Plotter with private; -- Blah, blah ... end Plotters.SVG; In order to allow the user to select the actual plotter via the command lin= e I use a generic package Plugin_Table that implements a kind of "map" from= names to descendant of Abstract_Plotter. Plugin_Table provides two operat= ions: (1) Register_Plugin(T: Tag; Name: String) =20 used by a concrete plotter to "register" itself to the table. Usu= ally it is called from the "initialization" part of the body of the package= definynig the concrete plotter. For example, plotters-svg.adb could call Register_Plugin(SVG_Plotter'Tag, "svg"); (2) Get_Plugin (Name:String) return Abstract_Plotter'Class to be called to generate a concrete plotter. In a future version Plugin_Table will be able to search for some dynamic li= brary to be loaded if a plugin with the given name is not registered. ** The Question **=20 In order to have all the built-in plugins registered in my executable, I ne= ed to "with" them, so that they are linked to my code and the initializatio= n part of their bodies is elaborated. However, no part of my code call expl= icitly, say, SVG_Plotter. Therefore, my solution is to add something like with Plotters.SVG; pragma Warnings(Off, Plotter.SVG); in the "main." It works, but it leaves me a bit unsatisfied since it seems = an "hack". Also, since no actual code is called directly I am not sure if = the binder could take the liberty of not including them (maybe it cannot, b= ut I am not sure). Do you have any better solution? Also, I am not sure if I risk getting in trouble with Elaboration order. I= think not, but I am not 100% sure. What do you think? Thanks, Riccardo