comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@on2.com (Matthew Heaney)
Subject: Re: using charles library
Date: 27 May 2003 08:05:47 -0700
Date: 2003-05-27T15:05:48+00:00	[thread overview]
Message-ID: <1ec946d1.0305270705.7599a034@posting.google.com> (raw)
In-Reply-To: 3ED24C46.6080208@spam.com

Jeffrey Carter <spam@spam.com> wrote in message news:<3ED24C46.6080208@spam.com>...
> Roman V. Isaev wrote:
> > 
> >    I wonder is there any package easier to use? I only want two
> > functions, something like store(key,value) and lookup(key), that's
> > all, without 20+ string declaration voodoo... Grrrrr. I miss perl's
> > associative arrays.

Your problem is a consequence of the fact that the intended element
type, String, is indefinite.  Most container libraries in Ada
--including Charles-- require container elements to be definite, with
some kind of constraint.  That's why the generic formal type looks
like this:

generic
  type Element_Type is private;
package GP is ...;

Note that this is the case even for built-in array types: type String
cannot be an array component subtype directly.

Had you chosen a simpler type, as Integer or Float, then you would
have had fewer difficulties instantiating the component.

If you need to use type String as a container element, then you need
some kind of wrapper class, either Ada.Strings.Unbounded or
Charles.Strings.Unbounded, that is itself definite.

To store a key/element pair in the map, use Insert:

  Insert (Map, Key, Element);

That operation is overloaded to return an iterator that designates the
pair:

  Insert (Map, Key, Element, Iterator);

It's overloaded again to return a Success parameter, which allows the
insertion to be conditional (insert fails if key is already in the
map):

  Insert (Map, Key, Element, Iterator, Success);


To lookup a key/value pair, just use the Find operation:

procedure Op (Map : Map_Subtype) is
  I : Iterator_Type := Find (Map, Key);
begin
  if I /= Back (Map) then
    declare
      E : Element_Type := Element (I);
      --or E : Element_TYpe renames To_Access (I).all;
    begin
      ...
    end;
  end if;
end;

It wasn't clear from your original example why you were using
Ada.Strings.Unbounded, if you were using Charles.Strings.Unbounded as
the element type.

Drop me a line if any of this isn't clear.

Matt



  reply	other threads:[~2003-05-27 15:05 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-26 13:27 using charles library Roman V. Isaev
2003-05-26 13:40 ` Preben Randhol
2003-05-26 16:44   ` Roman V. Isaev
2003-05-26 17:05     ` Preben Randhol
2003-05-26 17:10       ` Preben Randhol
2003-05-26 22:05         ` Roman V. Isaev
2003-05-26 17:16     ` Jeffrey Carter
2003-05-27 15:05       ` Matthew Heaney [this message]
2003-05-27 18:28         ` Stephen Leake
2003-05-26 17:20     ` Preben Randhol
2003-05-26 22:46       ` Roman V. Isaev
2003-05-27  4:35         ` Gautier Write-only
2003-05-29 17:29           ` Roman V. Isaev
2003-05-29 18:56             ` Gautier Write-only
2003-05-29 23:19             ` Gautier Write-only
2003-05-30  7:56               ` Roman V. Isaev
2003-05-30 13:49                 ` Gautier
2003-05-30 14:36               ` Robert C. Leif
2003-05-30 17:32                 ` Preben Randhol
2003-05-30 19:21               ` Randy Brukardt
2003-05-31 11:50                 ` Gautier Write-only
2003-05-31 14:24                   ` Bill Findlay
2003-06-01  3:42                   ` Randy Brukardt
2003-06-02 11:02                   ` Georg Bauhaus
2003-06-02 20:25                     ` Gautier Write-only
2003-05-30  8:48             ` Preben Randhol
2003-05-27 10:31         ` Preben Randhol
2003-05-29 20:30           ` Roman V. Isaev
2003-05-30  9:01             ` Preben Randhol
2003-05-30 22:02               ` Roman V. Isaev
2003-05-31 13:34                 ` Preben Randhol
2003-05-27 18:27     ` Stephen Leake
2003-05-27 20:24 ` Matthew Heaney
replies disabled

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