From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,74d953d10520ed5e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-05-27 08:05:48 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: mheaney@on2.com (Matthew Heaney) Newsgroups: comp.lang.ada Subject: Re: using charles library Date: 27 May 2003 08:05:47 -0700 Organization: http://groups.google.com/ Message-ID: <1ec946d1.0305270705.7599a034@posting.google.com> References: <3ED24C46.6080208@spam.com> NNTP-Posting-Host: 66.162.65.162 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1054047948 13841 127.0.0.1 (27 May 2003 15:05:48 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 27 May 2003 15:05:48 GMT Xref: archiver1.google.com comp.lang.ada:37841 Date: 2003-05-27T15:05:48+00:00 List-Id: Jeffrey Carter 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