File: schema-decimal.ads

package info (click to toggle)
libxmlada 18-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,324 kB
  • sloc: ada: 32,766; makefile: 480; xml: 111; sh: 43; python: 35
file content (123 lines) | stat: -rw-r--r-- 5,351 bytes parent folder | download
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
------------------------------------------------------------------------------
--                     XML/Ada - An XML suite for Ada95                     --
--                                                                          --
--                     Copyright (C) 2005-2017, AdaCore                     --
--                                                                          --
-- This library is free software;  you can redistribute it and/or modify it --
-- under terms of the  GNU General Public License  as published by the Free --
-- Software  Foundation;  either version 3,  or (at your  option) any later --
-- version. This library is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- --
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
--                                                                          --
------------------------------------------------------------------------------

--  This package provides the basic types to define the facets for an XSD type

pragma Ada_05;

with Sax.Symbols;
with Sax.Utils;
with Unicode.CES;

package Schema.Decimal is

   ---------------------------------
   -- Arbitrary_Precision_Numbers --
   ---------------------------------
   --  This type provides some minimal handling for arbitrary precision
   --  numbers as described by the "decimal" and "integer" types.
   --  This is *not* an arbitrary-precision library, which is not needed in the
   --  context of XML

   type Arbitrary_Precision_Number is private;
   Undefined_Number : constant Arbitrary_Precision_Number;

   function Image
     (Number : Arbitrary_Precision_Number) return Unicode.CES.Byte_Sequence;
   --  Return a displayable version of Number

   procedure Value
     (Symbols  : Sax.Utils.Symbol_Table;
      Ch       : Unicode.CES.Byte_Sequence;
      Val      : out Arbitrary_Precision_Number;
      Error    : out Sax.Symbols.Symbol);
   --  Convert Ch to a number.
   --  Raises a Validation_Error if this is not a valid number

   function Value (Val : Sax.Symbols.Symbol) return Arbitrary_Precision_Number;
   --  Assumes [Val] is a valid Arbitrary_Precision_Number.

   procedure Value_No_Exponent
     (Symbols  : Sax.Utils.Symbol_Table;
      Ch       : Unicode.CES.Byte_Sequence;
      Val      : out Arbitrary_Precision_Number;
      Error    : out Sax.Symbols.Symbol);
   --  Same as value, but does not allow a "E" part

   function "<"  (Num1, Num2 : Arbitrary_Precision_Number) return Boolean;
   function "<=" (Num1, Num2 : Arbitrary_Precision_Number) return Boolean;
   function "="  (Num1, Num2 : Arbitrary_Precision_Number) return Boolean;
   function ">=" (Num1, Num2 : Arbitrary_Precision_Number) return Boolean;
   function ">"  (Num1, Num2 : Arbitrary_Precision_Number) return Boolean;
   --  Compare two numbers

   function Check_Digits
     (Symbols                       : Sax.Utils.Symbol_Table;
      Num                           : Arbitrary_Precision_Number;
      Fraction_Digits, Total_Digits : Integer := -1)
      return Sax.Symbols.Symbol;
   --  Check whether the two facets Fraction_Digits and Total_Digits match.
   --  If any of the two values is negative, no check is done for it.
   --  Returns an error message or [No_Symbol].

   ---------------
   -- XML_Float --
   ---------------
   --  This type represents a floating point value (float or double in XSD),
   --  including infinity and NaN

   type XML_Float is private;
   Unknown_Float : constant XML_Float;

   function "<=" (F1, F2 : XML_Float) return Boolean;
   function "<" (F1, F2 : XML_Float) return Boolean;
   function ">=" (F1, F2 : XML_Float) return Boolean;
   function ">" (F1, F2 : XML_Float) return Boolean;
   --  Compare two numbers

   function Image (Value : XML_Float) return String;
   --  Return a displayable version of Number

   function Value (Str : String) return XML_Float;
   --  Return the float stored in Str (including +INF, -INF)

private
   type Arbitrary_Precision_Number is record
      Value : Sax.Symbols.Symbol;
   end record;
   Undefined_Number : constant Arbitrary_Precision_Number :=
     (Value => Sax.Symbols.No_Symbol);

   type XML_Float_Kind is (Plus_Infinity, Minus_Infinity, NaN, Standard_Float);
   type XML_Float (Kind : XML_Float_Kind := NaN) is record
      case Kind is
         when Standard_Float =>
            Mantiss : Long_Long_Float;
            Exp     : Integer;
         when others =>
            null;
      end case;
   end record;
   Unknown_Float : constant XML_Float := (Kind => NaN);

end Schema.Decimal;