1 with Ada
.Characters
.Handling
;
3 with Ada
.Containers
.Indefinite_Hashed_Maps
;
6 package body Opt50_Pkg
is
8 type Enum_Name
is array (Enum
) of access constant String;
10 Enum_Name_Table
: constant Enum_Name
:= (
11 One
=> new String'("one"),
12 Two => new String'("two"),
13 Three
=> new String'("three"));
15 package String_To_Enum_Map is new Ada.Containers.Indefinite_Hashed_Maps
16 (Key_Type => String, Element_Type => Enum,
17 Hash => Ada.Strings.Hash, Equivalent_Keys => "=");
19 function Fill_Hashed_Map return String_To_Enum_Map.Map is
20 Res : String_To_Enum_Map.Map;
21 use String_To_Enum_Map;
23 for I in Enum_Name_Table'Range loop
25 Kind : constant String := Enum_Name_Table (I).all;
27 Res.Insert(Key => Kind, New_Item => I);
33 String_To_Enum : constant String_To_Enum_Map.Map := Fill_Hashed_Map;
35 procedure Get (Kind : String; Result : out Enum; Success : out Boolean) is
36 X : constant String := Ada.Characters.Handling.To_Lower (Kind);
37 use String_To_Enum_Map;
38 Curs : constant Cursor := String_To_Enum.Find (X);
40 Success := Curs /= No_Element;
42 Result := Element(Curs);
46 procedure Set (A : Enum_Boolean_Array) is null;