comp.lang.ada
 help / color / mirror / Atom feed
* problem with abstract types
@ 2002-10-31 12:06 Ulrich Eckhardt
  2002-10-31 13:15 ` John English
                   ` (3 more replies)
  0 siblings, 4 replies; 30+ messages in thread
From: Ulrich Eckhardt @ 2002-10-31 12:06 UTC (permalink / raw)


Hi,

i am starting my first project in ada (A complete rewrite
of WHFC, see my Homepage). For this i want to
write an OS independend way to store configuration
informations (on windows in the registry and on unix in
human readable config files).

Therefore my idea was to created a package registry wich defines
an abstract type registry and several abstract functions
and (at this time) one real function .

package registry is
   type registry is abstract tagged limited private;
   type registry_Access is access all registry'Class;

   procedure openRegistry(reg : in out registry; ..) is abstract;
   function getRegistry( .. ) return registry_Access
   [..]

Also i have created a child package registry.unix,
which implements the abstract functions for using on
unix:

  package registry.unix is
     type file_registry is new registry with private;
     procedure openRegistry(reg : in out file_registry; ..);  	
     [..]

Also i will create a package registry.win which does the
same for windows.
package registry.win is
     type win_registry is new registry with private;
     procedure openRegistry(reg : in out win_registry; ..);

The function getRegistry of the main package should return
and initialize now depending on the os a package registry.win
or registry.unix, since for the use of this package it
should not be visible on which platform it was compiled.

function getRegistry (a : in sys_access; p_name : in Unbounded_String)
   return registry_Access is
   r : registry_Access;
   begin
     if compiled = SYS_UNIX then
        r := new file_registry(s_access => a);
     else
        r := new win_registry();
     end if;
     return r;
end getRegistry;

So in a testprogramm i use :

with registry; use registry;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

procedure main is
    reg : registry_Access;
    err : r_error;
