|
|
DataMuseum.dkPresents historical artifacts from the history of: Rational R1000/400 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Rational R1000/400 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 14336 (0x3800)
Types: Ada Source
Notes: 03_class, FILE, R1k_Segment, e3_tag, package body Associations_Generic_Enumerated_To_String, seg_0046d4
└─⟦8527c1e9b⟧ Bits:30000544 8mm tape, Rational 1000, Arrival backup of disks in PAM's R1000
└─⟦cfc2e13cd⟧ »Space Info Vol 2«
└─⟦this⟧
with Maps;
with String_Utilities;
package body Associations_Generic_Enumerated_To_String is
Null_Association : constant String := "";
function Is_Separator (This_Character : in Character) return Boolean is
begin
return This_Character = Separator;
end Is_Separator;
package Associations is new Maps (Is_Separator);
function Normalized (This_String : in String; Ignore_Case : in Boolean)
return String is
begin
if Ignore_Case then
return String_Utilities.Upper_Case (This_String);
else
return This_String;
end if;
end Normalized;
function Is_Associated (This_String : in String;
With_This_Key : in Keys;
Ignore_Case : in Boolean := True) return Boolean is
The_Associations : Associations.Map;
The_Association : Associations.Mapping;
The_Key : constan String := Keys'Image (With_This_Key);
The_String : constant String := Normalized (This_String, Ignore_Case);
begin
The_Associations := Associations.Create
(From_Map_File => Associations_File);
begin
The_Association := Associations.Mapping_For
(The_Key, The_Associations);
Associations.Reset (The_Association);
while not Associations.Done (The_Association) loop
if Associations.Current (The_Association) = The_String then
Associations.Dispose (The_Associations);
return True; -- Found it.
end if;
Associations.Next (The_Association);
end loop;
Associations.Dispose (The_Associations);
return False;
exception
when Associations.No_Mapping =>
Associations.Dispose (The_Associations);
return False;
end;
exception
when Associations.Io_Failure =>
raise Io_Failure;
end Is_Associated;
procedure Associate (This_String : in String;
With_This_Key : in Keys;
Unique : in Boolean := False;
Ignore_Case : in Boolean := True) is
The_Associations : Associations.Map;
The_Association : Associations.Mapping;
The_Key : constant String := Keys'Image (With_This_Key);
The_String : constant String := Normalized (This_String, Ignore_Case);
Was_Modified : Boolean := False;
Was_Already_Associated : Boolean := False;
begin
if The_String = Null_Association then
raise Bad_Entry;
end if;
The_Associations := Associations.Create
(From_Map_File => Associations_File);
if nique then
-- Get rid of all associations to other keys.
for Current_Key in Keys loop
begin
The_Association :=
Associations.Mapping_For
(Keys'Image (Current_Key), The_Associations);
Associations.Reset (The_Association);
while not Associations.Done (The_Association) loop
if Associations.Current (The_Association) =
The_String then
if Current_Key = With_This_Key then
Was_Already_Associated := True;
exit;
else
Associations.Modify
(The_Association,
Null_Association); -- Turn off association.
Was_Modified := True;
end if;
end if;
Associations.Next (The_Association);
end loop;
if Was_Modified then
Associations.Add (The_Association, The_Associations);
end if;
exception
when Associations.No_Mapping =>
null;
end;
end loop;
end if;
if Was_Already_Associated then
if Was_Modified then
Associations.Save (Associations_File, The_Associations);
end if;
else
-- Create the association.
begin
The_Association := Associations.Mapping_For
(The_Key, The_Associations);
Associations.Reset (The_Association);
while not Associations.Done (The_Association) loop
if Associations.Current (The_Association) = The_String then
Was_Already_Associated := True;
exit;
end if;
Associations.Next (The_Association);
end loop;
if not Was_Already_Associated then
Associations.Add (This_Field => The_String,
To_Mapping => The_Association,
Using_Separator => Separator);
Associations.Add (The_Association, The_Associations);
Associations.Save (Associations_File, The_Associations);
end if;
exception
when Associations.No_Mapping => -- Brand new key.
Associations.Add (This_Mapping =>
The_Key & Separator & The_String,
To_Map => The_Associations);
Associations.Save (Associations_File, The_Associations);
end;
end if;
Associations.Dispose (The_Associations);
exception
when Associations.Io_Failure =>
raise Io_Failure;
end Associate;
procedure Dissociate (This_String : in String;
From_This_Key : in Keys;
Ignore_Case : in Boolean := True) is
The_Associations : Associations.Map;
The_Association : Associations.Mapping;
The_Key : constant String := Keys'Image (From_This_Key);
The_String : constant String := Normalized (This_String, Ignore_Case);
Was_Modified : Boolean := False;
begin
The_Associations := Associations.Create
(From_Map_File => Associations_File);
begin
The_Association := Associations.Mapping_For
(The_Key, The_Associations);
Associations.Reset (The_Association);
while not Associations.Done (The_Association) loop
if Associations.Current (The_Association) = The_String then
Associations.Modify (The_Association, Null_Association);
Was_Modified := True;
end if;
-- Keep going, might be duplicates.
Associations.Next (The_Association);
end loop;
if Was_Modified then
Associations.Add (The_Association, The_Associations);
Associations.Save (Associations_File, The_Associations);
end if;
exception
when Associations.No_Mapping =>
null;
end;
Associations.Dispose (The_Associations);
exception
when Associations.Io_Failure =>
raise Io_Failure;
end Dissociate;
function Strings_Associated_With
(This_Key : in Keys; Ignore_Case : in Boolean := True)
return Strings is
The_Strings : Strings := Lines.Create;
The_Associations : Associations.Map;
The_Association : Associations.Mapping;
The_Key : constant String := Keys'Image (This_Key);
begin
The_Associations := Associations.Create
(From_Map_File => Associations_File);
begin
The_Association := Associations.Mapping_For
(The_Key, The_Associations);
Associations.Reset (The_Association);
Associations.Next (The_Association); -- Ignore key field.
while not Associations.Done (The_Association) loop
declare
Current_String : constant String :=
Normalized (Associations.Current (The_Association),
Ignore_Case);
begin
if Current_String /= Null_Association then
Lines.Add (The_Strings, Lines.Create (Current_String));
end if;
end;
Associations.Next (The_Association);
end loop;
exception
when Associations.No_Mapping =>
null;
end;
Lines.Reset_To_First (The_Strings);
Associations.Dispose (The_Associations);
return The_Strings;
exception
when Associations.Io_Failure =>
raise Io_Failure;
end Strings_Associated_With;
end Associations_Generic_Enumerated_To_String;
nblk1=d
nid=0
hdr6=1a
[0x00] rec0=20 rec1=00 rec2=01 rec3=032
[0x01] rec0=00 rec1=00 rec2=0d rec3=002
[0x02] rec0=17 rec1=00 rec2=02 rec3=064
[0x03] rec0=20 rec1=00 rec2=03 rec3=016
[0x04] rec0=00 rec1=00 rec2=0c rec3=002
[0x05] rec0=13 rec1=00 rec2=04 rec3=014
[0x06] rec0=19 rec1=00 rec2=05 rec3=024
[0x07] rec0=12 rec1=00 rec2=06 rec3=084
[0x08] rec0=1e rec1=00 rec2=07 rec3=042
[0x09] rec0=00 rec1=00 rec2=0b rec3=002
[0x0a] rec0=1b rec1=00 rec2=08 rec3=02e
[0x0b] rec0=17 rec1=00 rec2=09 rec3=05e
[0x0c] rec0=18 rec1=00 rec2=0a rec3=000
tail 0x217002a2c815c6723695b 0x42a00088462061e03