home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gnat-2.06-src.tgz / tar.out / fsf / gnat / ada / a-wtcoio.adb < prev    next >
Text File  |  1996-09-28  |  5KB  |  162 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --   A D A . T E X T _ I O . W I D E _ T E X T _ IO . C O M P L E X _ I O   --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.1 $                              --
  10. --                                                                          --
  11. --        Copyright (c) 1992,1993,1994,1995 NYU, All Rights Reserved        --
  12. --                                                                          --
  13. -- The GNAT library is free software; you can redistribute it and/or modify --
  14. -- it under terms of the GNU Library General Public License as published by --
  15. -- the Free Software  Foundation; either version 2, or (at your option) any --
  16. -- later version.  The GNAT library is distributed in the hope that it will --
  17. -- be useful, but WITHOUT ANY WARRANTY;  without even  the implied warranty --
  18. -- of MERCHANTABILITY  or  FITNESS FOR  A PARTICULAR PURPOSE.  See the  GNU --
  19. -- Library  General  Public  License for  more  details.  You  should  have --
  20. -- received  a copy of the GNU  Library  General Public License  along with --
  21. -- the GNAT library;  see the file  COPYING.LIB.  If not, write to the Free --
  22. -- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.        --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. with Ada.Text_IO.Complex_Aux;
  27. with System.WCh_Con; use System.WCh_Con;
  28. with System.WCh_WtS; use System.WCh_WtS;
  29.  
  30. with Ada.Unchecked_Conversion;
  31.  
  32. package body Ada.Text_IO.Wide_Text_IO.Complex_IO is
  33.  
  34.    package Aux renames Ada.Text_IO.Complex_Aux;
  35.    --  We can share the normal Text_IO circuits for the non-string cases
  36.    --  since numeric values involve no wide character values, and the first
  37.    --  character of a wide character value (ESC or an upper half character)
  38.    --  always looks non-numeric for the Get case). For the Wide_String cases
  39.    --  we can share the normal Text_IO circuits by converting to String.
  40.  
  41.    subtype LLF is Long_Long_Float;
  42.    --  Type used for calls to routines in Aux
  43.  
  44. --   subtype TFT is Ada.Text_IO.File_Type;
  45.    --  File type required for calls to routines in Aux
  46.  
  47.    function TFT is new
  48.      Ada.Unchecked_Conversion (File_Type, Ada.Text_IO.File_Type);
  49.    --  This unchecked conversion is to get around a visibility bug in
  50.    --  GNAT version 2.04w. It should be possible to simply use the
  51.    --  subtype declared above and do normal checked conversions.
  52.  
  53.    ---------
  54.    -- Get --
  55.    ---------
  56.  
  57.    procedure Get
  58.      (File  : in  File_Type;
  59.       Item  : out Complex;
  60.       Width : in  Field := 0)
  61.    is
  62.       Real_Item  : Real'Base;
  63.       Imag_Item  : Real'Base;
  64.  
  65.    begin
  66.       Aux.Get (TFT (File), LLF (Real_Item), LLF (Imag_Item), Width);
  67.       Item := (Real_Item, Imag_Item);
  68.  
  69.    exception
  70.       when Constraint_Error => raise Data_Error;
  71.    end Get;
  72.  
  73.    ---------
  74.    -- Get --
  75.    ---------
  76.  
  77.    procedure Get
  78.      (Item  : out Complex;
  79.       Width : in  Field := 0)
  80.    is
  81.    begin
  82.       Get (Current_Input, Item, Width);
  83.    end Get;
  84.  
  85.    ---------
  86.    -- Get --
  87.    ---------
  88.  
  89.    procedure Get
  90.      (From : in  Wide_String;
  91.       Item : out Complex;
  92.       Last : out Positive)
  93.    is
  94.       Real_Item : Real'Base;
  95.       Imag_Item : Real'Base;
  96.  
  97.       S : constant String := Wide_String_To_String (From, WCEM_Upper);
  98.       --  String on which we do the actual conversion. Note that the method
  99.       --  used for wide character encoding is irrelevant, since if there is
  100.       --  a character outside the Standard.Character range then the call to
  101.       --  Aux.Gets will raise Data_Error in any case.
  102.  
  103.    begin
  104.       Aux.Gets (S, LLF (Real_Item), LLF (Imag_Item), Last);
  105.       Item := (Real_Item, Imag_Item);
  106.  
  107.    exception
  108.       when Data_Error => raise Constraint_Error;
  109.    end Get;
  110.  
  111.    ---------
  112.    -- Put --
  113.    ---------
  114.  
  115.    procedure Put
  116.      (File : in File_Type;
  117.       Item : in Complex;
  118.       Fore : in Field := Default_Fore;
  119.       Aft  : in Field := Default_Aft;
  120.       Exp  : in Field := Default_Exp)
  121.    is
  122.    begin
  123.       Aux.Put (TFT (File), LLF (Re (Item)), LLF (Im (Item)), Fore, Aft, Exp);
  124.    end Put;
  125.  
  126.    ---------
  127.    -- Put --
  128.    ---------
  129.  
  130.    procedure Put
  131.      (Item : in Complex;
  132.       Fore : in Field := Default_Fore;
  133.       Aft  : in Field := Default_Aft;
  134.       Exp  : in Field := Default_Exp)
  135.    is
  136.    begin
  137.       Put (Current_Output, Item, Fore, Aft, Exp);
  138.    end Put;
  139.  
  140.    ---------
  141.    -- Put --
  142.    ---------
  143.  
  144.    procedure Put
  145.      (To   : out Wide_String;
  146.       Item : in  Complex;
  147.       Aft  : in  Field := Default_Aft;
  148.       Exp  : in  Field := Default_Exp)
  149.    is
  150.       S : String (To'First .. To'Last);
  151.  
  152.    begin
  153.       Aux.Puts (S, LLF (Re (Item)), LLF (Im (Item)), Aft, Exp);
  154.  
  155.       for J in S'Range loop
  156.          To (J) := Wide_Character'Val (Character'Pos (S (J)));
  157.       end loop;
  158.  
  159.    end Put;
  160.  
  161. end Ada.Text_IO.Wide_Text_IO.Complex_IO;
  162.