ada - 具有持续访问父类型对象的 Ada 记录
问题描述
我最近开始学习 Ada。我想看看是否有可能在 Ada 中创建一个类似Boost::Statechart
的框架。为此,我需要一个记录结构,该结构具有对父类型对象的常量访问对象,例如静态指向另一个树节点的树节点,并且父指针始终不得更改。像这样的东西:
-- Not working sample
type Node_T is record
Parent : constant access Node_T;
-- error: constant components are not permitted
end record;
-- I wish to create objects of this type like this
Top_Node : Node_T (null);
Child1_Node : Node_T (Top_Node'Access);
Child2_Node : Node_T (Top_Node'Access);
Ada 似乎不支持常量成员字段。所以我求助于使用访问判别器:
-- Not working sample
type Node_T (Parent : access Node_T) is null record;
-- error: type declaration cannot refer to itself
但是,使用命名访问类型作为判别式有效
type Node_T;
type Ref_Node_T is access all Node_T;
type Node_T (Parent : Ref_Node_T) is null record;
但是,据我所知,这会导致Node_T
对象的生命周期绑定到一个Ref_Node_T
对象的生命周期,而不是另一个父Node_T
对象的生命周期。这是真的?
有没有更好的方法来实现我所需要的?
解决方案
https://www.sigada.org/ada_letters/june2000/sanden.pdf中描述了创建有限状态机的另一种方法。 此解决方案使用受保护对象和任务的组合来实现有限状态机。
推荐阅读
- jenkins - 在 Jenkins 范围报告中,屏幕截图为空白
- udp - 如何处理丢失连接的客户端地址?
- python-3.x - 提取所有分页链接到带有scrapy for url = https://www.blablacar.in/ride-sharing/new-delhi/chandigarh/的页面
- css - 制作嵌套选择器以生成没有空格的选择器
- oracle - 在 Oracle 中插入多行
- facebook-graph-api - 反正有没有使用 Facebook v2.6 API 而不是最新的 v3.0 API?
- react-native - 在共享对话框中显示我的应用程序
- wordpress - 汇总自定义帖子字段中的特定元值
- powershell - PowerDesigner COM 对象在 Windows Server 2012 上为空
- javascript - 克隆的 DOM 结构上的 Angular 5 点击事件未触发