comp.lang.ada
 help / color / mirror / Atom feed
From: Gene <gene.ressler@gmail.com>
Subject: Re: Breaking a circularity
Date: Mon, 28 Mar 2011 12:47:09 -0700 (PDT)
Date: 2011-03-28T12:47:09-07:00	[thread overview]
Message-ID: <700a06e2-7f55-4933-b1d1-5fe5c3ed3fa5@f31g2000pri.googlegroups.com> (raw)
In-Reply-To: 5aac3e2d-a382-479e-90a3-8acd846ca204@o21g2000prh.googlegroups.com

On Mar 28, 5:59 am, Ludovic Brenta <ludo...@ludovic-brenta.org> 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.  The
> > handlers for events must have access to a simulation state record, so
> > used a generic thus:
> [...]
> > Here's the circularity:  Instantiating 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?  The 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
>    type State_Type is tagged private;
> package States_With_Event_Queues is
>
>    type State_With_Event_Queue_Type is new State_Type with private;
>
>    type Event_Type is abstract tagged limited private;
>
  [...]
>    -- other methods not shown.
> private
>
  [...]
>    -- We are just going to put a thin wrapper around Ada ordered sets
>    -- 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.  

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.



  parent reply	other threads:[~2011-03-28 19:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-28  4:11 Breaking a circularity Gene
2011-03-28  9:59 ` Ludovic Brenta
2011-03-28 11:37   ` Simon Wright
2011-03-28 22:38     ` Gene
2011-03-29  3:01       ` Randy Brukardt
2011-03-28 19:47   ` Gene [this message]
2011-03-28 10:15 ` Simon Wright
2011-03-28 21:31   ` Gene
2011-03-28 11:06 ` Martin
2011-03-28 22:26   ` Gene
2011-03-29 16:28     ` Martin
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox