1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- S Y S T E M . D I M . I N T E G E R _ I O --
9 -- Copyright (C) 2011-2012, Free Software Foundation, Inc. --
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. --
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. --
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/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
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.
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):
40 -- type Mks_Type is new Integer
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'));
51 -- Case 1. A value is supplied for Symbol
53 -- * Put : The string appears as a suffix of Item
55 -- * Put_Dim_Of : The string appears alone
57 -- Obj : Mks_Type := 2;
58 -- Put (Obj, Symbols => "dimensionless");
59 -- Put_Dim_Of (Obj, Symbols => "dimensionless");
61 -- The corresponding outputs are:
65 -- Case 2. No value is supplied for Symbol and Item is dimensionless
67 -- * Put : Item appears without a suffix
69 -- * Put_Dim_Of : the output is []
71 -- Obj : Mks_Type := 2;
75 -- The corresponding outputs are:
79 -- Case 3. No value is supplied for Symbol and Item has a dimension
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.
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.
92 -- subtype Length is Mks_Type
102 -- The corresponding outputs are:
106 -- subtype Random is Mks_Type
113 -- Obj : Random := 5;
117 -- The corresponding outputs are:
121 with Ada
.Text_IO
; use Ada
.Text_IO
;
124 type Num_Dim_Integer
is range <>;
126 package System
.Dim
.Integer_IO
is
128 Default_Width
: Field
:= Num_Dim_Integer
'Width;
129 Default_Base
: Number_Base
:= 10;
133 Item
: Num_Dim_Integer
;
134 Width
: Field
:= Default_Width
;
135 Base
: Number_Base
:= Default_Base
;
136 Symbol
: String := "");
139 (Item
: Num_Dim_Integer
;
140 Width
: Field
:= Default_Width
;
141 Base
: Number_Base
:= Default_Base
;
142 Symbol
: String := "");
146 Item
: Num_Dim_Integer
;
147 Base
: Number_Base
:= Default_Base
;
148 Symbol
: String := "");
152 Item
: Num_Dim_Integer
;
153 Symbol
: String := "");
156 (Item
: Num_Dim_Integer
;
157 Symbol
: String := "");
161 Item
: Num_Dim_Integer
;
162 Symbol
: String := "");
165 pragma Inline
(Put_Dim_Of
);
167 end System
.Dim
.Integer_IO
;