si_units_0.2.0_13606e49/src/si_units-metric.ads

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
--------------------------------------------------------------------------------
--  Copyright (C) 2020 by Heisenbug Ltd. (gh+si_units@heisenbug.eu)
--
--  This work is free. You can redistribute it and/or modify it under the
--  terms of the Do What The Fuck You Want To Public License, Version 2,
--  as published by Sam Hocevar. See the LICENSE file for more details.
--------------------------------------------------------------------------------
pragma License (Unrestricted);

with Ada.Text_IO;

--------------------------------------------------------------------------------
--  Image subprograms for metric (SI) physical values.
--
--  Please note that the rather unusual prefixes centi, deci, Deka, and Hecto
--  are not supported by these subprograms.  You can use the Scaling package to
--  convert between differently prefixed value and work from there, though.
--------------------------------------------------------------------------------
package SI_Units.Metric is

   type Prefixes is (yocto, zepto, atto, femto, pico, nano, micro, milli,
                     None,
                     kilo, Mega, Giga, Tera, Peta, Exa, Zetta, Yotta);
   --  Prefixes supported in instantiated Image subprograms.

   Magnitude : constant := 1000.0;
   --  Magnitude change when trying to find the best representation for a given
   --  value.

   --
   --  Generic image function for different types.
   --
   --  Parameters:
   --
   --  Item        - the type you want an Image function instantiated for.
   --  Default_Aft - the default number of digits after the decimal point
   --                (regardless of the prefix finally used).
   --  Unit        - The name of your unit, e.g. "Hz", "m" or such (also see
   --                package SI_Units.Names).
   --

   generic
      type Item is delta <>;
      Default_Aft : in Ada.Text_IO.Field;
      Unit        : in Unit_Name;
   function Fixed_Image
     (Value : in Item;
      Aft   : in Ada.Text_IO.Field := Default_Aft) return String with
     Global => null;
   --  Image subroutine that can be instantiated for fixed types.

   generic
      type Item is digits <>;
      Default_Aft : in Ada.Text_IO.Field;
      Unit        : in Unit_Name;
   function Float_Image
     (Value : in Item;
      Aft   : in Ada.Text_IO.Field := Default_Aft) return String with
     Global => null;
   --  Image subroutine that can be instantiated for floating point types.

   generic
      type Item is range <>;
      Default_Aft : in Ada.Text_IO.Field;
      Unit        : in Unit_Name;
   function Integer_Image
     (Value : in Item;
      Aft   : in Ada.Text_IO.Field := Default_Aft) return String with
     Global => null;
   --  Image subroutine that can be instantiated for integer types.

   generic
      type Item is mod <>;
      Default_Aft : in Ada.Text_IO.Field;
      Unit        : in Unit_Name;
   function Mod_Image
     (Value : in Item;
      Aft   : in Ada.Text_IO.Field := Default_Aft) return String with
     Global => null;
   --  Image subroutine that can be instantiated for modular types.

end SI_Units.Metric;