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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2fa4069595cb9ef7 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!f31g2000pri.googlegroups.com!not-for-mail From: Gene Newsgroups: comp.lang.ada Subject: Re: Breaking a circularity Date: Mon, 28 Mar 2011 12:47:09 -0700 (PDT) Organization: http://groups.google.com Message-ID: <700a06e2-7f55-4933-b1d1-5fe5c3ed3fa5@f31g2000pri.googlegroups.com> References: <5aac3e2d-a382-479e-90a3-8acd846ca204@o21g2000prh.googlegroups.com> NNTP-Posting-Host: 134.240.241.2 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1301341630 19896 127.0.0.1 (28 Mar 2011 19:47:10 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 28 Mar 2011 19:47:10 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: f31g2000pri.googlegroups.com; posting-host=134.240.241.2; posting-account=-BkjswoAAACC3NU8b6V8c50JQ2JBOs04 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.30729; InfoPath.2; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:18547 Date: 2011-03-28T12:47:09-07:00 List-Id: On Mar 28, 5:59=A0am, Ludovic Brenta wrote: > Gene wrote on comp.lang.ada: > > > Need some expert help here with a circularity in the data structures > > for a discrete event simulation. > > > We need event queues and an arbitrary number of event types. =A0The > > handlers for events must have access to a simulation state record, so > > used a generic thus: > [...] > > Here's the circularity: =A0Instantiating an event queue requires the > > simulation state type, but the simulation state must contain an event > > queue (of the instantiated type). > [...] > > Is there a cleaner way to do this? =A0The painful part is introducing a > > pointer to the event queue in State_Type just to break the > > circularity, when this seems superfluous and means I should make > > State_Type controlled to release the queue. > > How about this: > > generic > =A0 =A0type State_Type is tagged private; > package States_With_Event_Queues is > > =A0 =A0type State_With_Event_Queue_Type is new State_Type with private; > > =A0 =A0type Event_Type is abstract tagged limited private; > [...] > =A0 =A0-- other methods not shown. > private > [...] > =A0 =A0-- We are just going to put a thin wrapper around Ada ordered sets > =A0 =A0-- to implement our event queue. > > end States_With_event_Queues; > > Would that work? Interesting. Ought to be fine, but > > BTW, why does Event_Type have to be limited? If it weren't limited, > you would not need Event_Ptr_Type. =A0 Events are "serial numbered" at creation time and meant to be unique. Pointer equality should be equivalent to content equality. > Also, why does it have to be > abstract? Events only have meaning in their specializations to particular kinds, i.e. requests, mission starts, mission completions, etc. So the root event type is just an (abtract) placeholder, not something you'd want to create. Thanks again.