begin
    reg := getRegistry(CLASS_USER,To_Unbounded_String("registrytest"));
    openRegistry(reg'access,err);
end main;

But when compiling this code i get a
main.adb:10:20: prefix of "access" attribute must be aliased

Any hints what i am missing, or comments how such things are better
done in ada?

Uli
-- 
Ulrich Eckhardt
http://www.uli-eckhardt.de




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

* Re: problem with abstract types
  2002-10-31 12:06 problem with abstract types Ulrich Eckhardt
@ 2002-10-31 13:15 ` John English
  2002-10-31 14:43   ` Ulrich Eckhardt
  2002-10-31 13:32 ` David C. Hoos
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 30+ messages in thread
From: John English @ 2002-10-31 13:15 UTC (permalink / raw)


Ulrich Eckhardt wrote:
> 
> procedure main is
>     reg : registry_Access;
>     err : r_error;
> begin
>     reg := getRegistry(CLASS_USER,To_Unbounded_String("registrytest"));
>     openRegistry(reg'access,err);
> end main;
> 
> But when compiling this code i get a
> main.adb:10:20: prefix of "access" attribute must be aliased

Reg is already an access value; you don't need to use 'Access
at all here. I think you'll find that this works:
    openRegistry(reg,err);

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------



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

* Re: problem with abstract types
  2002-10-31 12:06 problem with abstract types Ulrich Eckhardt
  2002-10-31 13:15 ` John English
@ 2002-10-31 13:32 ` David C. Hoos
  2002-10-31 13:47   ` problem with posters Peter Hermann
  2002-10-31 14:35   ` problem with abstract types Ulrich Eckhardt
  2002-10-31 15:31 ` Simon Wright
  2002-10-31 17:22 ` Stephen Leake
  3 siblings, 2 replies; 30+ messages in thread
From: David C. Hoos @ 2002-10-31 13:32 UTC (permalink / raw)



----- Original Message ----- 
From: "Ulrich Eckhardt" <uli.e@gmx.de>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: Thursday, October 31, 2002 6:06 AM
Subject: problem with abstract types


> Hi,
> 
> i am starting my first project in ada (A complete rewrite
> of WHFC, see my Homepage). For this i want to
> write an OS independend way to store configuration
> informations (on windows in the registry and on unix in
> human readable config files).
> 
> Therefore my idea was to created a package registry wich defines
> an abstract type registry and several abstract functions
> and (at this time) one real function .
> 
> package registry is
>    type registry is abstract tagged limited private;
>    type registry_Access is access all registry'Class;
> 
>    procedure openRegistry(reg : in out registry; ..) is abstract;
>    function getRegistry( .. ) return registry_Access
>    [..]
> 
> Also i have created a child package registry.unix,
> which implements the abstract functions for using on
> unix:
> 
>   package registry.unix is
>      type file_registry is new registry with private;
>      procedure openRegistry(reg : in out file_registry; ..);  
>      [..]
> 
> Also i will create a package registry.win which does the
> same for windows.
> package registry.win is
>      type win_registry is new registry with private;
>      procedure openRegistry(reg : in out win_registry; ..);
> 
> The function getRegistry of the main package should return
> and initialize now depending on the os a package registry.win
> or registry.unix, since for the use of this package it
> should not be visible on which platform it was compiled.
> 
> function getRegistry (a : in sys_access; p_name : in Unbounded_String)
>    return registry_Access is
>    r : registry_Access;
>    begin
>      if compiled = SYS_UNIX then
>         r := new file_registry(s_access => a);
>      else
>         r := new win_registry();
>      end if;
>      return r;
> end getRegistry;
> 
> So in a testprogramm i use :
> 
> with registry; use registry;
> with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
> 
> procedure main is
>     reg : registry_Access;
>     err : r_error;
> begin
>     reg := getRegistry(CLASS_USER,To_Unbounded_String("registrytest"));
>     openRegistry(reg'access,err);
> end main;
> 
> But when compiling this code i get a
> main.adb:10:20: prefix of "access" attribute must be aliased
> 
> Any hints what i am missing, or comments how such things are better
> done in ada?
This problem has nothing to do with abstract types. The error message means
exactly what it says.  So, what is the prefix of the "access" attribute?
It's "reg" so, "reg" must be aliased.

This the declaration of "reg" should be
reg : aliased registry_Access;
This will fix the compiler's complaint.

All of that being said, the bigger question is "why do you want to take the
"access" attribute of an access value?






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

* Re: problem with posters
  2002-10-31 13:32 ` David C. Hoos
@ 2002-10-31 13:47   ` Peter Hermann
  2002-10-31 14:15     ` Preben Randhol
  2002-10-31 14:35   ` problem with abstract types Ulrich Eckhardt
  1 sibling, 1 reply; 30+ messages in thread
From: Peter Hermann @ 2002-10-31 13:47 UTC (permalink / raw)


97% repeating the preposter / 3% of reply => not a good ratio, IMHO

-- 
--Peter Hermann(49)0711-685-3611 fax3758 ica2ph@csv.ica.uni-stuttgart.de
--Pfaffenwaldring 27 Raum 114, D-70569 Stuttgart Uni Computeranwendungen
--http://www.csv.ica.uni-stuttgart.de/homes/ph/
--Team Ada: "C'mon people let the world begin" (Paul McCartney)



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

* Re: problem with posters
  2002-10-31 13:47   ` problem with posters Peter Hermann
@ 2002-10-31 14:15     ` Preben Randhol
  0 siblings, 0 replies; 30+ messages in thread
From: Preben Randhol @ 2002-10-31 14:15 UTC (permalink / raw)


Peter Hermann wrote:
> 97% repeating the preposter / 3% of reply => not a good ratio, IMHO

Yesi, it would be nice if people could cut a bit more in the text they
reply to.

Regards,
Preben
-- 
Ada95 in the morning, Ada95 in the evening.



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

* Re: problem with abstract types
  2002-10-31 13:32 ` David C. Hoos
  2002-10-31 13:47   ` problem with posters Peter Hermann
@ 2002-10-31 14:35   ` Ulrich Eckhardt
  2002-11-01  8:31     ` Dmitry A.Kazakov
  1 sibling, 1 reply; 30+ messages in thread
From: Ulrich Eckhardt @ 2002-10-31 14:35 UTC (permalink / raw)


David C. Hoos wrote:

>>package registry is
>>   type registry is abstract tagged limited private;
>>   type registry_Access is access all registry'Class;
>>
>>   procedure openRegistry(reg : in out registry; ..) is abstract;
>>   function getRegistry( .. ) return registry_Access
>>   [..]

>>  package registry.unix is
>>     type file_registry is new registry with private;
>>     procedure openRegistry(reg : in out file_registry; ..);  
>>     [..]
>>
>>Any hints what i am missing, or comments how such things are better
>>done in ada?
> 
> This problem has nothing to do with abstract types. The error message means
> exactly what it says.  So, what is the prefix of the "access" attribute?
> It's "reg" so, "reg" must be aliased.

Yes and no ;-). The above fixes the compiler error, but not my
problem.

> All of that being said, the bigger question is "why do you want to take the
> "access" attribute of an access value?

Thats exact my problem. I have no idea how to do it a better way.
I use the package registry as some sort of interface, which sould
make sure that for every instance a set of functions are declared.

But i can not or don't know how to declare an abstract type
and assign later on a real type which is derived from this type.
For example on java i can create an abstract type and also declare
a variable of an abstract type. Later on the programm i can then
instantiate a real type an assign it to this variable. Thats what i
now want to do in java.

Uli
-- 
Ulrich Eckhardt
http://www.uli-eckhardt.de




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

* Re: problem with abstract types
  2002-10-31 13:15 ` John English
@ 2002-10-31 14:43   ` Ulrich Eckhardt
  2002-10-31 17:18     ` Robert I. Eachus
  0 siblings, 1 reply; 30+ messages in thread
From: Ulrich Eckhardt @ 2002-10-31 14:43 UTC (permalink / raw)


John English wrote:
> Ulrich Eckhardt wrote:
> 
>>procedure main is
>>    reg : registry_Access;
>>    err : r_error;
>>begin
>>    reg := getRegistry(CLASS_USER,To_Unbounded_String("registrytest"));
>>    openRegistry(reg'access,err);

> Reg is already an access value; you don't need to use 'Access
> at all here. I think you'll find that this works:
>     openRegistry(reg,err);
> 
No. openRegistry is first defined abstract and then implemented
as openRegistry(reg : in out file_registry; ..) and
openRegistry(reg : in out win_registry; ..) .

getRegistry should instantiate a class of file_registry or
win_registry depending on the Operation System and returns
this to the main programm. Within the main programm now
the correct instances of openRegistry should be choosen, so
that the current used implementation is not visible.
So the programmer which uses the registry package shouldnt't
care (and shouldn't see) whats behind the scene.

Uli
-- 
Ulrich Eckhardt
http://www.uli-eckhardt.de




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

* Re: problem with abstract types
  2002-10-31 12:06 problem with abstract types Ulrich Eckhardt
  2002-10-31 13:15 ` John English
  2002-10-31 13:32 ` David C. Hoos
@ 2002-10-31 15:31 ` Simon Wright
  2002-10-31 17:22 ` Stephen Leake
  3 siblings, 0 replies; 30+ messages in thread
From: Simon Wright @ 2002-10-31 15:31 UTC (permalink / raw)


Ulrich Eckhardt <uli.e@gmx.de> writes:

> package registry is
>    type registry is abstract tagged limited private;
>    type registry_Access is access all registry'Class;
> 
>    procedure openRegistry(reg : in out registry; ..) is abstract;
>    function getRegistry( .. ) return registry_Access
>    [..]

[...]

> with registry; use registry;
> with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
> 
> procedure main is
>     reg : registry_Access;
>     err : r_error;
> begin
>     reg := getRegistry(CLASS_USER,To_Unbounded_String("registrytest"));
>     openRegistry(reg'access,err);
> end main;
> 
> But when compiling this code i get a
> main.adb:10:20: prefix of "access" attribute must be aliased

reg'access is an access-to-registryAccess, while openRegistry requires
a registry, not an access-to-registryAccess or even a registryAccess,
so your call should have read

   openRegistry (reg.all, err);

Some people would declare your openRegistry as (pardon my Ada-isation
of your naming conventions):

   procedure Open (Reg : access Registry; ...);

in which case you could have said

   Registry.Open (Reg);

Passing a parameter called err to openRegistry implies you aren't
thinking of using exceptions, this is one place where you definitely
should.

It seems needlessly painful for users to make them use unbounded
strings in the getRegistry call, a plain string would be much easier.



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

* Re: problem with abstract types
  2002-10-31 14:43   ` Ulrich Eckhardt
@ 2002-10-31 17:18     ` Robert I. Eachus
  2002-10-31 18:20       ` Jeffrey Carter
  2002-11-01 10:57       ` Ulrich Eckhardt
  0 siblings, 2 replies; 30+ messages in thread
From: Robert I. Eachus @ 2002-10-31 17:18 UTC (permalink / raw)



Ulrich Eckhardt wrote:

> No. openRegistry is first defined abstract and then implemented
> as openRegistry(reg : in out file_registry; ..) and
> openRegistry(reg : in out win_registry; ..) .

Error, C++ thinking detected.  In Ada, unless you really have use them 
for some reason, avoid access types.  Access types IMHO, should be 
buried in packages which implement container abstractions and never show 
up in package specifications or user code.

If you change your specification to:

package registry is
   type registry is abstract tagged limited private;

   function openRegistry(Priviledge: in Sys_Access
                         Registry_Name: String)
   return registry is abstract;
   [..]
   exception Registry_Error; -- if you must.
end Registry;

In the two (or more!) child packages:

   function openRegistry (a      : in sys_access;
                         p_name : String)
       return file_registry is  --change as necessary.
     Reg: file_registry;
   begin
     -- any non-default actions here...
     return Reg;
   end fileRegistry;

Then your test program becomes:

  with registry; use registry;
  procedure main is
    declare
      reg := openRegistry(CLASS_USER,"registrytest");
    begin
      null; -- for now.
    exception
      when Registry_Error => -- do something useful like printing
                             -- location.
      when others => -- be prepared for anything in a test program...
    end;
  exception
    when others => -- catch finalization bugs here.
  end main;

Now you might think that Reg is declared inside a function and that it 
will either need to be declared on the heap, or copied during the 
return.  LET THE COMPILER WORRY ABOUT ALL THAT.  In practice the 
compiler will probably build the return value in place if it can inline 
openRegistry.  But it is not your problem, and a lot of unnecessary code 
goes away.

Also you will note that I got rid of any need for Unbounded_String.  It 
may be that some of the individual implementations of openRegistry will 
need to use Unbounded_String, but if the name never changes, you 
probably won't.  In any case, make things easy for the user of the 
abstraction.  In this case it also makes it easier for the implementor.





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

* Re: problem with abstract types
  2002-10-31 12:06 problem with abstract types Ulrich Eckhardt
                   ` (2 preceding siblings ...)
  2002-10-31 15:31 ` Simon Wright
@ 2002-10-31 17:22 ` Stephen Leake
  2002-11-01 10:25   ` Ulrich Eckhardt
  2002-11-01 11:15   ` Preben Randhol
  3 siblings, 2 replies; 30+ messages in thread
From: Stephen Leake @ 2002-10-31 17:22 UTC (permalink / raw)


Ulrich Eckhardt <uli.e@gmx.de> writes:

> Hi,
> 
> i am starting my first project in ada (A complete rewrite
> of WHFC, see my Homepage). For this i want to
> write an OS independend way to store configuration
> informations (on windows in the registry and on unix in
> human readable config files).

I am hurt, shocked, and amazed that noone has pointed you to Grace, at
http://savannah.nongnu.org/projects/grace/

It currently has a draft version of the Config_Files package, which
does exactly what you want, and was discussed extensively last spring.

Unfortunately, the administration of the Grace web site is a bit
lacking (hint to Ted Dennison :), so the easiest way to get the
Config_Files package is by browsing the CVS repository, at:

http://savannah.nongnu.org/cgi-bin/viewcvs/grace/grace/

and the documentation for Config_Files is only available as TeXinfo
source, at:

http://savannah.nongnu.org/cgi-bin/viewcvs/grace/doc/

I hope to make this cleaner soon.

Let me know if Grace.Config_Files meets your needs.

-- 
-- Stephe



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

* Re: problem with abstract types
  2002-10-31 17:18     ` Robert I. Eachus
@ 2002-10-31 18:20       ` Jeffrey Carter
  2002-10-31 20:58         ` Robert I. Eachus
  2002-11-01 10:57       ` Ulrich Eckhardt
  1 sibling, 1 reply; 30+ messages in thread
From: Jeffrey Carter @ 2002-10-31 18:20 UTC (permalink / raw)


I think this problem has already been solved. Do a search of c.l.a on 
Google groups. Of course, maybe you're doing this as a learning 
experience, and so don't want to reuse an existing library, but if not ...

Robert I. Eachus wrote:
> 
>    declare
>      reg := openRegistry(CLASS_USER,"registrytest");
>    begin

I'm going to risk making a donkey of Fred Bloggs and his brother and 
guess that he really meant to type

Reg : Registry'Class := Open_Registry (...);

I have used Open_Registry because that's the Ada Way :)

-- 
Jeff Carter
"If you think you got a nasty taunting this time,
you ain't heard nothing yet!"
Monty Python and the Holy Grail




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

* Re: problem with abstract types
  2002-10-31 18:20       ` Jeffrey Carter
@ 2002-10-31 20:58         ` Robert I. Eachus
  0 siblings, 0 replies; 30+ messages in thread
From: Robert I. Eachus @ 2002-10-31 20:58 UTC (permalink / raw)




Jeffrey Carter wrote:

> I'm going to risk making a donkey of Fred Bloggs and his brother and 
> guess that he really meant to type
> 
> Reg : Registry'Class := Open_Registry (...);

Oops!  Yep.

> I have used Open_Registry because that's the Ada Way :)

I was trying to not do too much of the Ada way and got burned!  I would 
normally do this:

  package Registries is
    type Registry is limited private;
    type Access_Mode is (User_Mode, Supervisor_Mode);
    function Open_Registry(Name: String; Mode: Access_Mode := User_Mode)
      return Registry;
private
    type Real_Registry(L: Natural) is tagged record
      Name: String(1..L);
      -- ...
    end record;
    type Registry is access Real_Registry'Class;
end Registries;

Actually, I'd probably go a bit further, and make Registry explicitly 
Controlled, to ensure that Registry objects were explicitly finalized. 
But that was definitely way out of bounds of this discussion.




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

* Re: problem with abstract types
  2002-10-31 14:35   ` problem with abstract types Ulrich Eckhardt
@ 2002-11-01  8:31     ` Dmitry A.Kazakov
  2002-11-01 11:32       ` Ulrich Eckhardt
  0 siblings, 1 reply; 30+ messages in thread
From: Dmitry A.Kazakov @ 2002-11-01  8:31 UTC (permalink / raw)


Ulrich Eckhardt wrote:

> Thats exact my problem. I have no idea how to do it a better way.
> I use the package registry as some sort of interface, which sould
> make sure that for every instance a set of functions are declared.
> 
> But i can not or don't know how to declare an abstract type
> and assign later on a real type which is derived from this type.
> For example on java i can create an abstract type and also declare
> a variable of an abstract type. Later on the programm i can then
> instantiate a real type an assign it to this variable. Thats what i
> now want to do in java.

You cannot have a variable of an abstract type. Abstract types have no 
instances. Probably you want a variable which type is derived from some 
abstract type. Maybe you do not know the exact type of the variable. If so 
you could use class-wide objects. Make your registry object a non-limited 
type to have an ability to declare an abstract "constructor":

package Registry is
   type Registry_Object is abstract tagged private;
   function Create (...) return Registry_Object is abstract;
   function Get (...) return ... is abstract;
   procedure Put (...) is abstract;
private
   ...
end Registry;

package Registry.UNIX is
   type UNIX_Registry_Object (<>)  is new Registry_Object with private;
   function Create (...) return UNIX_Registry_Object;
   ...

UNIX_Registry_Object isn't abstract, so you have to implement all abstract 
primitive operations: Create, Get, Put. An instance of 
Registry_Object'Class can be then created as follows:

My_Registry : Registry_Object'Class := Registry.UNIX.Create (...);

Registry_Object is abstract. But Registry_Object'Class is not.

It might look useless in this example because the specific type of 
My_Registry is statically known, but it will have much sense if you would 
later create some sort of a registry factory package:

with Registry.UNIX;
with Registry.POSIX;
...

package Registry.Factory is
   type Registry_Type is (UNIX, POSIX, WINDOWS, ...);
   function Create (Which : Registry_Type, ...)
      return Registry_Object'Class;
...

Then you could well hide all nasty details:

with Registry;               use Registry;
with Registry.Factory;  use Registry.Factory;
...
My_Registry : Registry_Object'Class := Create (UNIX, ...);

-- 
Regards,
Dmitry Kazakov
www.dmitry-kazakov.de



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

* Re: problem with abstract types
  2002-10-31 17:22 ` Stephen Leake
@ 2002-11-01 10:25   ` Ulrich Eckhardt
  2002-11-04 14:30     ` Ted Dennison
  2002-11-04 15:08     ` Ulrich Eckhardt
  2002-11-01 11:15   ` Preben Randhol
  1 sibling, 2 replies; 30+ messages in thread
From: Ulrich Eckhardt @ 2002-11-01 10:25 UTC (permalink / raw)


Stephen Leake wrote:
> Ulrich Eckhardt <uli.e@gmx.de> writes:

> I am hurt, shocked, and amazed that noone has pointed you to Grace, at
> http://savannah.nongnu.org/projects/grace/

Seems that i have used the wrong search words in google ;-)

> It currently has a draft version of the Config_Files package, which
> does exactly what you want, and was discussed extensively last spring.

> Let me know if Grace.Config_Files meets your needs.

Looks promising. But it seems, that support for the windows registry
is missing at the time. I will finish my package (i use it as a
lesson in programming ada) and make it public under GPL. Depending
how useful it is, we can merge it with grace, or the maintainers
of grace can grab the windows portion of my lib and change it
according their needs.

Uli
-- 
Ulrich Eckhardt
http://www.uli-eckhardt.de




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

* Re: problem with abstract types
  2002-10-31 17:18     ` Robert I. Eachus
  2002-10-31 18:20       ` Jeffrey Carter
@ 2002-11-01 10:57       ` Ulrich Eckhardt
  2002-11-01 12:05         ` Simon Wright
  1 sibling, 1 reply; 30+ messages in thread
From: Ulrich Eckhardt @ 2002-11-01 10:57 UTC (permalink / raw)


Robert I. Eachus wrote:
> Ulrich Eckhardt wrote:
> 
> 
>>No. openRegistry is first defined abstract and then implemented
>>as openRegistry(reg : in out file_registry; ..) and
>>openRegistry(reg : in out win_registry; ..) .
> 
[..]
> 
>   with registry; use registry;
>   procedure main is
>     declare
>       reg := openRegistry(CLASS_USER,"registrytest");

It's not so easy. My function get_Registry sould estimat what
type of registry should be used (mybe i want to add later on
also an LDAP, Database or some sort of pluggable support). So it
seems that i have to use access parameters for this.

> Also you will note that I got rid of any need for Unbounded_String.  It 
> may be that some of the individual implementations of openRegistry will 
> need to use Unbounded_String, but if the name never changes, you 

I will change my specs about this.

Uli
-- 
Ulrich Eckhardt
http://www.uli-eckhardt.de




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

* Re: problem with abstract types
  2002-10-31 17:22 ` Stephen Leake
  2002-11-01 10:25   ` Ulrich Eckhardt
@ 2002-11-01 11:15   ` Preben Randhol
  2002-11-01 17:21     ` Stephen Leake
  1 sibling, 1 reply; 30+ messages in thread
From: Preben Randhol @ 2002-11-01 11:15 UTC (permalink / raw)


Stephen Leake wrote:
> I am hurt, shocked, and amazed that noone has pointed you to Grace, at
> http://savannah.nongnu.org/projects/grace/

Don't be, but an ANNOUNCE would have been nice (perhaps I have missed
it). I didn't know it was finished, but I'll download it to test ASAP.

-- 
Preben Randhol  --------------------  http://www.pvv.org/~randhol
�.., chaos is found in greatest abundance wherever order is being
sought. It always defeats order, because it is better organized.�
                            -- Interesting Times, Terry Pratchett



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

* Re: problem with abstract types
  2002-11-01  8:31     ` Dmitry A.Kazakov
@ 2002-11-01 11:32       ` Ulrich Eckhardt
  0 siblings, 0 replies; 30+ messages in thread
From: Ulrich Eckhardt @ 2002-11-01 11:32 UTC (permalink / raw)


Dmitry A.Kazakov wrote:

> you could use class-wide objects. Make your registry object a non-limited 
> type to have an ability to declare an abstract "constructor":
> 
> package Registry is
>    type Registry_Object is abstract tagged private;
>    function Create (...) return Registry_Object is abstract;
>    function Get (...) return ... is abstract;
>    procedure Put (...) is abstract;
> private
[..]
> Then you could well hide all nasty details:
> 
> with Registry;               use Registry;
> with Registry.Factory;  use Registry.Factory;
> ...
> My_Registry : Registry_Object'Class := Create (UNIX, ...);

Hi,

yes thanks, thats the solution. Also i will do some rewritings
on my naming schemes. It wasn't a good idea to create a
package named registry with a type named registry. Then i wondered
why registry'Class creates error messages. Also thanks for all
the other good tips and comments here.

Uli
-- 
Ulrich Eckhardt
http://www.uli-eckhardt.de




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

* Re: problem with abstract types
  2002-11-01 10:57       ` Ulrich Eckhardt
@ 2002-11-01 12:05         ` Simon Wright
  2002-11-01 17:03           ` Robert A Duff
  0 siblings, 1 reply; 30+ messages in thread
From: Simon Wright @ 2002-11-01 12:05 UTC (permalink / raw)


Ulrich Eckhardt <uli.e@gmx.de> writes:

> Robert I. Eachus wrote:

> >   with registry; use registry;
> >   procedure main is
> >     declare
> >       reg := openRegistry(CLASS_USER,"registrytest");
> 
> It's not so easy. My function get_Registry sould estimat what
> type of registry should be used (mybe i want to add later on
> also an LDAP, Database or some sort of pluggable support). So it
> seems that i have to use access parameters for this.

Reg was of type (access to) Registry'Class, which means that the
actual value can be of whichever type you decide at run time.

But to make this work you have to do things the right way: the
"proper" idiom is to initialize using a function,

   declare
      Reg : Registry'Class := Open_Registry (...);
   begin

where you might need to include some indication of what sort of
registry to choose in the parameters to Open_Registry. Often people
use strings. This is a classic example of the Factory pattern ..



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

* Re: problem with abstract types
  2002-11-01 12:05         ` Simon Wright
@ 2002-11-01 17:03           ` Robert A Duff
  2002-11-04 15:18             ` Robert I. Eachus
  0 siblings, 1 reply; 30+ messages in thread
From: Robert A Duff @ 2002-11-01 17:03 UTC (permalink / raw)


Simon Wright <simon.j.wright@amsjv.com> writes:

> But to make this work you have to do things the right way: the
> "proper" idiom is to initialize using a function,
> 
>    declare
>       Reg : Registry'Class := Open_Registry (...);
>    begin
> 
> where you might need to include some indication of what sort of
> registry to choose in the parameters to Open_Registry. Often people
> use strings. This is a classic example of the Factory pattern ..

Right, but if the code can't figure out the Tag of Reg when it is
created, or if the Tag changes over time, then Reg will have to be of
an access-to-Registry'Class type.  But that does not imply that all
the operations need to take access parameters.  They can take Registry
parameters, and you would then pass Reg.all as the actual parameter.

- Bob



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

* Re: problem with abstract types
  2002-11-01 11:15   ` Preben Randhol
@ 2002-11-01 17:21     ` Stephen Leake
  0 siblings, 0 replies; 30+ messages in thread
From: Stephen Leake @ 2002-11-01 17:21 UTC (permalink / raw)


Preben Randhol <randhol+news@pvv.org> writes:

> Stephen Leake wrote:
> > I am hurt, shocked, and amazed that noone has pointed you to Grace, at
> > http://savannah.nongnu.org/projects/grace/
> 
> Don't be, but an ANNOUNCE would have been nice (perhaps I have missed
> it). I didn't know it was finished, but I'll download it to test ASAP.

Well, my phrasing was mostly tongue-in-cheek (I guess I should have
worked in a smiley somewhere). There has not been an explicit
announcement, because of my problems with the Grace web site. Ted has
agreed to make me an administrator, so things should get better soon.

Be aware that the code in Grace.Config_Files does _not_ currently meet
the full requirements for Config_Files spelled out in the document.
Feel free to work on it; I can make you a Grace developer if you'd
like.

-- 
-- Stephe



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

* Re: problem with abstract types
  2002-11-01 10:25   ` Ulrich Eckhardt
@ 2002-11-04 14:30     ` Ted Dennison
  2002-11-04 15:08     ` Ulrich Eckhardt
  1 sibling, 0 replies; 30+ messages in thread
From: Ted Dennison @ 2002-11-04 14:30 UTC (permalink / raw)


Ulrich Eckhardt <uli.e@gmx.de> wrote in message news:<tpktpa-481.ln@uli.uli-eckhardt.de>...
> Looks promising. But it seems, that support for the windows registry
> is missing at the time. I will finish my package (i use it as a
> lesson in programming ada) and make it public under GPL. Depending
> how useful it is, we can merge it with grace, or the maintainers
> of grace can grab the windows portion of my lib and change it
> according their needs.


I'd also like to point out that there are thick Win32 registry
bindings in the SETI@Home Service, for which sources are available.
The sources are GPL, but I've always intended to release the bindings
into the public domain, or find them a good home elsewhere. So if
anyone is interested in them but put off by the GPL, contact me.

-- 
T.E.D.   Home     -  mailto:dennison@telepath.com (Yahoo:
Ted_Dennison)
         Homepage -  http://www.telepath.com/~dennison/Ted/TED.html

"Klingons do not make software 'releases'. Our software 'escapes'.
Typically leaving a trail of wounded programmers in it's wake."



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

* Re: problem with abstract types
  2002-11-01 10:25   ` Ulrich Eckhardt
  2002-11-04 14:30     ` Ted Dennison
@ 2002-11-04 15:08     ` Ulrich Eckhardt
  2002-11-04 15:32       ` Stephen Leake
  1 sibling, 1 reply; 30+ messages in thread
From: Ulrich Eckhardt @ 2002-11-04 15:08 UTC (permalink / raw)


Ulrich Eckhardt wrote:
> Stephen Leake wrote:
>>Let me know if Grace.Config_Files meets your needs.
>  
> Looks promising. But it seems, that support for the windows registry
> is missing at the time. I will finish my package (i use it as a
> lesson in programming ada) and make it public under GPL. Depending

As promised a first pre-alpha version of this package
is available (under GPL) from
http://www.uli-eckhardt.de/ada_registry

Since this is also intended to be a learning ada project
for me, comments and hints about my programming style
are also welcome.

Uli
-- 
Ulrich Eckhardt
http://www.uli-eckhardt.de




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

* Re: problem with abstract types
  2002-11-01 17:03           ` Robert A Duff
@ 2002-11-04 15:18             ` Robert I. Eachus
  2002-11-04 16:14               ` Robert A Duff
  0 siblings, 1 reply; 30+ messages in thread
From: Robert I. Eachus @ 2002-11-04 15:18 UTC (permalink / raw)


Robert A Duff wrote:

> Right, but if the code can't figure out the Tag of Reg when it is
> created, or if the Tag changes over time, then Reg will have to be of
> an access-to-Registry'Class type.  But that does not imply that all
> the operations need to take access parameters.  They can take Registry
> parameters, and you would then pass Reg.all as the actual parameter.

Bob, this is at best overkill in this case.  I can imagine a situation 
where you might want to copy data from one type of registry to another 
that would require having two open registries with different tags.  But 
even in that case, you have as an invariant that every object of type 
registry has a single tag value, and it must be determinable when the 
registry is opened.  Open registries morphing their types underneath a 
program boggles the mind.

I guess that there is a meta-rule here.  To paraphrase Einstein, "The 
user view of a data structure should be as simple as possible, but no 
simpler."  ;-) The "extra" work the implementor of an abstraction may 
have to accept to keep the visible abstraction simple is just good 
software engineering.

Ada goes to a lot of hard work to allow simple abstractions to be 
implemented with little or no run-time overhead.  In this particular 
case, the compiler might generate better code for the case with a 
classwide variable initialized at open than for an access to classwide 
type varible.  But I don't see that "savings" as the real reason for 
implementing an abstraction correctly.  The real benefit is that the 
user of the abstraction doesn't have to sweat the details if the 
abstraction is a good match to "reality," whatever that means to the 
user of the abstraction.

For example, if you are writing avionics software, "this aircraft" is an 
implicit constant.  Some of its attributes, such as weight or current 
airspeed may change, but avionics software does not expect to find 
itself in a new aircraft during flight.  If you are working on air 
traffic control software, "this aircraft" is a variable, and in fact, 
you even have to change the type of aircraft associated with a 
particular track.  (Mostly from unknown to a particular class, but that 
is a detail.)




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

* Re: problem with abstract types
  2002-11-04 15:08     ` Ulrich Eckhardt
@ 2002-11-04 15:32       ` Stephen Leake
  2002-11-04 17:12         ` Ulrich Eckhardt
  0 siblings, 1 reply; 30+ messages in thread
From: Stephen Leake @ 2002-11-04 15:32 UTC (permalink / raw)


Ulrich Eckhardt <uli.e@gmx.de> writes:

> Ulrich Eckhardt wrote:
> 
> As promised a first pre-alpha version of this package
> is available (under GPL) from
> http://www.uli-eckhardt.de/ada_registry
> 
> Since this is also intended to be a learning ada project
> for me, comments and hints about my programming style
> are also welcome.

If files suffice under Unix, then files will suffice under Windows,
and you don't need the registry. On the other hand, if you need the
registry (for multi-process interaction), then you need it under
windows; see the gconf package in Gnome.

I have nothing against an Ada interface to the Windows registry; I'm
just suggesting you be consistent across the two platforms.

Feel free to see Config_Files for ideas on implementation; imitation is
the best form of flattery :).

-- 
-- Stephe



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

* Re: problem with abstract types
  2002-11-04 15:18             ` Robert I. Eachus
@ 2002-11-04 16:14               ` Robert A Duff
  0 siblings, 0 replies; 30+ messages in thread
From: Robert A Duff @ 2002-11-04 16:14 UTC (permalink / raw)


"Robert I. Eachus" <rieachus@attbi.com> writes:

>...Open registries morphing their types underneath a
> program boggles the mind.

Yes, I agree with that.  But it might be convenient to have a "this
registry" variable in some package body, and it might be inconvenient to
know what sort of registry it is when that variable is elaborated.
In that case, one needs a pointer.

But I do agree that the program probably won't magically migrate from
Windows to Unix at run time, and change its registry accordingly!  ;-)

- Bob



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

* Re: problem with abstract types
  2002-11-04 15:32       ` Stephen Leake
@ 2002-11-04 17:12         ` Ulrich Eckhardt
  2002-11-04 17:43           ` David C. Hoos
  0 siblings, 1 reply; 30+ messages in thread
From: Ulrich Eckhardt @ 2002-11-04 17:12 UTC (permalink / raw)


Stephen Leake wrote:
>>Ulrich Eckhardt wrote:
>>
>>As promised a first pre-alpha version of this package
>>is available (under GPL) from
>>http://www.uli-eckhardt.de/ada_registry

> If files suffice under Unix, then files will suffice under Windows,

Yes and No. For example there is no standard location on
windows where user dependend files are stored. But the
registry has suitable places. On the other hand on Unix
not registry exists, but there is a common place for user
dependend files under /home/<username>/.

Also it makes sense to store all this config informations under
Windows in the registry so that all the windows guys can use
their preferred tools for replication/backup/distribution.

My package should handle this things transparently without the
need of worring how the configuration options are really stored
on every platform.

> and you don't need the registry. On the other hand, if you need the
> registry (for multi-process interaction), then you need it under

It's not a primary goal to access the windows registry. Maybe i will
add some support functions for this to the windows part.

> I have nothing against an Ada interface to the Windows registry; I'm
> just suggesting you be consistent across the two platforms.

Yes, thats my primary goal. It should be a consitent interface
which stores the configuration options on all platforms in their
"native" form. Also it should be easy to create new modules
which for example may access an LDAP server.


Uli
-- 
Ulrich Eckhardt
http://www.uli-eckhardt.de




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

* Re: problem with abstract types
  2002-11-04 17:12         ` Ulrich Eckhardt
@ 2002-11-04 17:43           ` David C. Hoos
  2002-11-04 19:34             ` Ulrich Eckhardt
                               ` (2 more replies)
  0 siblings, 3 replies; 30+ messages in thread
From: David C. Hoos @ 2002-11-04 17:43 UTC (permalink / raw)



----- Original Message ----- 
From: "Ulrich Eckhardt" <uli.e@gmx.de>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: Monday, November 04, 2002 11:12 AM
Subject: Re: problem with abstract types


> Stephen Leake wrote:
> >>Ulrich Eckhardt wrote:
> >>
> >>As promised a first pre-alpha version of this package
> >>is available (under GPL) from
> >>http://www.uli-eckhardt.de/ada_registry
> 
> > If files suffice under Unix, then files will suffice under Windows,
> 
> Yes and No. For example there is no standard location on
> windows where user dependend files are stored. But the
> registry has suitable places. On the other hand on Unix
> not registry exists, but there is a common place for user
> dependend files under /home/<username>/.

FWIW, the use of the Registry is deprecated for new development.
There is, in fact, for the "modern" versions of windows an
application data directory designated by the environment variable
APPDATA which has underneath it a directory for each
manufacturer of the application software.
> 
> Also it makes sense to store all this config informations under
> Windows in the registry so that all the windows guys can use
> their preferred tools for replication/backup/distribution.
> 
> My package should handle this things transparently without the
> need of worring how the configuration options are really stored
> on every platform.
> 
> > and you don't need the registry. On the other hand, if you need the
> > registry (for multi-process interaction), then you need it under
> 
> It's not a primary goal to access the windows registry. Maybe i will
> add some support functions for this to the windows part.
> 
> > I have nothing against an Ada interface to the Windows registry; I'm
> > just suggesting you be consistent across the two platforms.
> 
> Yes, thats my primary goal. It should be a consitent interface
> which stores the configuration options on all platforms in their
> "native" form. Also it should be easy to create new modules
> which for example may access an LDAP server.
> 
> 
> Uli
> -- 
> Ulrich Eckhardt
> http://www.uli-eckhardt.de
> 
> _______________________________________________
> 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] 30+ messages in thread

* Re: problem with abstract types
  2002-11-04 17:43           ` David C. Hoos
@ 2002-11-04 19:34             ` Ulrich Eckhardt
  2002-11-04 19:54             ` Stephen Leake
  2002-11-04 20:08             ` Robert A Duff
  2 siblings, 0 replies; 30+ messages in thread
From: Ulrich Eckhardt @ 2002-11-04 19:34 UTC (permalink / raw)


David C. Hoos wrote:

 >Ulrich Eckhardt wrote:

>>Yes and No. For example there is no standard location on
>>windows where user dependend files are stored. But the

> FWIW, the use of the Registry is deprecated for new development.
> There is, in fact, for the "modern" versions of windows an
> application data directory designated by the environment variable
> APPDATA which has underneath it a directory for each
> manufacturer of the application software.

Are you really sure and do you have a link handy ?
How ever, my concept is flexible enough to handle this too
and hopefully the concept is flexible enough
to handle further "good ideas[tm]" of microsoft

Uli
-- 
Ulrich Eckhardt
http://www.uli-eckhardt.de




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

* Re: problem with abstract types
  2002-11-04 17:43           ` David C. Hoos
  2002-11-04 19:34             ` Ulrich Eckhardt
@ 2002-11-04 19:54             ` Stephen Leake
  2002-11-04 20:08             ` Robert A Duff
  2 siblings, 0 replies; 30+ messages in thread
From: Stephen Leake @ 2002-11-04 19:54 UTC (permalink / raw)


"David C. Hoos" <david.c.hoos.sr@ada95.com> writes:

> FWIW, the use of the Registry is deprecated for new development.
> There is, in fact, for the "modern" versions of windows an
> application data directory designated by the environment variable
> APPDATA which has underneath it a directory for each
> manufacturer of the application software.

Amazing :). Where is this documented? I'd like to reference it in the
Config_Files documentation.

-- 
-- Stephe



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

* Re: problem with abstract types
  2002-11-04 17:43           ` David C. Hoos
  2002-11-04 19:34             ` Ulrich Eckhardt
  2002-11-04 19:54             ` Stephen Leake
@ 2002-11-04 20:08             ` Robert A Duff
  2 siblings, 0 replies; 30+ messages in thread
From: Robert A Duff @ 2002-11-04 20:08 UTC (permalink / raw)


"David C. Hoos" <david.c.hoos.sr@ada95.com> writes:

> FWIW, the use of the Registry is deprecated for new development.
> There is, in fact, for the "modern" versions of windows an
> application data directory designated by the environment variable
> APPDATA which has underneath it a directory for each
> manufacturer of the application software.

Is this a joke?!

If not, I'm astonished.  Can you point to some docs on this?
Too bad the registry wasn't deprecated immediately upon being invented
-- it's an utterly bad idea.

- Bob



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

end of thread, other threads:[~2002-11-04 20:08 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-31 12:06 problem with abstract types Ulrich Eckhardt
2002-10-31 13:15 ` John English
2002-10-31 14:43   ` Ulrich Eckhardt
2002-10-31 17:18     ` Robert I. Eachus
2002-10-31 18:20       ` Jeffrey Carter
2002-10-31 20:58         ` Robert I. Eachus
2002-11-01 10:57       ` Ulrich Eckhardt
2002-11-01 12:05         ` Simon Wright
2002-11-01 17:03           ` Robert A Duff
2002-11-04 15:18             ` Robert I. Eachus
2002-11-04 16:14               ` Robert A Duff
2002-10-31 13:32 ` David C. Hoos
2002-10-31 13:47   ` problem with posters Peter Hermann
2002-10-31 14:15     ` Preben Randhol
2002-10-31 14:35   ` problem with abstract types Ulrich Eckhardt
2002-11-01  8:31     ` Dmitry A.Kazakov
2002-11-01 11:32       ` Ulrich Eckhardt
2002-10-31 15:31 ` Simon Wright
2002-10-31 17:22 ` Stephen Leake
2002-11-01 10:25   ` Ulrich Eckhardt
2002-11-04 14:30     ` Ted Dennison
2002-11-04 15:08     ` Ulrich Eckhardt
2002-11-04 15:32       ` Stephen Leake
2002-11-04 17:12         ` Ulrich Eckhardt
2002-11-04 17:43           ` David C. Hoos
2002-11-04 19:34             ` Ulrich Eckhardt
2002-11-04 19:54             ` Stephen Leake
2002-11-04 20:08             ` Robert A Duff
2002-11-01 11:15   ` Preben Randhol
2002-11-01 17:21     ` Stephen Leake

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