cashe_1.0.0_d142893b/src/cashe-currency_handling.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
 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
pragma Assertion_Policy (Check);
with ISO.Currencies;
with Ada.Strings.Wide_Wide_Unbounded;
--  ****h* Cashe/Currency_Handling
--  SOURCE
package Cashe.Currency_Handling is
--  DESCRIPTION
--    This package provides methods of defining custom currency and storing
--    currencies.
--  ****

   --  ****c* Currency_Handling/Currency_Handling.Custom_Currency
   --  SOURCE
   type Custom_Currency is tagged private;
   --  DESCRIPTION
   --    Allows for defining and storing a custom currency.  Member functions
   --    can be used to retrieve information such as its code, minor units,
   --    and symbols.  Can be initialized with the Create function.
   --  USAGE
   --    with Cashe.Currency_Handling; use Cashe.Currency_Handling;
   --    King : Custom_Currency := Create (Code => "KNG",
   --                                      Minor_Unit => 2,
   --                                      Name => "King Currency",
   --                                      Symbol => "K");
   --  METHODS
   --  * Currency_Handling.Custom_Currency/Set_Code
   --  * Currency_Handling.Custom_Currency/Set_Name
   --  * Currency_Handling.Custom_Currency/Set_Symbol
   --  * Currency_Handling.Custom_Currency/Set_Unit
   --  * Currency_Handling.Custom_Currency/Code
   --  * Currency_Handling.Custom_Currency/Name
   --  * Currency_Handling.Custom_Currency/Symbol
   --  * Currency_Handling.Custom_Currency/Unit
   --  ****

   --  ****m* Currency_Handling.Custom_Currency/Set_Code
   --  SOURCE
   procedure Set_Code
      (This : in out Custom_Currency;
       --  The custom currency
       Item : Wide_Wide_String
       --  New code for the custom currency
      );
   --  FUNCTION
   --    [Re]define the code associated with the currency.
   --  PARAMETERS
   --    Item - New code for the custom currency as wide_wide_string
   --  EXAMPLE
   --    with Cashe.Currency_Handling; use Cashe.Currency_Handling;
   --    declare
   --       My_Cur : Custom_Currency;
   --    begin
   --       My_Cur.Set_Code ("CUR");
   --    end;
   --  ****

   --  ****m* Currency_Handling.Custom_Currency/Set_Name
   --  SOURCE
   procedure Set_Name
      (This : in out Custom_Currency;
       --   The custom currency.
       Item : Wide_Wide_String
       --  New name
      );
   --  FUNCTION
   --    [Re]define the name of the custom currency.
   --  PARAMETERS
   --    Item - New name as wide_wide_string
   --  EXAMPLE
   --    with Cashe.Currency_Handling; use Cashe.Currency_Handling;
   --    declare
   --       My_Cur : Custom_Currency;
   --    begin
   --       My_Cur.Set_Name ("Custom Currency");
   --    end;
   --  ****

   --  ****m* Currency_Handling.Custom_Currency/Set_Symbol
   --  SOURCE
   procedure Set_Symbol
      (This : in out Custom_Currency;
       --   The custom currency.
       Item : Wide_Wide_String
       --  New symbol
      );
   --  FUNCTION
   --    [Re]define the symbol of the custom currency.
   --  PARAMETERS
   --    Item - New symbol as wide_wide_string
   --  EXAMPLE
   --    with Cashe.Currency_Handling; use Cashe.Currency_Handling;
   --    declare
   --       My_Cur : Custom_Currency;
   --    begin
   --       My_Cur.Set_Symbol ("$");
   --    end;
   --  ****

   --  ****m* Currency_Handling.Custom_Currency/Set_Unit
   --  SOURCE
   procedure Set_Unit
      (This : in out Custom_Currency;
       --  The custom currency.
       Item : Natural
       --  New minor
      );
   --  FUNCTION
   --    [Re]define the minor unit of the custom currency.
   --  PARAMETERS
   --    Item - New symbol unit as Natural
   --  EXAMPLE
   --    with Cashe.Currency_Handling; use Cashe.Currency_Handling;
   --    declare
   --       My_Cur : Custom_Currency;
   --    begin
   --       My_Cur.Set_Unit (2);
   --    end;
   --  ****

   --  ****m* Currency_Handling.Custom_Currency/Code
   --  SOURCE
   function  Code   (This : Custom_Currency) return Wide_Wide_String;
   --  FUNCTION
   --    Retrieves the code of the custom currency.
   --  RETURN VALUE
   --    Wide_Wide_String - Code belonging to currency.
   --  EXAMPLE
   --    Ada.Text_Wide_Wide_IO.Put_Line (My_Currency.Code);
   --  ****

   --  ****m* Currency_Handling.Custom_Currency/Name
   --  SOURCE
   function  Name   (This : Custom_Currency) return Wide_Wide_String;
   --  FUNCTION
   --    Retrieves the name of the custom currency.
   --  RETURN VALUE
   --    Wide_Wide_String - name belonging to currency.
   --  EXAMPLE
   --    Ada.Text_Wide_Wide_IO.Put_Line (My_Currency.Name);
   --  ****

   --  ****m* Currency_Handling.Custom_Currency/Symbol
   --  SOURCE
   function  Symbol (This : Custom_Currency) return Wide_Wide_String;
   --  FUNCTION
   --    Retrieves the symbol of the custom currency.
   --  RETURN VALUE
   --    Wide_Wide_String - symbol belonging to currency.
   --  EXAMPLE
   --    Ada.Text_Wide_Wide_IO.Put_Line (My_Currency.Symbol);
   --  ****

   --  ****m* Currency_Handling.Custom_Currency/Unit
   --  SOURCE
   function  Unit   (This : Custom_Currency) return Natural;
   --  FUNCTION
   --    Retrieves the code of the custom currency.
   --  RETURN VALUE
   --    Natural - Minor Unit belonging to currency.
   --  EXAMPLE
   --    My_Unit : Natural := My_Currency.Unit;
   --  ****

   --  ****f* Currency_Handling/Currency_Handling.Create
   --  SOURCE
   function Create
      (Code        : Wide_Wide_String;
       --  Currency's code
       Minor_Unit  : Natural := 0;
       --  Currency's minor unit. Optional.
       Name        : Wide_Wide_String := "";
       --  Currency's name. Optional.
       Symbol      : Wide_Wide_String := ""
       --  Currency's symbol. Optional.
      )
   return Custom_Currency with pre => Minor_Unit <= Max_Precision;
   --  FUNCTION
   --    Create a custom currency according to parameters. Minor unit may not
   --    be greater than maximum precision supported by library.
   --  PARAMETERS
   --    Code - A code as a string, such as "EUR" or "USD".
   --    Minor_Unit - Currency's minor unit. Optional.
   --    Name - Currency's name. Optional.
   --    Symbol - Currency's symbol. Optional.
   --  RETURN VALUE
   --    Currency_Handling/Currency_Handling.Custom_Currency
   --  EXAMPLE
   --    King : Custom_Currency := Create (Code => "KNG",
   --                                      Minor_Unit => 2,
   --                                      Name => "King Currency",
   --                                      Symbol => "K");
   --  ****

   --  ****t* Currency_Handling/Currency_Handling.Currency_Type
   --  SOURCE
   type Currency_Type is (Type_Custom_Currency, Type_ISO_Currency);
   --  DESCRIPTION
   --    For Currency_Data variant record.
   --  SEE ALSO
   --    Currency_Handling/Currency_Handling.Currency_Data
   --  ****

   --  ****s* Currency_Handling/Currency_Handling.Currency_Data
   --  SOURCE
   type Currency_Data
      (Which_Currency_Type : Currency_Type := Type_ISO_Currency)
   is record
      case Which_Currency_Type is
         when Type_Custom_Currency =>
            --  The custom currency that will be stored in money/exchange.
            Custom_Code : Custom_Currency;
         when Type_ISO_Currency =>
            --  The ISO currency that will be stored in the money/exchange.
            ISO_Code : ISO.Currencies.Currency;
      end case;
   end record;
   --  DESCRIPTION
   --     A "holder" for both custom or non-custom currency, if needed.
   --     Which kind of currency can be verified by accessing the object's
   --     "Which_Currency_Data" later on.
   --  PARAMETERS
   --    Which_Currency_Type: Which kind of currency?
   --  EXAMPLE
   --    declare
   --       My_Holder : Currency_Data :=
   --          (Which_Currency_Type => Type_ISO_Currency,
   --           ISO_Code            => ISO.Currencies.From_Code ("USD"));
   --    begin
   --       case My_Holder.Which_Currency_Type is
   --          when Type_Custom_Currency =>
   --             Put_Line ("Currency is " & My_Holder.Custom_Code.Name);
   --          when Type_ISO_Currency =>
   --             Put_Line ("Currency is " & My_Holder.ISO_Code.Name);
   --             Put_Line ("And Numeric is " & My_Holder.ISO_Code.Numeric);
   --       end case;
   --    end;
   --  SEE ALSO
   --    Currency_Handling/Currency_Handling.Currency_Type
   --  ****

private

   type Custom_Currency is tagged record
      Custom_Code   :
         Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
      Custom_Symbol :
         Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
      Custom_Name   :
         Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;
      Custom_Minor_Unit : Natural := 0;
   end record;

end Cashe.Currency_Handling;