* subtype definitions
@ 2012-09-26 13:45 björn lundin
2012-09-26 13:58 ` Niklas Holsti
0 siblings, 1 reply; 3+ messages in thread
From: björn lundin @ 2012-09-26 13:45 UTC (permalink / raw)
Hi!
I got a type definition as
type Assignment_Type_Type is (Transport, Store, Retrieve, Rearrange, Check,
Set_Error, Restore, Mob_Trsp1, Mob_Trsp2,
Mob_Trsp3, Mob_Trsp4, Mob_Store, Mob_Check);
I want to loop through some of the values, in another order
for Asm_Type in Transport | Check | Restore | Set_Error | Store loop
Do_Something(Asm_Type);
end loop;
The above does not compile.
subtype Asm_Type_Type is Assignment_Type_Type range Transport | Check | Restore | Set_Error | Store ;
no go .
Is there a valid construction in Ada 05 (gnat) that I can use?
http://en.wikibooks.org/wiki/Ada_Programming/Subtypes
has a long discussion, but none with
elements in different order, only like Retrieve .. Check
--
Björn Lundin
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: subtype definitions
2012-09-26 13:45 subtype definitions björn lundin
@ 2012-09-26 13:58 ` Niklas Holsti
2012-09-26 14:36 ` björn lundin
0 siblings, 1 reply; 3+ messages in thread
From: Niklas Holsti @ 2012-09-26 13:58 UTC (permalink / raw)
On 12-09-26 16:45 , bj�rn lundin wrote:
> Hi!
>
> I got a type definition as
>
> type Assignment_Type_Type is (Transport, Store, Retrieve, Rearrange, Check,
> Set_Error, Restore, Mob_Trsp1, Mob_Trsp2,
> Mob_Trsp3, Mob_Trsp4, Mob_Store, Mob_Check);
>
> I want to loop through some of the values, in another order
>
> for Asm_Type in Transport | Check | Restore | Set_Error | Store loop
> Do_Something(Asm_Type);
> end loop;
>
> The above does not compile.
>
> subtype Asm_Type_Type is Assignment_Type_Type range Transport | Check | Restore | Set_Error | Store ;
> no go .
>
> Is there a valid construction in Ada 05 (gnat) that I can use?
This is what comes to mind, apart from a simple sequence of calls to
Do_Something:
Loop_Order : constant array (Integer range <>)
of Assignment_Type_Type :=
(Transport, Check, Restore, Set_Error, Store);
for L in Loop_Order'Range loop
Do_Something (Loop_Order(L));
end loop;
--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
. @ .
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: subtype definitions
2012-09-26 13:58 ` Niklas Holsti
@ 2012-09-26 14:36 ` björn lundin
0 siblings, 0 replies; 3+ messages in thread
From: björn lundin @ 2012-09-26 14:36 UTC (permalink / raw)
Den onsdagen den 26:e september 2012 kl. 15:58:05 UTC+2 skrev Niklas Holsti:
> Loop_Order : constant array (Integer range <>)
> of Assignment_Type_Type :=
> (Transport, Check, Restore, Set_Error, Store);
> for L in Loop_Order'Range loop
> Do_Something (Loop_Order(L));
> end loop;
>
Thanks.
Final result:
States : constant array (Integer range <>) of Queue.State_Type := (Queue.Loaded, Queue.Started, Queue.Queued);
Trp_Types : constant array (Integer range <>) of Core_Types. Assignment_Type_Type := (Core_Types.Transport,
Core_Types.Check,
Core_Types.Restore,
Core_Types.Set_Error,
Core_Types.Store);
begin
for i in States'range loop
for j in Trp_Types'range loop
Queue.Get_Assignments(State=> States(i), Asm_Type => Trp_Types(j) , List => An_Asm_List);
Treat_Restart_List (State=> States(i), Asm_Type => Trp_Types(j) , List => An_Asm_List);
end loop;
end loop;
works well :-)
--
Björn Lundin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-09-26 14:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-26 13:45 subtype definitions björn lundin
2012-09-26 13:58 ` Niklas Holsti
2012-09-26 14:36 ` björn lundin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox