parse_args_0.9.0_635f9e4f/src/parse_args-generic_discrete_array_options.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
-- parse_args-generic_discrete_array_options.ads
-- A simple command line option parser

-- Copyright (c) 2015, James Humphry
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
-- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
-- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-- OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-- PERFORMANCE OF THIS SOFTWARE.

pragma Profile(No_Implementation_Extensions);

with Ada.Unchecked_Deallocation;

with Parse_Args.Generic_Indefinite_Options;
with Parse_Args.Split_CSV;

generic
   type Element is (<>);
   type Element_Array is array (Integer range <>) of Element;
   type Element_Array_Access is access Element_Array;
   with procedure Valid (Arg : in Element_Array_Access; Result : in out Boolean) is null;
package Parse_Args.Generic_Discrete_Array_Options is

   procedure Free_Element_Array is new Ada.Unchecked_Deallocation(Object => Element_Array,
                                                                  Name => Element_Array_Access);

   function Split_CSV_Element_Array is new Split_CSV(Element => Element,
                                                     Element_Array => Element_Array,
                                                     Element_Array_Access => Element_Array_Access,
                                                     Value => Element'Value);

   function Element_Array_Image(Arg : Element_Array_Access) return String;

   package Inner is new Parse_Args.Generic_Indefinite_Options(Element => Element_Array,
                                                              Element_Access => Element_Array_Access,
                                                              Value => Split_CSV_Element_Array,
                                                              Image => Element_Array_Image,
                                                              Free_Element => Free_Element_Array,
                                                              Valid => Valid
                                                             );

   subtype Element_Array_Option is Inner.Element_Option;
   function Image (O : in Element_Array_Option) return String renames Inner.Image;
   function Value (O : in Element_Array_Option) return Element_Array_Access renames Inner.Value;
   function Value(A : in Argument_Parser; Name : in String) return Element_Array_Access renames Inner.Value;
   function Make_Option return Option_Ptr renames Inner.Make_Option;

end Parse_Args.Generic_Discrete_Array_Options;