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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED.3d73Ybk3C5U4I2t8lv+lAQ.user.gioia.aioe.org!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Simple Components: adding an existing object to a graph Date: Sun, 26 Jan 2020 14:10:55 +0100 Organization: Aioe.org NNTP Server Message-ID: References: <87wo9eikja.fsf@gaheris.vdwege.eu> NNTP-Posting-Host: 3d73Ybk3C5U4I2t8lv+lAQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader01.eternal-september.org comp.lang.ada:57950 Date: 2020-01-26T14:10:55+01:00 List-Id: On 2020-01-26 11:23, Mart van de Wege wrote: > This one's for Dimitry, probably: I want to create a genealogy of > persons using his generic directed weighted graph package. > > I've seen how I can do that like this (example code, assuming an > instantiated Graph): > > type Person is record > Name: Unbounded_String, > Age: Natural > end record; > > and then adding it to the graph with: > > Ancestor : Node := new Person; > > However, assume I already have plenty of code to create and manipulate > Person objects, how do I assign an *existing* object of type Person to a > graph? Trying to do it the obvious way by assigning an access to Person > to a Node object gets me an error message that Node is not a general > access type. The design of the graph is based on keeping edges/links in the memory pool in front of the node itself. That prevents copying of nodes. Thus all instances of Person must be allocated in that pool, which is why the access type is pool-specific. If persons need to be kept outside the pool, which I would not recommend, you could use a reference to person inside the node. BTW, this is how Unbounded_String works. Name in Person actually is a wrapped access type to the string body allocated elsewhere. A compound design would rather be: type Person (Name_Length : Natural) is record -- Everything is here Age : Natural; Name : String (1..Name_Length); end record; P.S. For reference-counted object see Object.Handle, but don't see an immediate need of that. You should simply change function creating Person to return Node. The rest would remain. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de