comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: API design considerations - variable-length array in record type
Date: Mon, 8 Oct 2012 02:03:03 -0700 (PDT)
Date: 2012-10-08T02:03:03-07:00	[thread overview]
Message-ID: <c40023e6-e7d1-431f-8759-5ac224c0aa1f@googlegroups.com> (raw)

Hi,

I am working on the API design where there is a need for a record type with field(s) that are arrays of some predefined type (say, Integer). So, an example record type might look like this:

type R is record
   X : Integer;
   Y : Unbounded_String;
   Z : Array_Of_Integers_That_We_Talk_About_Here;
end record;

The trouble is, the types involved should comply with the following requirements:

- the enclosing record type should not be limited (it should be copyable)
- the record type can be explicitly controlled, if necessary
- the record type should be definite (it should not require initialization)
- it should be possible to assign to Z, just as it is possible to assign to X and Y, and the new value for Z *might have a different length*

An important relaxation is that it is not necessary to support in-place modifications of the field in question. That is, Y above can be modified (by appending or modifying individual characters, for example) in place. It is not necessary to support it for Z, assignment of the whole array is the only operation that is needed there.

A straightforward choice is a predefined instantiation of Ada.Containers.Vectors for Integer and this would be probably the least surprising, especially in the context of Y : Unbounded_String, but at the same time I'm open to consider some more lightweight alternatives.
The problem is - any other alternative I can think of leads to the complication of API in the form of introducing Ada.Finalization.Controlled to the picture.

Do you have some favourite solutions?

For comparison, in C++ this would be solved with std::vector<int>, which suggests Ada.Containers.Vectors for Ada; but in Java this would be done simply with int[], which is conceptually lighter and easier to use in this particular context.

-- 
Maciej Sobczak * http://www.msobczak.com * http://www.inspirel.com



             reply	other threads:[~2012-10-08  9:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-08  9:03 Maciej Sobczak [this message]
2012-10-08 11:13 ` API design considerations - variable-length array in record type Simon Wright
2012-10-08 11:29 ` Egil Høvik
2012-10-08 11:53   ` Maciej Sobczak
2012-10-08 14:37     ` Tero Koskinen
2012-10-09  2:02 ` Shark8
2012-10-09  5:16   ` Adam Beneschan
2012-10-09  5:45     ` Shark8
2012-10-09  5:42   ` Niklas Holsti
2012-10-09  3:10 ` Stephen Leake
2012-10-09  7:47   ` Maciej Sobczak
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox