comp.lang.ada
 help / color / mirror / Atom feed
* Q: Hiding the structure of a tagged type using containers
@ 2006-05-09  1:52 brian.b.mcguinness
  2006-05-09  6:43 ` Stephen Leake
  2006-05-09 14:47 ` Matthew Heaney
  0 siblings, 2 replies; 6+ messages in thread
From: brian.b.mcguinness @ 2006-05-09  1:52 UTC (permalink / raw)


I am trying to create a tree of object classes to represent arrays.  I
want to hide the internal representation of the arrays in the private
sections of the packages for the tagged types.  However, I am having
trouble figuring out how to do this.  For example, I have an abstract
base
class called APL_Array, and I am trying to create a child class called
APL_Array_Dimensioned that contains a list of dimensions (which may
change
over time, say if someone concatenates a row or column to a matrix).
This
class can provide various structural operations that only affect the
list
of dimensions.  Then I can descend a generic child array class from
this
to hold a list of array elements of any desired data type.

I tried this:

1
--------------------------------------------------------------------------------
2  -- Declaration of an array with a list of dimensions
3  --
4  -- Brian B. McGuinness     May, 2006
5
--------------------------------------------------------------------------------
6  with Ada.Containers.Vectors;
7
8  package APL.Arrays.Dimensioned is
9
10    type APL_Shape is private;
11
12    type APL_Array_Dimensioned is new APL_Array with private;
13
14    -- Get the total number of elements
15    overriding function Length (A : APL_Array_Dimensioned) return
Dimension;
16
17    -- Get the number of dimensions
18    function Rank (A : APL_Array_Dimensioned) return Dimension_Count;
19
20    -- Get the current shape of the array
21    procedure Shape (A : in APL_Array_Dimensioned; Dimensions : out
APL_Shape);
22
23    -- Set the shape of the array
24    procedure Replace_Shape (A : in out APL_Array_Dimensioned;
Dimensions : in APL_Shape);
25
26  private
27
28    package APL_Dimension_List is new Ada.Containers.Vectors (
29      Index_Type   => Dimension_Index,
30      Element_Type => Dimension
31    );
32
33    type APL_Shape is new APL_Dimension_List.Vector with null record;
34
35    type APL_Array_Dimensioned is new APL_Array with record
36      Dimensions : APL_Shape;
37    end record;
38
39  end APL.Arrays.Dimensioned;

but when I try to compile it, I get:

# gnatmake -gnat05 apl-arrays-dimensioned.adb
gcc -c -gnat05 apl-arrays-dimensioned.adb
apl-arrays-dimensioned.ads:21:13: operation can be dispatching in only
one type
apl-arrays-dimensioned.ads:24:13: operation can be dispatching in only
one type
apl-arrays-dimensioned.ads:33:08: type must be declared abstract or
"TO_VECTOR" overridden
apl-arrays-dimensioned.ads:33:08: "TO_VECTOR" has been inherited at
line 33
apl-arrays-dimensioned.ads:33:08: "TO_VECTOR" has been inherited from
subprogram at a-convec.ads:63, instance at line 28
gnatmake: "apl-arrays-dimensioned.adb" compilation error
#

Using APL_Dimension_List.Vector might work, but I am trying to
rename this to APL_Shape in order to hide the ".Vector" part
and make the dimension list look like a simple data type. I
tried using "type APL_Shape renames APL_Dimension_List.Vector"
but that doesn't work, either.

If the Ada 2005 RM provides information on how to do this,
I have been unable to find it.

I would appreciate any help that you can provide.

--- Brian




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-05-10 11:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-05-09  1:52 Q: Hiding the structure of a tagged type using containers brian.b.mcguinness
2006-05-09  6:43 ` Stephen Leake
2006-05-09 14:52   ` Matthew Heaney
2006-05-10 11:50     ` Craig Carey
2006-05-09 14:47 ` Matthew Heaney
2006-05-09 14:55   ` brian.b.mcguinness

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