phcpack_2.4.88_e448e94a/src/Ada/CtoPHC/Types/c_to_ada_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
 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
with Interfaces.C;
with Standard_Integer_Numbers;            use Standard_Integer_Numbers;
with Standard_Floating_Numbers;           use Standard_Floating_Numbers;
with Standard_Complex_Numbers;
with Double_Double_Numbers;               use Double_Double_Numbers;
with DoblDobl_Complex_Numbers;
with Quad_Double_Numbers;                 use Quad_Double_Numbers;
with QuadDobl_Complex_Numbers;

package body C_to_Ada_Arrays is

  function Convert ( v : C_Integer_Array )
                   return Standard_Integer_Vectors.Vector is

    res : Standard_Integer_Vectors.Vector(0..integer32(v'length)-1);

  begin
    for i in v'range loop
      res(integer32(i)) := integer32(v(i));
    end loop;
    return res;
  end Convert;

  function Convert ( v : Standard_Integer_Vectors.Vector )
                   return C_Integer_Array is

    res : C_Integer_Array(0..Interfaces.C.size_T(v'length-1));
    ind : Interfaces.C.size_T := 0;

    use Interfaces.C;

  begin
    for i in v'range loop
      res(ind) := Interfaces.C.int(v(i));
      ind := ind + 1;
    end loop;
    return res;
  end Convert;

  function Convert ( v : C_Double_Array )
                   return Standard_Floating_Vectors.Vector is

    res : Standard_Floating_Vectors.Vector(0..integer32(v'length)-1);

  begin
    for i in v'range loop
      res(integer32(i)) := double_float(v(i));
    end loop;
    return res;
  end Convert;

  function Convert ( v : Standard_Floating_Vectors.Vector )
                   return C_Double_Array is

    res : C_Double_Array(0..Interfaces.C.size_T(v'length-1));
    ind : Interfaces.C.size_T := 0;

    use Interfaces.C;

  begin
    for i in v'range loop
      res(ind) := Interfaces.C.double(v(i));
      ind := ind + 1;
    end loop;
    return res;
  end Convert;

  function Convert ( v : C_Double_Array )
                   return Standard_Complex_Vectors.Vector is

    vlen : constant integer32 := integer32(v'length);
    res : Standard_Complex_Vectors.Vector(1..vlen/2);
    ind : Interfaces.C.size_T := 0;

    use Interfaces.C,Standard_Complex_Numbers;

  begin
    for i in res'range loop
      res(i) := Create(double_float(v(ind)),double_float(v(ind+1)));
      ind := ind + 2;
    end loop;
    return res;
  end Convert;

  function Convert ( v : Standard_Complex_Vectors.Vector )
                   return C_Double_Array is

    res : C_Double_Array(0..Interfaces.C.size_T(2*v'length-1));
    ind : Interfaces.C.size_T := 0;
    re,im : double_float;
    use Interfaces.C;

  begin
    for i in v'range loop
      re := Standard_Complex_Numbers.REAL_PART(v(i));
      res(ind) := Interfaces.C.double(re);
      ind := ind + 1;
      im := Standard_Complex_Numbers.IMAG_PART(v(i));
      res(ind) := Interfaces.C.double(im);
      ind := ind + 1;
    end loop;
    return res;
  end Convert;

  function Convert ( v : DoblDobl_Complex_Vectors.Vector )
                   return C_Double_Array is

    dim : constant integer32 := v'last;
    res : C_Double_Array(0..Interfaces.C.size_T(4*dim));
    ind : Interfaces.C.size_T := 0;
    re,im : double_double;
    use Interfaces.C;

  begin
    for i in v'range loop
      re := DoblDobl_Complex_Numbers.REAL_PART(v(i));
      res(ind) := Interfaces.C.double(hi_part(re)); ind := ind + 1;
      res(ind) := Interfaces.C.double(lo_part(re)); ind := ind + 1;
      im := DoblDobl_Complex_Numbers.IMAG_PART(v(i));
      res(ind) := Interfaces.C.double(hi_part(im)); ind := ind + 1;
      res(ind) := Interfaces.C.double(lo_part(im)); ind := ind + 1;
    end loop;
    return res;
  end Convert;

  function Convert ( v : QuadDobl_Complex_Vectors.Vector )
                   return C_Double_Array is

    dim : constant integer32 := v'last;
    res : C_Double_Array(0..Interfaces.C.size_T(8*dim));
    ind : Interfaces.C.size_T := 0;
    re,im : quad_double;
    use Interfaces.C;

  begin
    for i in v'range loop
      re := QuadDobl_Complex_Numbers.REAL_PART(v(i));
      res(ind) := Interfaces.C.double(hihi_part(re)); ind := ind + 1;
      res(ind) := Interfaces.C.double(lohi_part(re)); ind := ind + 1;
      res(ind) := Interfaces.C.double(hilo_part(re)); ind := ind + 1;
      res(ind) := Interfaces.C.double(lolo_part(re)); ind := ind + 1;
      im := QuadDobl_Complex_Numbers.IMAG_PART(v(i));
      res(ind) := Interfaces.C.double(hihi_part(im)); ind := ind + 1;
      res(ind) := Interfaces.C.double(lohi_part(im)); ind := ind + 1;
      res(ind) := Interfaces.C.double(hilo_part(im)); ind := ind + 1;
      res(ind) := Interfaces.C.double(lolo_part(im)); ind := ind + 1;
    end loop;
    return res;
  end Convert;

  function Convert ( m : Standard_Complex_Matrices.Matrix )
                   return C_Double_Array is

    len : constant integer32 := 2*m'length(1)*m'length(2);
    res : C_Double_Array(0..Interfaces.C.size_T(len-1));
    ind : Interfaces.C.size_T := 0;
    re,im : double_float;
    use Interfaces.C;

  begin
    for i in m'range(1) loop
      for j in m'range(2) loop
        re := Standard_Complex_Numbers.REAL_PART(m(i,j));
        res(ind) := Interfaces.C.double(re);
        ind := ind + 1;
        im := Standard_Complex_Numbers.IMAG_PART(m(i,j));
        res(ind) := Interfaces.C.double(im);
        ind := ind + 1;
      end loop;
    end loop;
    return res;
  end Convert;

end C_to_Ada_Arrays;