* Dynamic allocation of named arrays
@ 2008-04-29 9:12 Kim Rostgaard Christensen
2008-04-29 9:55 ` Thomas Locke
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Kim Rostgaard Christensen @ 2008-04-29 9:12 UTC (permalink / raw)
Hello
I need an array that has both variable length key and value (strings)
that is dynamically allocated at run-time.
I have looked at ada05's "Containers.Hashed_maps" but am missing a good
example on usage, and would like to use something more portable.
It is for loading a standard config file into memory.
Best
--
Kim Rostgaard Christensen
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Dynamic allocation of named arrays
2008-04-29 9:12 Dynamic allocation of named arrays Kim Rostgaard Christensen
@ 2008-04-29 9:55 ` Thomas Locke
2008-04-29 18:37 ` DScott
2008-04-29 19:38 ` Simon Wright
2008-04-29 20:14 ` Gautier
2 siblings, 1 reply; 6+ messages in thread
From: Thomas Locke @ 2008-04-29 9:55 UTC (permalink / raw)
Kim Rostgaard Christensen wrote:
> Hello
>
> I need an array that has both variable length key and value (strings)
> that is dynamically allocated at run-time.
>
> I have looked at ada05's "Containers.Hashed_maps" but am missing a good
> example on usage, and would like to use something more portable.
>
> It is for loading a standard config file into memory.
>
> Best
Hello Kim,
Maybe this will work:
http://www.rosettacode.org/wiki/Creating_an_Associative_Array#Ada
:o)
Thomas
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Dynamic allocation of named arrays
2008-04-29 9:55 ` Thomas Locke
@ 2008-04-29 18:37 ` DScott
0 siblings, 0 replies; 6+ messages in thread
From: DScott @ 2008-04-29 18:37 UTC (permalink / raw)
Thomas Locke wrote:
> Kim Rostgaard Christensen wrote:
>> Hello
>>
>> I need an array that has both variable length key and value (strings)
>> that is dynamically allocated at run-time.
>>
>> I have looked at ada05's "Containers.Hashed_maps" but am missing a good
>> example on usage, and would like to use something more portable.
>>
>> It is for loading a standard config file into memory.
>>
>> Best
>
> Hello Kim,
>
> Maybe this will work:
>
> http://www.rosettacode.org/wiki/Creating_an_Associative_Array#Ada
>
> :o)
> Thomas
What? Not advice_config.ads/adb? :)
--
Fui et vidi experiri.
=DSM=
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Dynamic allocation of named arrays
2008-04-29 9:12 Dynamic allocation of named arrays Kim Rostgaard Christensen
2008-04-29 9:55 ` Thomas Locke
@ 2008-04-29 19:38 ` Simon Wright
2008-04-29 20:14 ` Gautier
2 siblings, 0 replies; 6+ messages in thread
From: Simon Wright @ 2008-04-29 19:38 UTC (permalink / raw)
Kim Rostgaard Christensen <krc@greenpc.dk> writes:
> I have looked at ada05's "Containers.Hashed_maps" but am missing a
> good example on usage, and would like to use something more
> portable.
If you have an Ada (05) compiler it will almost certainly have
Containers -- what could be more portable than that?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Dynamic allocation of named arrays
2008-04-29 9:12 Dynamic allocation of named arrays Kim Rostgaard Christensen
2008-04-29 9:55 ` Thomas Locke
2008-04-29 19:38 ` Simon Wright
@ 2008-04-29 20:14 ` Gautier
2008-04-29 20:59 ` Gautier
2 siblings, 1 reply; 6+ messages in thread
From: Gautier @ 2008-04-29 20:14 UTC (permalink / raw)
Kim Rostgaard Christensen wrote:
> Hello
>
> I need an array that has both variable length key and value (strings)
> that is dynamically allocated at run-time.
>
> I have looked at ada05's "Containers.Hashed_maps" but am missing a good
> example on usage
with Ada.Strings.Unbounded.Hash;
...
package Dictionaries is new Ada.Containers.Hashed_Maps
(Ada.Strings.Unbounded.Unbounded_String,
Ada.Strings.Unbounded.Unbounded_String,
Ada.Strings.Unbounded.Hash,
equivalent_keys => Ada.Strings.Unbounded."=");
For a full example, search "Texture_Name_Mapping" in:
http://globe3d.svn.sourceforge.net/viewvc/globe3d/src/globe_3d-textures.adb?revision=78&view=markup
> , and would like to use something more portable.
Well, how can it be more portable ?!...
Do you mean with some Ada 95 compilers ?
______________________________________________________________
Gautier -- http://www.mysunrise.ch/users/gdm/index.htm
Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm
NB: For a direct answer, e-mail address on the Web site!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Dynamic allocation of named arrays
2008-04-29 20:14 ` Gautier
@ 2008-04-29 20:59 ` Gautier
0 siblings, 0 replies; 6+ messages in thread
From: Gautier @ 2008-04-29 20:59 UTC (permalink / raw)
Mmmmh - always better to test examples before posting...
This one is working:
-----8<-----------8<-----------8<-----------8<------
with Ada.Containers.Hashed_Maps;
with Ada.Strings.Unbounded.Hash;
with Ada.Text_IO;
procedure Dummy_dico is
package Dictionaries is new Ada.Containers.Hashed_Maps
(Ada.Strings.Unbounded.Unbounded_String,
Ada.Strings.Unbounded.Unbounded_String,
Ada.Strings.Unbounded.Hash,
Ada.Strings.Unbounded."=",
Ada.Strings.Unbounded."=");
use Dictionaries;
function "-" (Source : Ada.Strings.Unbounded.Unbounded_String) return String
renames Ada.Strings.Unbounded.To_String;
function "+" (Source : String) return Ada.Strings.Unbounded.Unbounded_String
renames Ada.Strings.Unbounded.To_Unbounded_String;
procedure Translate( dico: Map; from: String ) is
use Ada.Text_IO;
begin
Put_Line( from & " ---> " & (-Element(dico,+from)) );
end Translate;
dico_F_to_E: Map;
c: Cursor;
s: Boolean;
begin
Insert(dico_F_to_E, +"souris", +"mouse", c, s);
Insert(dico_F_to_E, +"chat", +"cat", c, s);
Insert(dico_F_to_E, +"chien", +"dog", c, s);
Insert(dico_F_to_E, +"cheval", +"horse", c, s);
--
Translate(dico_F_to_E, "chien");
Translate(dico_F_to_E, "chat");
end;
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-04-29 20:59 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-29 9:12 Dynamic allocation of named arrays Kim Rostgaard Christensen
2008-04-29 9:55 ` Thomas Locke
2008-04-29 18:37 ` DScott
2008-04-29 19:38 ` Simon Wright
2008-04-29 20:14 ` Gautier
2008-04-29 20:59 ` Gautier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox