OSDN Git Service

2012-02-08 Vincent Celier <celier@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-diinio.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT RUN-TIME COMPONENTS                         --
4 --                                                                          --
5 --                  S Y S T E M . D I M . I N T E G E R _ I O               --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 2011-2012, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 3,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
17 --                                                                          --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception,   --
20 -- version 3.1, as published by the Free Software Foundation.               --
21 --                                                                          --
22 -- You should have received a copy of the GNU General Public License and    --
23 -- a copy of the GCC Runtime Library Exception along with this program;     --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
25 -- <http://www.gnu.org/licenses/>.                                          --
26 --                                                                          --
27 -- GNAT was originally developed  by the GNAT team at  New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
29 --                                                                          --
30 ------------------------------------------------------------------------------
31
32 --  This package provides output routines for integer dimensioned types. All
33 --  Put routines are modelled after those in package Ada.Text_IO.Integer_IO
34 --  with the addition of an extra default parameter.
35
36 --  All the examples in this package are based on the MKS system of units:
37
38 --    type Mks_Type is new Integer
39 --      with
40 --       Dimension_System => ((Meter, 'm'),
41 --         (Kilogram, "kg"),
42 --         (Second,   's'),
43 --         (Ampere,   'A'),
44 --         (Kelvin,   'K'),
45 --         (Mole,     "mol"),
46 --         (Candela,  "cd"));
47
48 --  Parameter Symbol may be used in the following manner:
49
50 --  Case 1. A value is supplied for Symbol
51
52 --    The string appears as a suffix of Item
53
54 --      Obj : Mks_Type := 2;
55 --      Put (Obj, Symbols => " dimensionless");
56
57 --      The corresponding output is: 2 dimensionless
58
59 --  Case 2. No value is supplied for Symbol and Item is dimensionless
60
61 --    Item appears without a suffix
62
63 --      Obj : Mks_Type := 2;
64 --      Put (Obj);
65
66 --      The corresponding output is: 2
67
68 --  Case 3. No value is supplied for Symbol and Item has a dimension
69
70 --    If the type of Item is a dimensioned subtype whose symbolic name is not
71 --    empty, then the symbolic name appears as a suffix.
72
73 --      subtype Length is Mks_Type
74 --        with
75 --         Dimension => ('m',
76 --           Meter =>  1,
77 --           others => 0);
78
79 --      Obj : Length := 2;
80 --      Put (Obj);
81
82 --      The corresponding output is: 2 m
83
84 --    Otherwise, a new string is created and appears as a suffix of Item.
85 --    This string results in the successive concatanations between each
86 --    dimension symbolic name raised by its corresponding dimension power from
87 --    the dimensions of Item.
88
89 --      subtype Random is Mks_Type
90 --        with
91 --         Dimension => ("",
92 --         Meter =>   3,
93 --         Candela => 2,
94 --         others =>  0);
95
96 --      Obj : Random := 5;
97 --      Put (Obj);
98
99 --      The corresponding output is: 5 m**3.cd**2
100
101 with Ada.Text_IO; use Ada.Text_IO;
102
103 generic
104    type Num_Dim_Integer is range <>;
105
106 package System.Dim.Integer_IO is
107
108    Default_Width : Field       := Num_Dim_Integer'Width;
109    Default_Base  : Number_Base := 10;
110
111    procedure Put
112      (File    : File_Type;
113       Item    : Num_Dim_Integer;
114       Width   : Field       := Default_Width;
115       Base    : Number_Base := Default_Base;
116       Symbols : String      := "");
117
118    procedure Put
119      (Item    : Num_Dim_Integer;
120       Width   : Field       := Default_Width;
121       Base    : Number_Base := Default_Base;
122       Symbols : String      := "");
123
124    procedure Put
125      (To      : out String;
126       Item    : Num_Dim_Integer;
127       Base    : Number_Base := Default_Base;
128       Symbols : String      := "");
129
130    pragma Inline (Put);
131
132 end System.Dim.Integer_IO;