with Text_Io;
with Dynarray_Pkg;
with Type_Definitions, Implementation_Dependencies;
with String_Pkg;

package Varhand is

    --| overview
    --| VARiableHANDler is a package to handle the initialization, assignment,
    --| and other operations of variable record arrays.  it also defines all
    --| variable related types.

    --| n/a: errors, raises, modifies, requires

    --version:             0.0
    --author:              Alexis Wei
    --initial release:     05/14/85

    use Type_Definitions, Implementation_Dependencies;

    subtype Variable_Kind is Logfile_Keys
                                range Integer_Variable .. Fixed_Point_Variable;

    type Variable_Record (Whichkind : Variable_Kind) is
        record
            Programid : Program_Unit_Unique_Identifier;
            Variablename : Filename;
            Unitname : Filename;
            Variablecount : Positive;
            case Whichkind is
                when Integer_Variable =>
                    Current_V : Integer;
                    Max_V : Integer;
                    Min_V : Integer;
                    Average_V : Integer;

                when Float_Variable =>
                    Current_Fv : Float;
                    Max_Fv : Float;
                    Min_Fv : Float;
                    Average_Fv : Float;

                when Long_Integer_Variable =>
                    Current_Liv : Long_Integer;
                    Max_Liv : Long_Integer;
                    Min_Liv : Long_Integer;
                    Average_Liv : Long_Integer;


                --                when Long_Float_Variable =>
                --                    Current_Lfv : Long_Float;
                --                    Max_Lfv     : Long_Float;
                --                    Min_Lfv     : Long_Float;
                --                    Average_Lfv : Long_Float;

                -- when fixed_point_variable =>
                -- current_fpv:       fixed_point;
                -- max_fpv:           fixed_point;
                -- min_fpv:           fixed_point;
                -- average_fpv:       fixed_point;

                when others =>
                    null;
            end case;
        end record;

    type Loop_Record is
        record
            Programid : Program_Unit_Unique_Identifier;
            Brkpt_No : Breakpoint_Number_Range;
            Brkptcount : Positive;
            Unitname : Filename;
        end record;

    subtype Ivrecord is Variable_Record (Integer_Variable);
    subtype Livrecord is Variable_Record (Long_Integer_Variable);
    subtype Fvrecord is Variable_Record (Float_Variable);
    --    subtype Lfvrecord is Variable_Record (Long_Float_Variable);

    package Ivdarray_Pkg is new Dynarray_Pkg (Ivrecord);
    use Ivdarray_Pkg;
    package Livdarray_Pkg is new Dynarray_Pkg (Livrecord);
    use Livdarray_Pkg;
    package Fvdarray_Pkg is new Dynarray_Pkg (Fvrecord);
    use Fvdarray_Pkg;
    --    package Lfvdarray_Pkg is new
    --        Dynarray_Pkg (Lfvrecord);
    --    use Lfvdarray_Pkg;


    procedure Initarray ( --| to initialize the 1st element of variable array
                         Ivarray : in out Ivrecord;
                         Idarray : in out Ivdarray_Pkg.Darray;
                         Pid : in Program_Unit_Unique_Identifier;
                         Vname : in Filename;
                         Unitname : in Filename;
                         Value : in Integer;
                         Kunt : in Natural);


    procedure Initarray ( --| to initialize the 1st element of variable array
                         Livarray : in out Livrecord;
                         Lidarray : in out Livdarray_Pkg.Darray;
                         Pid : in Program_Unit_Unique_Identifier;
                         Vname : in Filename;
                         Unitname : in Filename;
                         Value : in Long_Integer;
                         Kunt : in Natural);


    procedure Initarray ( --| to initialize the 1st element of variable array
                         Fvarray : in out Fvrecord;
                         Fdarray : in out Fvdarray_Pkg.Darray;
                         Pid : in Program_Unit_Unique_Identifier;
                         Vname : in Filename;
                         Unitname : in Filename;
                         Value : in Float;
                         Kunt : in Natural);


    --    procedure Initarray ( --| to initialize the 1st element of variable array
    --                         Lfvarray : in out Lfvrecord;
    --                         Lfdarray : in out Lfvdarray_Pkg.Darray;
    --                         Pid : in Program_Unit_Unique_Identifier;
    --                         Vname : in Filename;
    --                         Unitname : in Filename;
    --                         Value : in Long_Float;
    --                         Kunt : in Natural);


    --procedure initarray (--| to initialize the 1st element of variable array
    --                     fparray:            in out fpvrecord;
    --                     fpdarray:           in out fpvdarray_pkg.darray;
    --                     pid:                in program_unit_unique_identifier;
    --                     vname:              in filename;
    --                     unitname:           in filename;
    --                     value:              in fixed_point;
    --                     kunt:               in natural);

    procedure Find_Variable (--| check to see if the variable read is an
                             --| existing variable, it also return the
                             --| array index if found
                             Pid : in Program_Unit_Unique_Identifier;
                             Idarray : in out Ivdarray_Pkg.Darray;
                             Ivarray : in out Ivrecord;
                             Vname : in Filename;
                             Kunt : in Natural;
                             Idx : out Natural;
                             Found : out Boolean);

    procedure Find_Variable (--| check to see if the variable read is an
                             --| existing variable, it also return the
                             --| array index if found
                             Pid : in Program_Unit_Unique_Identifier;
                             Lidarray : in out Livdarray_Pkg.Darray;
                             Livarray : in out Livrecord;
                             Vname : in Filename;
                             Kunt : in Natural;
                             Idx : out Natural;
                             Found : out Boolean);

    procedure Find_Variable (--| check to see if the variable read is an
                             --| existing variable, it also return the
                             --| array index if found
                             Pid : in Program_Unit_Unique_Identifier;
                             Fdarray : in out Fvdarray_Pkg.Darray;
                             Fvarray : in out Fvrecord;
                             Vname : in Filename;
                             Kunt : in Natural;
                             Idx : out Natural;
                             Found : out Boolean);

    --    procedure Find_Variable (--| check to see if the variable read is an
    --                          --| existing variable, it also return the
    --                          --| array index if found
    --                             Pid : in Program_Unit_Unique_Identifier;
    --                             Lfdarray : in out Lfvdarray_Pkg.Darray;
    --                             Lfvarray : in out Lfvrecord;
    --                             Vname : in Filename;
    --                             Kunt : in Natural;
    --                             Idx : out Natural;
    --                             Found : out Boolean);

    --procedure find_variable(--| check to see if the variable read is an --janus
    --                        --| existing variable, it also return the   --janus
    --                        --| array index if found                    --janus
    --                        pid:             in     program_unit_unique_identifier;
    --                        fpdarray:        in out fpdarray_pkg.darray;
    --                        fparray:         in out variable_record(fixed_point_variable);
    --                        vname:           in filename;
    --                        kunt:            in natural;
    --                        idx:             out natural;
    --                        found:           out boolean);


    procedure Find_Maxmin (Ivarray : in out Ivrecord;
                           Idarray : in out Ivdarray_Pkg.Darray;
                           Idx : in Natural;
                           Value : in Integer);


    procedure Find_Maxmin (Livarray : in out Livrecord;
                           Lidarray : in out Livdarray_Pkg.Darray;
                           Idx : in Natural;
                           Value : in Long_Integer);


    procedure Find_Maxmin (Fvarray : in out Fvrecord;
                           Fdarray : in out Fvdarray_Pkg.Darray;
                           Idx : in Natural;
                           Value : in Float);



    --    procedure Find_Maxmin (Lfvarray : in out Lfvrecord;
    --                           Lfdarray : in out Lfvdarray_Pkg.Darray;
    --                           Idx : in Natural;
    --                           Value : in Long_Float);


    --procedure find_maxmin(
    --                        fpvarray:        in out variable_record(fixed_point_variable);
    --                        fpdarray:        in out fpvdarray_pkg.darray;
    --                        idx:             in natural;
    --                        value:           in fixed_point);


    function Last_Value ( --| Return the last value of the string variable
                         Unit_Id : Program_Unit_Unique_Identifier;
                         Variable_Name : Ada_Name;
                         Current_Value : String_Variables) return String;

    --| Effects
    --| Searches the String_Variable_Array for the last value of
    --| the specified string variable. If it is the first occurrence
    --| of the string variable then it is added to the array and
    --| a null String_Type is returned. Otherwise the last value
    --| stored in the array for the string variable is returned.
    --| If the current value of the string variable is different
    --| than the previous value then the array is updated with the
    --| new current value.

    --| Modifies
    --| If it is the first occurrence of the string value of the string
    --| variable of if the current value is different than the previous
    --| value then the String_Array is updated

    --| N/A: Raises, Requires, Errors


    function Long_Integer_To_Str
                (Lint : Long_Integer; Width : Natural := 0) return String;

    function Float_To_Str (Flo : Float; Width : Natural := 0) return String;

    --    function Long_Float_To_Str (
    --                                Lflo : Long_Float;
    --                                Width : Natural := 0
    --                                ) return String;

end Varhand;