我试图用受保护的对象包装散列映射,以便可以通过多个任务来访问它。我希望受保护类型的过程可用,但将散列映射和元素记录定义移动到软件包专用部分会很好。从Ada的受保护对象访问私有类型
示例代码在这里:
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;
我试图定义Thing_Info为私有类型..但我不知道我会如何定义Thing_Info_Maps包作为私人使用,但仍然来自保护对象访问类型。
所以我真的不会发现试图找到一种方式来获得这样的事:
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;
我编辑了自己的冠军。请参阅:“[应该在其标题中包含”标签“](http://meta.stackexchange.com/questions/19190/)”,其中的共识是“不,他们不应该”。 –
我想现在它不像ada相关那么明显。尤其是在排名前15的投票标题为“ada”的问题中,只有一个在标题中没有Ada。 –
我会照顾的。 –