Re: Real Time IO routines answering Simon Wright part 2
- From: anon@xxxxxxxx (anon)
- Date: Tue, 30 Oct 2007 16:35:03 GMT
--
-- This is Part 2. A simpler version of an Ada purist type of
-- answer to the original thread poster question. Also ths
-- version should answer "Dmitry A. Kazakov" concerns about
-- types being defined in private. The RM does have its view on
-- this version.
--
--
-- Where did I get the information that IMAGE should be use for
-- debugging only? A few Ada conferences back in the early to
-- mid 1990's dealing with Ada programming and debugging
-- techniques. And is fully embrased by Adacore aka creaters of
-- GNAT.
--
--
-- z.adb
--
--
-- Compile with "-gnatwI" or you may receive Portable and Version
-- Warnings, for the sub package "ada.real_time.io" aka user-written
-- child of "ada.real_time". (GNAT)
--
with Ada.Real_Time ;
with Ada.Real_Time.IO ; -- programmer Ada extension package
with Ada.Text_IO ;
use Ada.Real_Time ;
use Ada.Text_IO ;
procedure z is
Time_Value : Time ;
begin
Time_Value := Clock ;
Put ( "Time := " ) ;
Ada.Real_Time.IO.Put ( Time_Value ) ;
New_Line ;
end z ;
--
-- a-retiio.ads
--
-- Package must be included with program source code, do to
-- the "non-Portable" nature of this code.
--
package Ada.Real_Time.IO is
--
-- Put: Uses the default Put routine. To keep this example
-- simple the routines uses the type default for
-- formatting
--
procedure Put ( Z : Time ) ;
end Ada.Real_Time.IO ;
--
-- a-retiio.adb => Ada Standard Extension Package.
--
pragma Style_Checks (OFF); -- not needed if you use GNAT style
-- requirements aka rules for spacing
--
-- Gnat will view this package as a "Language Defined Unit" even
-- though it is not in the Standard GNAT package list.
--
-- Package must be included with program source code, do to
-- the "non-Portable" nature of this code.
--
-- ------------------------------------------------------- --
-- An Ada Purist would have bypassed using a package --
-- routine and added a local routine for printing the --
-- "Time" value directly to a text file. That way they --
-- could reduce the code to the bare bones. --
-- ------------------------------------------------------- --
-- I used a generic package because it was faster and --
-- easier to generate the example of an extension to --
-- the Standard Ada packages. --
-- ------------------------------------------------------- --
with Ada.Text_IO ;
package body Ada.Real_Time.IO is
--
-- Time specification comes from the parent's code.
--
package D_IO is new Ada.Text_IO.Fixed_IO ( Time ) ;
--
-- Put: Uses the default Put routine. To keep this example
-- simple the routines uses the type default for
-- formatting
--
procedure Put ( Z : Time ) is
begin -- Put
D_IO.Put ( Z ) ;
end Put ;
end Ada.Real_Time.IO ;
In <m2tzoc5iqw.fsf@xxxxxxx>, Simon Wright <simon.j.wright@xxxxxxx> writes:
anon@xxxxxxxx (anon) writes:
Ada Purist never and I mean NEVER uses IMAGE attribute, in the body of
a program. They create a package or sub-package that performs the IO
functions with the use of the IMAGE attribute.
IMAGE attribute is the last thing a programmer should use. to print a value.
It is normally use for DEBUGGING ONLY! A programmer should always create
a routine or better yet a package that uses an algorithm to prints the value
without the use of attributes.
Mostly programs that are created by newbees use IMAGE attribute.
I must be a newbie (NB spelling!) then.
Where on earth do you get this viewpoint from? Please say why it is
better to instantiate enumeration IO for Boolean rather than to use
Boolean'Image?
I suppose you would ban people from using Integer_IO, too. Good grief.
And as for my code! It answer the person question without adding extra
code that might confuse him. Plus, the "Ada.Real_Time" package uses:
type Time is new Duration;
which is in private section. So I know what to convert the value to.
This is true so long as you and the person to whom you are giving
advice are both using *this version of* *GNAT*. Whatever makes you
suppose that the code you see in that private part will be the same
for any other compiler? or for any other version of GNAT? or for GNAT
for a different platform?
.
- Follow-Ups:
- Re: Real Time IO routines answering Simon Wright part 2
- From: Adam Beneschan
- Re: Real Time IO routines answering Simon Wright part 2
- From: Simon Wright
- Re: Real Time IO routines answering Simon Wright part 2
- References:
- Real Time IO routines
- From: andrew
- Re: Real Time IO routines
- From: anon
- Re: Real Time IO routines
- From: Dmitry A. Kazakov
- Re: Real Time IO routines
- From: anon
- Re: Real Time IO routines
- From: Simon Wright
- Real Time IO routines
- Prev by Date: virtual memory, was Re: Largest size array in Gnat 2005 for the PC?
- Next by Date: Re: Largest size array in Gnat 2005 for the PC?
- Previous by thread: Re: Real Time IO routines -- answering Simon Wright part 1
- Next by thread: Re: Real Time IO routines answering Simon Wright part 2
- Index(es):
Relevant Pages
|