comp.lang.ada
 help / color / mirror / Atom feed
* RE: Using renaming declarations to make private subprograms visib le
@ 2001-08-28 20:19 Beard, Frank
  2001-08-28 22:42 ` Matthew Woodcraft
  0 siblings, 1 reply; 4+ messages in thread
From: Beard, Frank @ 2001-08-28 20:19 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'

Matthew,

Have you tried fully qualified names, such as:

private

   type Token_Type is new Ada.Strings.Unbounded.Unbounded_String;

   function To_Token (Source : String) return Token_Type
     renames Ada.Strings.Unbounded.To_Unbounded_String;

   function To_String (Source : Token_Type) return String
     renames Ada.Strings.Unbounded.To_String;

   [...]

Frank

-----Original Message-----
From: Matthew Woodcraft [mailto:mattheww@chiark.greenend.org.uk]
Sent: Saturday, August 25, 2001 9:14 AM
To: comp.lang.ada@ada.eu.org
Subject: Using renaming declarations to make private subprograms visible



Suppose I want a private type that I can convert to a string and back:


package Foo is

   type Token_Type is private;

   function To_Token (Source : String) return Token_Type;

   function To_String (Source : Token_Type) return String;

   [...]

private

   [...]	

end Foo;



Now suppose that (for the moment), I want to implement this type using
an unbounded string. I can make Token_Type a derived type of
Unbounded_String, and use renaming declarations to make some of the
'inherited' subprograms publicly visible:

private

   type Token_Type is new Ada.Strings.Unbounded.Unbounded_String;

   function To_Token (Source : String) return Token_Type
     renames To_Unbounded_String;

    -- No good
   function To_String (Source : Token_Type) return String
     renames To_String;

   [...]


The trouble is, this doesn't work when I want the public name of a
subprogram to be the same as the private name (eg, To_String above), as
my new definition overrides the inherited one, and I end up trying
renaming the function to itself.

Is there any way to make the inherited subprogram publicly visible with
the same name? Or am I better off making Token_Type a record with one
component, rather than a derived type?


-M-
_______________________________________________
comp.lang.ada mailing list
comp.lang.ada@ada.eu.org
http://ada.eu.org/mailman/listinfo/comp.lang.ada



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

* Re: Using renaming declarations to make private subprograms visib le
  2001-08-28 20:19 Using renaming declarations to make private subprograms visib le Beard, Frank
@ 2001-08-28 22:42 ` Matthew Woodcraft
  2001-08-29  4:18   ` DuckE
  0 siblings, 1 reply; 4+ messages in thread
From: Matthew Woodcraft @ 2001-08-28 22:42 UTC (permalink / raw)


"Beard, Frank" <beardf@spawar.navy.mil> writes:

> Matthew,
> 
> Have you tried fully qualified names, such as:
> 
> private
> 
>    type Token_Type is new Ada.Strings.Unbounded.Unbounded_String;
> 
>    function To_Token (Source : String) return Token_Type
>      renames Ada.Strings.Unbounded.To_Unbounded_String;
> 
>    function To_String (Source : Token_Type) return String
>      renames Ada.Strings.Unbounded.To_String;

But Ada.String.Unbounded.To_String is a function which return an
Ada.Strings.Unbounded.Unbounded_String. The function which I want to
make visible is its implicitly-defined cousin, which returns a Token.

-M-




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

* Re: Using renaming declarations to make private subprograms visib le
  2001-08-28 22:42 ` Matthew Woodcraft
@ 2001-08-29  4:18   ` DuckE
  0 siblings, 0 replies; 4+ messages in thread
From: DuckE @ 2001-08-29  4:18 UTC (permalink / raw)


Do you have a problem with creating a body for the package to do the
conversion?

with Ada.Strings.Unbounded;

package tokens is

  type Token_Type is private;

  function To_Token(Source: String) return Token_Type;
  pragma Inline( To_Token );

private
  type Token_Type is new Ada.Strings.Unbounded.Unbounded_String;
end;

package body tokens is

   function To_Token (Source: String) return Token_Type is
   begin
      return Token_Type(
Ada.Strings.Unbounded.To_Unbounded_String(Source) );
   end To_Token;

end tokens;

It may be a little verbose, but should work just fine (I didn't run it to
verify, but it compiles).

SteveD

"Matthew Woodcraft" <mattheww@chiark.greenend.org.uk> wrote in message
news:878zg3vma6.fsf@chiark.greenend.org.uk...
> "Beard, Frank" <beardf@spawar.navy.mil> writes:
>
> > Matthew,
> >
> > Have you tried fully qualified names, such as:
> >
> > private
> >
> >    type Token_Type is new Ada.Strings.Unbounded.Unbounded_String;
> >
> >    function To_Token (Source : String) return Token_Type
> >      renames Ada.Strings.Unbounded.To_Unbounded_String;
> >
> >    function To_String (Source : Token_Type) return String
> >      renames Ada.Strings.Unbounded.To_String;
>
> But Ada.String.Unbounded.To_String is a function which return an
> Ada.Strings.Unbounded.Unbounded_String. The function which I want to
> make visible is its implicitly-defined cousin, which returns a Token.
>
> -M-
>





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

* RE: Using renaming declarations to make private subprograms visib le
@ 2001-08-29 17:26 Beard, Frank
  0 siblings, 0 replies; 4+ messages in thread
From: Beard, Frank @ 2001-08-29 17:26 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'

-----Original Message-----
From: Matthew Woodcraft [mailto:mattheww@chiark.greenend.org.uk]

> Matthew,
> But Ada.String.Unbounded.To_String is a function which return an
> Ada.Strings.Unbounded.Unbounded_String. The function which I want to
> make visible is its implicitly-defined cousin, which returns a Token.

You're right.  I don't know what I was thinking.  I think the only
"quick" way, short of Steve's perfectly reasonable option, it to
do the following:

with Ada.Strings.Unbounded;

package Foo is

   type Token_Type is private;

   function To_Token (Source : String) return Token_Type;

 --function To_String (Source : Token_Type) return String;
   function To_Token_String (Source : Token_Type) return String;

private

   type Token_Type is new Ada.Strings.Unbounded.Unbounded_String;

   function To_Token (Source : String) return Token_Type
     renames To_Unbounded_String;

-- function To_String (Source : Token_Type) return String
--   renames To_String;
   function To_Token_String (Source : Token_Type) return String
     renames To_String;

end Foo;

Frank



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

end of thread, other threads:[~2001-08-29 17:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-28 20:19 Using renaming declarations to make private subprograms visib le Beard, Frank
2001-08-28 22:42 ` Matthew Woodcraft
2001-08-29  4:18   ` DuckE
  -- strict thread matches above, loose matches on Subject: below --
2001-08-29 17:26 Beard, Frank

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