From: anon@anon.org (anon)
Subject: Re: Controlling endian-ness? (Example: Attribute Overriding)
Date: Wed, 06 Aug 2008 17:07:16 GMT
Date: 2008-08-06T17:07:16+00:00 [thread overview]
Message-ID: <8Tkmk.148915$102.119869@bgtnsc05-news.ops.worldnet.att.net> (raw)
In-Reply-To: 4898d0ca$0$19680$4d3efbfe@news.sover.net
-- File: newprog.adb
--
-- An example of how to Override an built-in Attribute:
-- Based on examples from RM 13.3 ( 84 ) and 13.13.2 ( 40 ) ;
--
with Interfaces ;
use Interfaces ;
with Ada.Text_IO ;
use Ada.Text_IO ;
with Ada.Streams.Stream_IO;
procedure NewProg is
-----------------------------------------------------------
type Unsigned_32 is new Interfaces.Unsigned_32 ;
--
-- Define New Attribute Specifications
--
procedure newWrite
( Stream : access Ada.Streams.Root_Stream_Type'Class;
Item : in Unsigned_32 ) ;
-- Performs Overriding of attribute
for Unsigned_32'Write use newWrite ;
-----------------------------------------------------------
--
-- Define New Attribute Body
--
procedure newWrite
( Stream : access Ada.Streams.Root_Stream_Type'Class;
Item : in Unsigned_32 ) is
begin
--
-- Replace with your "Write code"
--
-- test message only, just to prove that we are using this Attribute
--
Put_Line ( "New Write Attribute" ) ;
end newWrite ;
-----------------------------------------------------------
Data_File : Ada.Streams.Stream_IO.File_Type;
Data_Stream : Ada.Streams.Stream_IO.Stream_Access;
The_Filename : constant String := "Test.Dat" ;
Test_Data : Unsigned_32 := 9 ;
begin
Ada.Streams.Stream_IO.Create ( Data_File,
Ada.Streams.Stream_IO.Out_File,
The_Filename ) ;
Data_Stream := Ada.Streams.Stream_IO.Stream ( Data_File ) ;
Put_Line ( "Testing: New Atrribute: Write" ) ;
New_Line ;
Unsigned_32'Write ( Data_Stream, Test_Data ) ;
Ada.Streams.Stream_IO.Close ( Data_File ) ;
end NewProg ;
In <4898d0ca$0$19680$4d3efbfe@news.sover.net>, "Peter C. Chapin" <pcc482719@gmail.com> writes:
>anon wrote:
>
>> For using Unsigned_32. Why not just override the built-in Write attributes
>> routines for Unsigned_32 by re-writing the attributes routines. This may at
>> most require a new package with a few extra attributes routines that may
>> be needed. Also, this will also allow you to use "Shift_Left/Shift_Right"
>> directly with Unsigned_32.
>>
>> So in your program you could use:
>>
>> Data : Unsigned_32 ;
>> ...
>> Unsigned_32'Write ( Stream_Pointer, Data ) ;
>
>I actually tried something like this but the compiler told me that I
>couldn't redefine attributes for that type (or something like that). I
>think the problem is that since the type is defined in another package
>it is already frozen or some such. It could also be that I did it wrong.
>
>Peter
next prev parent reply other threads:[~2008-08-06 17:07 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-05 2:16 Controlling endian-ness? Peter C. Chapin
2008-08-05 3:10 ` Steve
2008-08-05 9:59 ` Peter C. Chapin
2008-08-05 5:23 ` christoph.grein
2008-08-05 9:59 ` Peter C. Chapin
2008-08-05 14:59 ` anon
2008-08-05 22:14 ` Peter C. Chapin
2008-08-06 0:16 ` Adam Beneschan
2008-08-06 13:44 ` Peter C. Chapin
2008-08-06 17:07 ` anon [this message]
2008-08-12 13:42 ` Simon Wright
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox