Ada:包装概念 [英] Ada: packaging concepts

查看:103
本文介绍了Ada:包装概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我之前的帖子的后续内容:

This is a follow up of my earlier post here:

Ada:了解私有类型并了解包装

Rectangular类型的实现是使用一个实现实现的,即,Rectangular_Method_1,并且此实现需要规范文件和主体文件.

An implementation for the Rectangular type was made using one implementation i.e. Rectangular_Method_1 and a specification file and a body file were required for this implementation.

如果我们想为用户提供另一个实现Rectangular_Method_2,则可以将主文件rectangular_Form.ads更改为

If we want to have another implementation Rectangular_Method_2 available to the user then the main file rectangular_Form.ads can be changed to

-- with Rectangular_Method_1;
-- package Rectangular_Form renames Rectangular_Method_1;
with Rectangular_Method_2;
package Rectangular_Form renames Rectangular_Method_2;

问题

  1. 这是软件工程中允许另一种实现的正确方法吗,因为对于不同的实现,测试文件test_rectangular_form.adb保持相同?

如果我们创建第二个实现Rectangular_Method_2,除了该新实现的强制性新主体之外,是否需要创建单独的规范文件?但是,在新的实现中需要为Vector_Basis_rSet_HorzGet_Horz等提供相同的过程/功能,以便我们可以在test_rectangular_form.adb中对其进行调用.

If we create a second implementation Rectangular_Method_2, Is there a need to create a separate specification file in addition to the compulsory new body for this new implementation? There is the need however to provide the same procedures/functions for Vector_Basis_r, Set_Horz, Get_Horz etc in the new implementation so that we can call them in test_rectangular_form.adb.

谢谢...

推荐答案

如果使用GNAT,则可以将GPR文件用于项目.您可以在其中更改特定软件包的文件名,例如:

If you use GNAT, you can use GPR files for the project. In there you can change the filename for specific packages, for example:

for Specification (Rectangular_Form) use "Rectangular_Method_1.ads";
for Implementation (Rectangular_Form) use "Rectangular_Method_1.adb";

您甚至可以根据环境变量进行设置.

you can even set this depending on an environment variable.

如果规格文件的外观都相同,则可以使用Rectangular_Form.ads,并且只能使用上方的实施"行.

If your spec files all should look the same, you can use a Rectangular_Form.ads and only use the Implementation line from above.

示例GPR文件可能如下所示:

An example GPR file could look like this:

project Example is

   type Methods is ("normal", "something_else");
   Method : Methods := external ("METHOD", "normal");

   package Naming is
      case Method is
         when "normal" =>
            for Implementation ("Example") use "example_normal.adb";
         when "something_else" =>
            for Implementation ("Example") use "example_something.adb";
      end case;
   end Naming;

end Example;

然后,您可以根据您的METHOD变量使用gnatmake -P example.gpr对其进行编译,或者对gnatmake使用-XMETHOD=...参数,或者仅使用提供的默认值.

Then, you can use gnatmake -P example.gpr to compile it depending on your METHOD variable, or using a -XMETHOD=... parameter for gnatmake or just use the provided default value.

example_*.adb都应包含软件包Example的主体,而不是Example_Normal等.

The example_*.adb should all contain the body of the package Example, not Example_Normal, etc..

这篇关于Ada:包装概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