From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8054919d7e55838b,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!u72g2000cwu.googlegroups.com!not-for-mail From: brian.b.mcguinness@lmco.com Newsgroups: comp.lang.ada Subject: Q: Hiding the structure of a tagged type using containers Date: 8 May 2006 18:52:55 -0700 Organization: http://groups.google.com Message-ID: <1147139575.425825.290860@u72g2000cwu.googlegroups.com> NNTP-Posting-Host: 141.153.194.7 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1147139582 16535 127.0.0.1 (9 May 2006 01:53:02 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 9 May 2006 01:53:02 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.2) Gecko/20060419 Fedora/1.5.0.2-1.2.fc5 Firefox/1.5.0.2 pango-text,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: u72g2000cwu.googlegroups.com; posting-host=141.153.194.7; posting-account=R0BKUQwAAAAEH1zhMKQoEzkWfZJu3USj Xref: g2news2.google.com comp.lang.ada:4144 Date: 2006-05-08T18:52:55-07:00 List-Id: 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