I'm attempting to wrap a hashed map with a protected object so it can be accessed via a multiple tasks. I want the procedures on the protected type to be available but it would be nice to move the hash map and element record definition into the packages private section.
Example code here:
package Thing_Protected is
type Thing_Info is record
Key : Ada.Strings.Unbounded.Unbounded_String;
Counter_Value : Natural := 0;
end record;
package Thing_Info_Maps is new Ada.Containers.Hashed_Maps
(Key_Type => Ada.Strings.Unbounded.Unbounded_String,
Element_Type => Thing_Info,
Hash => Ada.Strings.Unbounded.Hash,
Equivalent_Keys => Ada.Strings.Unbounded."=");
protected type Thing is
procedure Increment (Key : String);
procedure Another_Thing (Key : String);
private
Thing_Map : Thing_Info_Maps.Map;
end Thing;
private
-- move Thing_Info, Thing_info_maps into here.
end Thing_Protected;
I've tried defining Thing_Info as a private type.. but I'm not sure how I would define the Thing_Info_Maps package as private but still access it from the protected object type.
So really I wouldn't find trying to find a way to get something like this:
package Thing_Protected is
type Thing_Info is private;
package Thing_Info_Maps is private;
protected type Thing is
procedure Increment (Key : String);
procedure Another_Thing (Key : String);
private
Thing_Map : Thing_Info_Maps.Map; -- <<- how would we know about .Map??
end Thing;
private
type Thing_Info is record
Key : Ada.Strings.Unbounded.Unbounded_String;
Counter_Value : Natural := 0;
end record;
package Thing_Info_Maps is new Ada.Containers.Hashed_Maps
(Key_Type => Ada.Strings.Unbounded.Unbounded_String,
Element_Type => Thing_Info,
Hash => Ada.Strings.Unbounded.Hash,
Equivalent_Keys => Ada.Strings.Unbounded."=");
end Thing_Protected;