comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: array
Date: 13 Apr 2001 08:09:31 +0100
Date: 2001-04-13T07:09:31+00:00	[thread overview]
Message-ID: <x7vitk9wa1g.fsf@smaug.pushface.org> (raw)
In-Reply-To: 5s2B6.32267$ii5.3236241@afrodite.telenet-ops.be

"Pieter Thysebaert" <pieter.thysebaert@pandora.be> writes:

> I've somehow been able to construct a binary tree (using nodes and
> access types etc.)
> 
> Now I was looking for a function that would allow me to convert the
> contents of a tree into an array (and vice versa) I've found
> something like arrays with variable range (I mean not fixed at
> compile-time) Well I think that's what I found - does that thing
> exist ?
> 
> And if it does, how would one manipulate it (add/remove elements)

It's certainly possible to work with unconstrained array types, you
just need to be aware that the size of an instance of such a type is
*not* variable; it can be fixed at initialization, though:

  type A is array (Integer range <>) of Integer;

  function Fun return A is
    Result : A (12 .. 34) := (others => 42);
  begin
    -- stuff
    return Result;
  end Fun;

  V : A := Fun;

> Or are there data structures like C++ STL stuff (vector etc)
> available ?

The 20010325 release of the Booch Components contains a generic Copy
feature:

  with Bc.Containers;
  generic
    type Item is private;
    with package Source is new BC.Containers (Item);
    type From is new Source.Container with private;
    with package Target is new BC.Containers (Item);
    type To is new Target.Container with private;
    with procedure Clear (The_Container : in out To) is <>;
    with procedure Add (To_The_Container : in out To; I : Item) is <>;
  procedure BC.Copy (Input : From; Output : in out To);

Basically, you have a Source.From container type and a Target.To
container type (clearly both containing the same sort of Item!).  You
need a procedure to Clear the Target.To container, and a procedure
to Add Items to the Target.To container.

  procedure BC.Copy (Input : From; Output : in out To) is
    procedure Ins (I : Item; OK : out Boolean);
    pragma Inline (Ins);
    procedure Cp is new Source.Visit (Ins);
    procedure Ins (I : Item; OK : out Boolean) is
    begin
      Add (Output, I);
      OK := True;
    end Ins;
    It : Source.Iterator'Class := New_Iterator (Input);
  begin
    Clear (Output);
    Cp (It);
  end BC.Copy;

The implementation Clears the the Target.To container and then
iterates over the Source.From container, Adding each Item as it goes.

-Simon



  parent reply	other threads:[~2001-04-13  7:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-11 19:41 array Pieter Thysebaert
2001-04-12 14:59 ` array Ted Dennison
2001-04-12 18:59   ` array Des Walker
2001-04-12 18:51 ` array Stephen Leake
2001-04-12 21:05 ` array Jeffrey Carter
2001-04-13  7:09 ` Simon Wright [this message]
  -- strict thread matches above, loose matches on Subject: below --
1998-04-15  0:00 Array BanaN
1998-04-17  0:00 ` Array BanaN
replies disabled

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