ファイルから入力を読み取って使用しようとするときの方法'Size
と動作について、私はかなり混乱しています。ソースとターゲットの両方をうまく使用するには、同じである必要があることを私は知っています。次のようなファイルから入力を読み込んでおり、未チェックの変換を使用してそれをビットの配列に入れたいと考えています。ただし、サイズが同じでないか小さすぎるため、変換は常に失敗するようです。'Component_Size
Unchecked_Conversion
Unchecked_Conversion
size
000100000101001
with Ada.Unchecked_Conversion;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure main is
type Bit is mod 2 with size => 1;
type Bit_Array is array(Positive range <>) of Bit with pack;
subtype Bit15 is Bit_Array(1 .. 15); //subtypes because can't use conversion on unconstrainted type
subtype Bit11 is Bit_Array(1 .. 11);
function StringA_to_Bit15 is
new Ada.Unchecked_Conversion(source => String, target => Bit15);
begin
while not end_of_file loop
declare
s: String := get_line; //holding first line of input
len: constant Natural := (if s'length-3 = 15
then 15
else 11);
i: Integer;
ba: Bit_Array(1 .. len); //constrain a Bit_Array based on length of input
begin
ba := String_to_Bit15(s);
new_line;
end;
end loop;
size
これが私のタイプです。ビットは0または1で、1ビットまでしかありません。Bit_Array は、入力が 15 ビット長または 11 ビット長のいずれかになる可能性があるため、制約のないビットの単なる配列です。私の考えは、最初の行を文字列に読み込み、それを Bit_Array に変換することでした。String およびその他のすべてのプリミティブ型は ではないため、これは機能しませんSize => 1
。したがって、当然のことながら、これを処理する新しい型を作成して、独自の文字列型を作成し、size => 1
文字には 8 ビットが必要です。データ行を読み取り、Bit_Array に収まるように変換するには、どのデータ型を作成する必要がありますか? 私はこれに間違って近づいているかもしれませんが、私にとっては非常に混乱しています。ヘルプやヒントをいただければ幸いです。