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. All Put_Dim_Of routines
35--  output the dimension of Item in a symbolic manner.
36
37--  Parameter Symbol may be used in the following manner (all the examples are
38--  based on the MKS system of units as defined in package System.Dim.Mks):
39
40--    type Mks_Type is new Integer
41--      with
42--       Dimension_System => (
43--        (Unit_Name => Meter,    Unit_Symbol => 'm',   Dim_Symbol => 'L'),
44--        (Unit_Name => Kilogram, Unit_Symbol => "kg",  Dim_Symbol => 'M'),
45--        (Unit_Name => Second,   Unit_Symbol => 's',   Dim_Symbol => 'T'),
46--        (Unit_Name => Ampere,   Unit_Symbol => 'A',   Dim_Symbol => 'I'),
47--        (Unit_Name => Kelvin,   Unit_Symbol => 'K',   Dim_Symbol => "Θ"),
48--        (Unit_Name => Mole,     Unit_Symbol => "mol", Dim_Symbol => 'N'),
49--        (Unit_Name => Candela,  Unit_Symbol => "cd",  Dim_Symbol => 'J'));
50
51--  Case 1. A value is supplied for Symbol
52
53--   * Put        : The string appears as a suffix of Item
54
55--   * Put_Dim_Of : The string appears alone
56
57--      Obj : Mks_Type := 2;
58--      Put (Obj, Symbols => "dimensionless");
59--      Put_Dim_Of (Obj, Symbols => "dimensionless");
60
61--      The corresponding outputs are:
62--      $2 dimensionless
63--      $dimensionless
64
65--  Case 2. No value is supplied for Symbol and Item is dimensionless
66
67--   * Put        : Item appears without a suffix
68
69--   * Put_Dim_Of : the output is []
70
71--      Obj : Mks_Type := 2;
72--      Put (Obj);
73--      Put_Dim_Of (Obj);
74
75--      The corresponding outputs are:
76--      $2
77--      $[]
78
79--  Case 3. No value is supplied for Symbol and Item has a dimension
80
81--   * Put        : If the type of Item is a dimensioned subtype whose
82--                  symbol is not empty, then the symbol appears as a suffix.
83--                  Otherwise, a new string is created and appears as a
84--                  suffix of Item. This string results in the successive
85--                  concatenations between each unit symbol raised by its
86--                  corresponding dimension power from the dimensions of Item.
87
88--   * Put_Dim_Of : The output is a new string resulting in the successive
89--                  concatenations between each dimension symbol raised by its
90--                  corresponding dimension power from the dimensions of Item.
91
92--      subtype Length is Mks_Type
93--        with
94--         Dimension => ('m',
95--           Meter =>  1,
96--           others => 0);
97
98--      Obj : Length := 2;
99--      Put (Obj);
100--      Put_Dim_Of (Obj);
101
102--      The corresponding outputs are:
103--      $2 m
104--      $[L]
105
106--      subtype Random is Mks_Type
107--        with
108--         Dimension => ("",
109--           Meter =>   3,
110--           Candela => 2,
111--           others =>  0);
112
113--      Obj : Random := 5;
114--      Put (Obj);
115--      Put_Dim_Of (Obj);
116
117--      The corresponding outputs are:
118--      $5 m**3.cd**2
119--      $[L**3.J**2]
120
121with Ada.Text_IO; use Ada.Text_IO;
122
123generic
124   type Num_Dim_Integer is range <>;
125
126package System.Dim.Integer_IO is
127
128   Default_Width : Field       := Num_Dim_Integer'Width;
129   Default_Base  : Number_Base := 10;
130
131   procedure Put
132     (File   : File_Type;
133      Item   : Num_Dim_Integer;
134      Width  : Field       := Default_Width;
135      Base   : Number_Base := Default_Base;
136      Symbol : String      := "");
137
138   procedure Put
139     (Item   : Num_Dim_Integer;
140      Width  : Field       := Default_Width;
141      Base   : Number_Base := Default_Base;
142      Symbol : String      := "");
143
144   procedure Put
145     (To     : out String;
146      Item   : Num_Dim_Integer;
147      Base   : Number_Base := Default_Base;
148      Symbol : String      := "");
149
150   procedure Put_Dim_Of
151     (File   : File_Type;
152      Item   : Num_Dim_Integer;
153      Symbol : String := "");
154
155   procedure Put_Dim_Of
156     (Item   : Num_Dim_Integer;
157      Symbol : String := "");
158
159   procedure Put_Dim_Of
160     (To     : out String;
161      Item   : Num_Dim_Integer;
162      Symbol : String := "");
163
164   pragma Inline (Put);
165   pragma Inline (Put_Dim_Of);
166
167end System.Dim.Integer_IO;
168