agpl_1.0.0_b5da3320/src/agpl-interfaces-c-arrays.adb

 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
with Ada.Numerics.Elementary_Functions;

package body Agpl.Interfaces.C.Arrays is

   --------------
   -- To_Array --
   --------------

   function To_Array (This : C_Matrix) return C_Array is
      R : C_Array (1 .. This'Length (1) * This'Length (2));
      I : Positive := R'First;
   begin
      for Row in This'Range (1) loop
         for Col in This'Range (2) loop
            R (I) := This (Row, Col);
            I := + 1;
         end loop;
      end loop;

      return R;
   end To_Array;

   ---------------
   -- To_Matrix --
   ---------------

   function To_Matrix (This : C_Array) return C_Matrix is
      use Ada.Numerics.Elementary_Functions;

      R : C_Matrix (1 .. Natural (Sqrt (Float (This'Length))),
                    1 .. Natural (Sqrt (Float (This'Length))));
      I : Positive := This'First;
   begin
      for Row in R'Range (1) loop
         for Col in R'Range (2) loop
            R (Row, Col) := This (I);
            I := I + 1;
         end loop;
      end loop;

      return R;
   end To_Matrix;

end Agpl.Interfaces.C.Arrays;