[英]Ada unconstrained type
Hello Im new to ada and I am trying to create some kind of unconstrained array and I can't figure out how to do it in ada. 您好Im是ada的新手,我正在尝试创建某种不受约束的数组,但我不知道如何在ada中做到这一点。
package data_puzzle is
type rotation is private;
type map(x_l,y_l,z_l : Natural) is private;
type valid_rotations is private;
private
type rotation is array(1..3) of Natural;
type map(x_l,y_l,z_l : Natural) is record
struct : Structure(x_l,y_l,z_l);
rot : rotation;
end record;
type valid_rotations is array(1..24) of map; --how can I make this row work?
end data_puzzle;
Structure looks like this 结构看起来像这样
type structure(x_l,y_l,z_l : Natural) is record
structure : xyz(1..x_l,1..y_l,1..z_l);
X : Natural := x_l;
Y : Natural := y_l;
Z : Natural := z_l;
end record;
Basically I have a map with rotations and data. 基本上,我有一个包含旋转和数据的地图。 Then I want to store all the different rotations in a list of size 24. The only solution I have right now is to initiate type valid_rotations is array(1..24) of map(x,y,z) then it works.
然后,我想将所有不同的旋转存储在大小为24的列表中。我现在唯一的解决方案是初始化类型valid_rotations是map(x,y,z)的array(1..24),然后它可以工作。 But I do not want to initiate it like that since I do not know what the size will be at that moment.
但是我不想这样启动,因为我不知道那时候的大小。
Cheers! 干杯!
Ok, the problem is that the type map
can be of varying size -- the compiler cannot therefore simply set aside the proper amount of memory w/o further information -- so the solution is to create some sort of indirection which can be the element of an array: we have this type since Ada 83 but with Ada 2005 and on we can further constrain access types from being null. 好的,问题是类型
map
的大小可以变化-编译器因此不能简单地在没有更多信息的情况下就留出适当的内存量-因此解决方案是创建某种可以作为元素的间接寻址数组的类型:自Ada 83以来,我们就拥有这种类型, 但随着Ada 2005的出现,我们可以进一步限制访问类型为null。
-- I don't know what this is supposed to be; I'm assuming an array.
type xyz is Array(Positive Range <>, Positive Range <>, Positive Range <>)
of Integer;
type structure(x_l,y_l,z_l : Natural) is record
structure : xyz(1..x_l,1..y_l,1..z_l);
X : Natural := x_l;
Y : Natural := y_l;
Z : Natural := z_l;
end record;
package data_puzzle is
type rotation is private;
type map(x_l,y_l,z_l : Natural) is private;
type valid_rotations is private;
type map_handle is private;
private
type rotation is array(1..3) of Natural;
type map(x_l,y_l,z_l : Natural) is record
struct : Structure(x_l,y_l,z_l);
rot : rotation;
end record;
-- Because the size of the record "map" can change
-- depending on its discriminants, we cannot simply
-- make some array -- we can however have an array
-- of accesses (since we know their sizes at compile)
-- and constrain these access-types to be non-null.
type valid_rotations is array(1..24) of map_handle;
-- Here it is: an access which cannot be null.
type map_handle is Not Null Access Map;
end data_puzzle;
Also, I'd delete the _1 from the discriminants (X,Y,Z) look fine to me. 另外,我会从判别式(X,Y,Z)中删除_1,对我来说很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.