~framefritti/gclp/trunk

« back to all changes in this revision

Viewing changes to generic_line_parser-storing.ads

  • Committer: Riccardo
  • Date: 2014-05-21 20:32:25 UTC
  • Revision ID: framefritti@gmail.com-20140521203225-x2m9woolcciwkkdy
Began working on an extension

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
with Ada.Finalization;
 
2
 
 
3
generic
 
4
   type Parameter_Index is (<>);
 
5
package Generic_Line_Parser.Storing is
 
6
   type Parameter_Type is (Str, Real, Int);
 
7
 
 
8
   type Action_Descriptor is
 
9
      new Ada.Finalization.Limited_Controlled
 
10
   with private;
 
11
 
 
12
   function Call (Callback : Parameter_Callback) return Action_Descriptor;
 
13
 
 
14
   function Store (Name : Parameter_Index;
 
15
                   Format : Parameter_Type)
 
16
                   return Action_Descriptor;
 
17
 
 
18
 
 
19
   type Extended_Descriptor is
 
20
      record
 
21
         Name       : Unbounded_String;    -- Parameter name
 
22
         Default    : Unbounded_String;    -- Default value used if not on C.L.
 
23
         If_Missing : Missing_Action;      -- What to do if parameter missing
 
24
         Only_Once  : Boolean;             -- Parameter MUST NOT be given more than once
 
25
         Action     : Action_Descriptor;
 
26
      end record;
 
27
 
 
28
    type Extended_Descriptor_Array is
 
29
      array (Natural range <>) of Extended_Descriptor;
 
30
 
 
31
   procedure Parse_Command_Line
 
32
     (Parameters  : in     Extended_Descriptor_Array;
 
33
      Result      :    out Config_Data;
 
34
      Help_Line   : in     String := "";
 
35
      Help_Output : in     Ada.Text_IO.File_Type := Ada.Text_IO.Standard_Error);
 
36
 
 
37
   function Get (Name : Parameter_Index) return Integer;
 
38
   function Get (Name : Parameter_Index) return Float;
 
39
   function Get (Name : Parameter_Index) return String;
 
40
private
 
41
   type Action_Class is (Call, Store);
 
42
 
 
43
   type Action_Internal_Descriptor (Class : Action_Class) is
 
44
      record
 
45
         case Class is
 
46
            when Call =>
 
47
               Handle : Parameter_Callback;
 
48
 
 
49
            when Store =>
 
50
               Where  : Parameter_Index;
 
51
               Format : Parameter_Type;
 
52
         end case;
 
53
      end record;
 
54
 
 
55
   type Access_Internal_Descriptor is
 
56
      access Action_Internal_Descriptor;
 
57
 
 
58
   type Action_Descriptor is
 
59
      new Ada.Finalization.Limited_Controlled with
 
60
      record
 
61
         Handle : Access_Internal_Descriptor;
 
62
      end record;
 
63
 
 
64
   overriding procedure Finalize (Object : in out Action_Descriptor);
 
65
end Generic_Line_Parser.Storing;