comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: Handling of unfriendly data structures
Date: Sun, 15 Sep 2002 20:26:04 GMT
Date: 2002-09-15T20:26:04+00:00	[thread overview]
Message-ID: <w16h9.330016$aA.57550@sccrnsc02> (raw)
In-Reply-To: cfbd115b.0209150548.75f52e4a@posting.google.com

> What would be the "Ada-way" to implement this, considering that
That depends somewhat on how to will want to access the data after
reading a block.  You seem to have declarations for part_? and
you could declare
  type string_access is access string;
  type block_type is new ada.finalization.limited_controlled with record
    a : part_a;
    a_text : string_access;
    b : part_b;
    b_text : string_access;
    ...
    y : part_y;
    y_text : string_access;
  end record;
  procedure read_a_block(block : out block_type);
private
  procedure finalize(block : in out block_type); -- free allocated ?_text's

If your program wants to access things sequentially, ie, the things in
a_part, then a_text, then the items in b_part, then b_text, etc, then you
might instead want to write a routine that reads a
part_a, doing endianness conversion as needed and returning a part_a to
its caller, and similar routines for part_b etc.  and finally a text
reader that uses its output size to read the right number of characters.
Using Ada.Streams, for instance, you could then write something like:
  part_a'read(stream, a);
  declare
    a_text : string(1 .. a.size);
  begin
    text'read(stream, a_text);
    -- process the part_a and a_text stuff
  end;
  part_b'read(stream, b);
  declare
    b_text : string(1 .. b.size);
  begin
    text'read(stream, b_text);
    -- process the part_b and b_text stuff
  end;
  ...



  reply	other threads:[~2002-09-15 20:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-15 13:48 Handling of unfriendly data structures L. Siever
2002-09-15 20:26 ` tmoran [this message]
2002-09-15 21:54 ` Nick Roberts
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox