comp.lang.ada
 help / color / mirror / Atom feed
From: Gautier write-only <gautier_niouzes@hotmail.com>
Subject: Record type as generic parameter
Date: Thu, 13 Aug 2009 02:52:52 -0700 (PDT)
Date: 2009-08-13T02:52:52-07:00	[thread overview]
Message-ID: <2698b15a-7a94-45b5-90af-d0fb5929b1cf@w41g2000yqb.googlegroups.com> (raw)

Hello,
Let's say I have an enumerated type called Scenario, and I want to
fill some data structure with the following information: for each
scenario, I have a certain number of items (of a defined type), which
is varying according to the scenario. That information is stored in an
array with pairs (scenario, item). An item might by appearing in
several scenarios, it is why I don't have simply an array(Item) of
Scenario. Everything fine up to now. Now, I would like to make it
generic, since I have several sets of scenario - i.e. different
enumerated types like Scenario. Then, my favourite Ada compiler
doesn't want a record as generic parameter:

      generic
        type Scenario is range <>;
        type Association is record
          scen: Scenario;
          it  : Item;
        end record;
        scenario_definition: array(Positive range <>) of Association;
      procedure Fill_Scenarios;

Any nice workaround ?
A not-so-nice one is to have two arrays, one array of Scenario, one
array of Item.
Ideally I would keep the type like Association above.
  XY_scenario_definition:
    constant array(Positive range <>) of XY_Association:=
    (
      (Scen_abc, Item_56),
      (Scen_abc, Item_345),
      (Scen_uvw, Item_12),
     ..
The data are easier to pump from a database directly as Ada sources,
they are then easier to read, and there is no chance of messing
positions as with the two arrays solution.
TIA
_________________________________________________________
Gautier's Ada programming -- http://sf.net/users/gdemont/
NB: For a direct answer, e-mail address on the Web site!




             reply	other threads:[~2009-08-13  9:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-13  9:52 Gautier write-only [this message]
2009-08-13 10:23 ` Record type as generic parameter Jean-Pierre Rosen
2009-08-13 13:34   ` Gautier write-only
2009-08-13 10:30 ` Jacob Sparre Andersen
replies disabled

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