gnoga_2.1.2_5f127c56/deps/zanyblue/src/parameters/zanyblue-parameters-sets.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
--  -*- coding: utf-8 -*-
--
--  ZanyBlue, an Ada library and framework for finite element analysis.
--
--  Copyright (c) 2012, 2016, Michael Rohan <mrohan@zanyblue.com>
--  All rights reserved.
--
--  Redistribution and use in source and binary forms, with or without
--  modification, are permitted provided that the following conditions
--  are met:
--
--    * Redistributions of source code must retain the above copyright
--      notice, this list of conditions and the following disclaimer.
--
--    * Redistributions in binary form must reproduce the above copyright
--      notice, this list of conditions and the following disclaimer in the
--      documentation and/or other materials provided with the distribution.
--
--    * Neither the name of ZanyBlue nor the names of its contributors may
--      be used to endorse or promote products derived from this software
--      without specific prior written permission.
--
--  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
--  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
--  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
--  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
--  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
--  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
--  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
--  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
--  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
--  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
--  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--

with Ada.Calendar;
with UXStrings.Text_IO;
with ZanyBlue.Parameters.Values;

private with ZanyBlue.Text;
private with Ada.Containers.Indefinite_Hashed_Maps;

package ZanyBlue.Parameters.Sets is

   use Ada.Calendar;
   use ZanyBlue.Parameters.Values;

   type Parameter_Set_Type is tagged private;

   function Number_Of_Parameters
     (Params : Parameter_Set_Type)
      return Natural;
   --  Return the number of parameters defined in a parameter set.

   procedure Clear (Params : in out Parameter_Set_Type);
   --  Clear any parameters defined in the parameter set.

   procedure Append
     (Params : in out Parameter_Set_Type;
      Name   :        String;
      Value  :        String);
   --  Append a string to a list value.  The list value is created if it
   --  doesn't already exist.

   procedure Prepend
     (Params : in out Parameter_Set_Type;
      Name   :        String;
      Value  :        String);
   --  Prepend a string to a list value.  The list value is created if it
   --  doesn't already exist.

   function Get
     (Params : Parameter_Set_Type;
      Name   : String)
      return Value_Type'Class;
   --  General parameter query routine.  This can be used to handle user
   --  defined parameter types.

   function Get_Boolean
     (Params : Parameter_Set_Type;
      Name   : String)
      return Boolean;
   --  Get the value of boolean parameter.  Both Not_A_Boolean_Error and
   --  Not_Defined_Error can be raised.

   function Get_Float
     (Params : Parameter_Set_Type;
      Name   : String)
      return Float;
   --  Get the value of floating point parameter.  Both Not_A_Real_Error and
   --  Not_Defined_Error can be raised.

   function Get_Integer
     (Params : Parameter_Set_Type;
      Name   : String)
      return Integer;
   --  Return the value of an integer parameter.  Both Not_An_Integer and
   --  Not_Defined_Error can be raised.

   function Get_List
     (Params : Parameter_Set_Type;
      Name   : String)
      return List_Type;
   --  Return the value of a list parameter.  An Not_Defined_Error can be
   --  raised.

   function Get_String
     (Params : Parameter_Set_Type;
      Name   : String)
      return String;
   --  Return the value of a string parameter.  Not_Defined_Error can be
   --  raised.

   function Get_Time
     (Params : Parameter_Set_Type;
      Name   : String)
      return Time;
   --  Return the value of a time parameter.  Not_Defined_Error can be
   --  raised.

   function Get_Name
     (Params : Parameter_Set_Type)
      return String;
   --  Return the name associated with the parameter set.  This the empty
   --  string, by default, but can be set using the Set_Name routine.

   procedure Increment
     (Params    : in out Parameter_Set_Type;
      Name      :        String;
      By_Amount :        Integer := 1);
   --  Increment the value of an integer parameter.  Both Not_An_Integer and
   --  Not_Defined_Error can be raised.

   function Is_Defined
     (Params : Parameter_Set_Type;
      Name   : String)
      return Boolean;
   --  Determine if a parameter is defined in the parameter set.

   procedure Set_Name
     (Params : in out Parameter_Set_Type;
      Name   :        String);
   --  Set the name associated with a parameter set.

   procedure Set
     (Params : in out Parameter_Set_Type;
      Name   :        String;
      Value  :        Value_Type'Class);
   --  General parameter set routine.  This can be used to support user
   --  defined parameter types.

   procedure Set_Boolean
     (Params : in out Parameter_Set_Type;
      Name   :        String;
      Value  :        Boolean);
   --  Set a boolean parameter value.

   procedure Set_Float
     (Params : in out Parameter_Set_Type;
      Name   :        String;
      Value  :        Float);
   --  Set a floating point parameter value.

   procedure Set_Integer
     (Params : in out Parameter_Set_Type;
      Name   :        String;
      Value  :        Integer);
   --  Set an integer parameter value.

   procedure Set_Time
     (Params : in out Parameter_Set_Type;
      Name   :        String;
      Value  :        Time);
   --  Set a time parameter value.

   procedure Set_String
     (Params : in out Parameter_Set_Type;
      Name   :        String;
      Value  :        String);
   --  Set a string parameter value.

   function Type_Name
     (Params : Parameter_Set_Type;
      Name   : String)
      return String;
   --  Return the type name a parameter.  Not_Defined_Error can be
   --  raised.

   procedure Dump
     (Params      : Parameter_Set_Type;
      Destination : UXStrings.Text_IO.File_Type;
      Level       : Natural := 0);
   --  Write the set of parameters defined in a parameter set to a file.  This
   --  is a debugging routine.

--     procedure Dump
--       (Params      : Parameter_Set_Type;
--        Destination : Ada.Wide_Text_IO.File_Type;
--        Level       : Natural := 0);
   --  Write the set of parameters defined in a parameter set to a file.  This
   --  is a debugging routine.

private

   function Equivalent_Keys
     (Left, Right : String)
      return Boolean;
   --  Key matching function to support the Hashed_Map data structure.

   package Params_Hash_Map is new Ada.Containers.Indefinite_Hashed_Maps
     (Key_Type => String, Element_Type => Value_Type'Class,
      Hash     => ZanyBlue.Text.Wide_Hash, Equivalent_Keys => Equivalent_Keys);
   --  Parameters are stored as a simple Hashed_Map.

   type Parameter_Set_Type is tagged record
      Name   : String;
      Values : Params_Hash_Map.Map;
   end record;
   --  The parameter set is a name and the set of values.

end ZanyBlue.Parameters.Sets;