comp.lang.ada
 help / color / mirror / Atom feed
* Access types to records containing strings
@ 2005-01-29  8:58 Stefan Merwitz
  2005-01-29  9:32 ` Martin Krischik
  2005-01-29 10:03 ` Dmitry A. Kazakov
  0 siblings, 2 replies; 6+ messages in thread
From: Stefan Merwitz @ 2005-01-29  8:58 UTC (permalink / raw)


Hello everybody,

it's me again. I need to implement a list containing strings using 
access types. Is there a way to implement this using variable length 
strings:

private type list;
private type listobject is record
     sContent: string(1..30);
     Next := list;
end record;
private type list is access listobject;

With the knowledge I have till now, I think it's only possible with 
fixed length strings. Am I right or is there any other way?


Thanks in advance,

Stefan



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Access types to records containing strings
  2005-01-29  8:58 Access types to records containing strings Stefan Merwitz
@ 2005-01-29  9:32 ` Martin Krischik
  2005-01-29 10:03 ` Dmitry A. Kazakov
  1 sibling, 0 replies; 6+ messages in thread
From: Martin Krischik @ 2005-01-29  9:32 UTC (permalink / raw)


Stefan Merwitz wrote:

> Hello everybody,
> 
> it's me again. I need to implement a list containing strings using
> access types. Is there a way to implement this using variable length
> strings:
> 
> private type list;
> private type listobject is record
>      sContent: string(1..30);
>      Next := list;
> end record;
> private type list is access listobject;
> 
> With the knowledge I have till now, I think it's only possible with
> fixed length strings.

Then you have not got very far in your textbook or lessons ;-) .

> Am I right or is there any other way? 

Two options are open:

1) Discriminanted_Record
   http://en.wikibooks.org/wiki/Programming:Ada:Types:record#Discriminanted_Record

2) Unbounded_Strings
   http://www.adaic.org/standards/95lrm/html/RM-A-4-5.html

Martin
-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Access types to records containing strings
  2005-01-29  8:58 Access types to records containing strings Stefan Merwitz
  2005-01-29  9:32 ` Martin Krischik
@ 2005-01-29 10:03 ` Dmitry A. Kazakov
  2005-02-15 12:17   ` Xavier Serrand
  1 sibling, 1 reply; 6+ messages in thread
From: Dmitry A. Kazakov @ 2005-01-29 10:03 UTC (permalink / raw)


On Sat, 29 Jan 2005 09:58:55 +0100, Stefan Merwitz wrote:

> it's me again. I need to implement a list containing strings using 
> access types. Is there a way to implement this using variable length 
> strings:
> 
> private type list;
> private type listobject is record
>      sContent: string(1..30);
>      Next := list;
> end record;
> private type list is access listobject;
> 
> With the knowledge I have till now, I think it's only possible with 
> fixed length strings. Am I right or is there any other way?

type List_Object;
type List is access List_Object;
type List_Object (Length : Natural) is record
   Content : String (1..Length);
   Next    : List;
end record;

or else

with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
...
type List_Object;
type List is access List_Object;
type List_Object is record
   Content : Unbounded_String;
   Next    : List;
end record;

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Access types to records containing strings
  2005-01-29 10:03 ` Dmitry A. Kazakov
@ 2005-02-15 12:17   ` Xavier Serrand
  2005-02-15 13:20     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 6+ messages in thread
From: Xavier Serrand @ 2005-02-15 12:17 UTC (permalink / raw)


Hello Dmitry,

Why no use pointer to string !!

type T_Ptr_String is access String;

And now your strings can have the length you want ... but you should
define function to construct your strings tha way (make something like
a class in a package and use it)

It should be as or more flexible than the unbounded strings...

Is it usefull?

Xavier

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message news:<8uvcyoh3nvbe$.fy9vv8opob1a.dlg@40tude.net>...
> On Sat, 29 Jan 2005 09:58:55 +0100, Stefan Merwitz wrote:
> 
> > it's me again. I need to implement a list containing strings using 
> > access types. Is there a way to implement this using variable length 
> > strings:
> > 
> > private type list;
> > private type listobject is record
> >      sContent: string(1..30);
> >      Next := list;
> > end record;
> > private type list is access listobject;
> > 
> > With the knowledge I have till now, I think it's only possible with 
> > fixed length strings. Am I right or is there any other way?
> 
> type List_Object;
> type List is access List_Object;
> type List_Object (Length : Natural) is record
>    Content : String (1..Length);
>    Next    : List;
> end record;
> 
> or else
> 
> with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
> ...
> type List_Object;
> type List is access List_Object;
> type List_Object is record
>    Content : Unbounded_String;
>    Next    : List;
> end record;



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Access types to records containing strings
  2005-02-15 12:17   ` Xavier Serrand
@ 2005-02-15 13:20     ` Dmitry A. Kazakov
  2005-02-15 16:18       ` Matthew Heaney
  0 siblings, 1 reply; 6+ messages in thread
From: Dmitry A. Kazakov @ 2005-02-15 13:20 UTC (permalink / raw)


On 15 Feb 2005 04:17:13 -0800, Xavier Serrand wrote:

> Why no use pointer to string !!

Pointers is the last resort choice in all cases...

> type T_Ptr_String is access String;
> 
> And now your strings can have the length you want ... but you should
> define function to construct your strings tha way (make something like
> a class in a package and use it)
> 
> It should be as or more flexible than the unbounded strings...

It is what unbounded strings already do. Additionally you will need to make
List_Object controlled (to control destruction), which might be
undesirable.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Access types to records containing strings
  2005-02-15 13:20     ` Dmitry A. Kazakov
@ 2005-02-15 16:18       ` Matthew Heaney
  0 siblings, 0 replies; 6+ messages in thread
From: Matthew Heaney @ 2005-02-15 16:18 UTC (permalink / raw)



Dmitry A. Kazakov wrote:
> On 15 Feb 2005 04:17:13 -0800, Xavier Serrand wrote:
>
> It is what unbounded strings already do. Additionally you will need
to make
> List_Object controlled (to control destruction), which might be
> undesirable.

In Ada 2005, you'll be able to put the strings on the indefinite list
standard container:

package String_Lists is
   new Ada.Containers.Indefinite_Doubly_Linked_Lists (String);

use String_Lists;

procedure Op (L : in out List) is
begin
   L.Append ("Hello, World");
   Replace_Element (Last (L), "Goodbye, World");
end;

No pointers required...

-Matt




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-02-15 16:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-29  8:58 Access types to records containing strings Stefan Merwitz
2005-01-29  9:32 ` Martin Krischik
2005-01-29 10:03 ` Dmitry A. Kazakov
2005-02-15 12:17   ` Xavier Serrand
2005-02-15 13:20     ` Dmitry A. Kazakov
2005-02-15 16:18       ` Matthew Heaney

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