comp.lang.ada
 help / color / mirror / Atom feed
From: Brad Moore <brad.moore@shaw.ca>
Subject: Re: String_Holder ?
Date: Sun, 18 Dec 2011 09:48:05 -0700
Date: 2011-12-18T09:48:05-07:00	[thread overview]
Message-ID: <cPoHq.25395$%O.10375@newsfe20.iad> (raw)
In-Reply-To: <slrnjerndj.1lme.lithiumcat@sigil.instinctive.eu>

On 18/12/2011 5:34 AM, Natasha Kerensikova wrote:
> Hello,
>
> in my few Ada projects so far, I have quite often encountered the need
> of storing a string along with other information in records. So I went
> for discriminants containing the string size, and putting the string
> directly in the record.
>
> This works well when there is only one or two strings, but with several
> of them, or in variant records, I find it quite heavy. So I was thinking
> about something like that:
>
>
> type String_Holder is still to be defined;
>
> function Hold (S : String) return String_Holder;
>
> function To_String (Holder : String_Holder) return String;
>
> procedure Query (Holder : String_Holder;
>                   Process : not null access procedure (S : String));
>
>
> I'm still unsure on what kind of type String_Holder should be (private,
> tagged private or interface). It would basically be a constant-size
> reference to an immutable string that is stored "somewhere".
>
> The simplest implementation would be an Unbounded_String, though if
> needed it could be improved reference counting to make assignments
> cheaper, or with a hash table to deduplicate identical strings, etc.
>
> So my question is, does it make sense to have such objects? Or am I
> getting blinded by my C past, where strings are always manipulated
> through a char* object?

Ada 2012 is in fact introducing a generic holder container.
You may want to have a look at;

http://www.ada-auth.org/standards/12rm/html/RM-A-18-18.html

>
> Assuming it does make sense, am I right in thinking it's better to have
> such a type, even if it's a thin wrapper around Unbounded_String,
> instead of using directly Unbounded_String?
>
> Assuming it does make sense to have a String_Holder, would it be better
> to have it private, tagged private or interface?

tagged private would allow more flexibility over private, since you can
extend the type to suit other purposes. Interfaces cannot have any 
components, and if you are thinking of a specific implementation such as
wrapping the unbounded string, then probably tagged private better
suits your needs since you can define the holder object to contain an
unbounded string object.


> And lastly, is there any trick to allow a String_Holder object or
> similar to be pre-elaborable?


The proposed holder container is a Remote_Types package which by
definition is preelaborable.

There shouldn't need to be any tricks. Ada.Strings.Unbounded has pragma 
Preelaborate. You should be able to do the same with your holder 
package, so long as that package does not "with" other packages that are
not preelaborable, and your package satisfies the rules for a 
preelaborated package.

Brad



  reply	other threads:[~2011-12-18 16:48 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-18 12:34 String_Holder ? Natasha Kerensikova
2011-12-18 16:48 ` Brad Moore [this message]
2011-12-18 20:55 ` Jeffrey Carter
2011-12-18 23:08   ` Natasha Kerensikova
2011-12-19 12:14     ` Niklas Holsti
2011-12-19 11:12 ` Martin
2011-12-19 23:53 ` Randy Brukardt
2011-12-22  9:08   ` Natasha Kerensikova
2011-12-22 10:08     ` Niklas Holsti
2011-12-22 12:23       ` Simon Wright
2011-12-23  1:26       ` Randy Brukardt
2011-12-23  6:18         ` Jeffrey Carter
2011-12-22 11:40     ` AdaMagica
replies disabled

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