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,6353697ffeb79d16 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news2.google.com!postnews.google.com!v12g2000vbh.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Encapsulating Ada.Direct_IO Date: Tue, 16 Nov 2010 21:20:05 -0800 (PST) Organization: http://groups.google.com Message-ID: <82e9201f-9186-4450-bbf8-9433f6a19d71@v12g2000vbh.googlegroups.com> References: <5ba4147a-6099-4a05-b548-09544f58247a@j18g2000yqd.googlegroups.com> NNTP-Posting-Host: 207.200.116.71 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1289971205 29351 127.0.0.1 (17 Nov 2010 05:20:05 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 17 Nov 2010 05:20:05 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: v12g2000vbh.googlegroups.com; posting-host=207.200.116.71; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-Via: HTTP/1.1 (Velocity/3.1.2.1 [uScMs f p eN:t cCMp s ]), HTTP/1.1 spider-ntc-ta05.proxy.aol.com[CFC87005] (Prism/1.2.1), HTTP/1.1 cache-ntc-ab07.proxy.aol.com[CFC87447] (Traffic-Server/6.1.5 [uScM]) X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; AOL 9.5; AOLBuild 4337.5401; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; HPDTDF; BRI/1; .NET4.0C),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:15532 Date: 2010-11-16T21:20:05-08:00 List-Id: On Nov 16, 8:44=A0pm, Bryan wrote: > I'm trying to port some code to Ada for dealing with Big5-encoded > files. I realize that I might be able to use Ada.Wide_Text_IO, but I'm > trying to learn Ada and understand the language better. =A0I'm still > working on wrapping my head around types and packages. =A0My original > code in C++ opens a file as binary and parses it byte by byte and > breaking it into Big5 characters depending on the byte codes. =A0I > thought I'd try to do something similar by encapsulating Ada.Direct_IO > into a package. =A0I'm not having much luck, however. > > Spec file: > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > with Ada.Direct_IO; > package Big5_Text_IO is > =A0 type File_Type is limited private; > =A0 procedure Close( File : in out File_Type ); > private > =A0 package Byte_IO is new Ada.Direct_IO(Character); > =A0 type File_Type is new Byte_IO.File_Type; > end Big5_Text_IO; > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > Body file > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > package body Big5_Text_IO is > =A0 procedure Close( File : in out File_Type ) is > =A0 begin > =A0 =A0 =A0 =A0 Byte_IO.Close(File); > =A0 end Close; > end Big5_Text_IO; > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > Test driver: > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > with Big5_Text_IO; > with Ada.Text_IO; > procedure Big5_Test is > =A0 Input_File : Big5_Text_IO.File_Type; > begin > =A0 Ada.Text_IO.Put_Line("OK?"); > end Big5_Test; > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > If I leave out the Close method and remove the body file, I can build > the test driver with no issues. =A0Otherwise, I get the following from > GNAT: > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > gcc -c big5_text_io.adb > big5_text_io.adb:6:23: expected private type "Ada.Direct_Io.File_Type" > from instance at big5_text_io.ads:11 > big5_text_io.adb:6:23: found private type "Big5_Text_IO.File_Type" > defined at big5_text_io.ads:12 > gnatmake: "big5_text_io.adb" compilation error > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > I would *greatly* appreciate any tips in how I can better design my > package so that it can encapsulate Ada.Direct_IO or some other method > of binary I/O. =A0I looked at the GNAT source and I'm hoping I won't > have to emulate what they have done...its a bit over my head at this > point. You're close. Try changing Byte_IO.Close (File); to Byte_IO.Close (Byte_IO.File_Type (File)); When you declare a derived type "type T2 is new T1", then T2 and T1 are not the same type, so you can't use an object of type T2 where something of type T1 is expected. But you can use a type conversion. Note: I'm at home so I can't try this easily. I seem to recall that there were some issues using this paradigm with limited types (including an incompatibility with earlier versions of the language), but I don't recall the details and it's hard for me to look them up right now. If it turns out the type conversion doesn't work, then you might have to make File_Type a record in the private part: type File_Type is record F : Byte_IO.File_Type; end record; and then use File.F whenever you want to use a Byte_IO operation, e.g.: Byte_IO.Close (File.F); Hope this helps, -- Adam