Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ada: packaging concepts [closed]

Tags:

packaging

ada

This is a follow up of my earlier post here:

Ada: Understanding private types and understanding packaging

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.

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;

Questions

  1. Is this the right way in software engineering to allow for another implementation in that the test file test_rectangular_form.adb remains the same for a different implementation?

  2. 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.

Thanks...

like image 599
yCalleecharan Avatar asked Jun 23 '26 08:06

yCalleecharan


1 Answers

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.

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

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;

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.

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

like image 150
Rommudoh Avatar answered Jun 27 '26 23:06

Rommudoh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!