For Programmers: Free Programming Magazines  


Home > Archive > Fortran > December 2006 > F2003









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author F2003
Mehmet Karatay

2006-12-13, 4:18 pm

Hello,

I'm still playing about with the new f2003 standard as far as my
compiler will let me to get a feel for it. There is one thing which is
causing me issues at the minute. I don't even know if what I'm trying
to do is possible.

I have one object (A) which has several objects of the same class (B)
in it. I would like these objects to be private and only accessed with
accessor functions. Is there anyway to call the procedures of class B
without writing a wrapper in A for each case? I was thinking something
along the lines of:

module object_A_class
use object_B_class
implicit none

type an_example
class(object_B), private, pointer :: bar
contains
procedure, public :: foo => bar%get() !The key line
end type an_example
end module object_A_class

The key line doesn't work, and I wasn't really expecting it to.
Hopefully, though, this explains what I am trying to achieve? My
compiler says there is a syntax error at the %.

Is it possible (in theory) to achieve this, any tips would be much
appreciated!

thanks for any suggestions,
mehmet

-------------------------
To contact me use:
m -dot- r -dot- karatay -at- domain as above

Mehmet Karatay

2006-12-13, 4:18 pm

Apologies for the vague title, I was going to come up with something
better but forgot. I only noticed after I posted.

mehmet

On Dec 13, 1:59 pm, "Mehmet Karatay" <nospam.meh...@gmail.com> wrote:
> Hello,
>
> I'm still playing about with the new f2003 standard as far as my
> compiler will let me to get a feel for it. There is one thing which is
> causing me issues at the minute. I don't even know if what I'm trying
> to do is possible.
>
> I have one object (A) which has several objects of the same class (B)
> in it. I would like these objects to be private and only accessed with
> accessor functions. Is there anyway to call the procedures of class B
> without writing a wrapper in A for each case? I was thinking something
> along the lines of:
>
> module object_A_class
> use object_B_class
> implicit none
>
> type an_example
> class(object_B), private, pointer :: bar
> contains
> procedure, public :: foo => bar%get() !The key line
> end type an_example
> end module object_A_class
>
> The key line doesn't work, and I wasn't really expecting it to.
> Hopefully, though, this explains what I am trying to achieve? My
> compiler says there is a syntax error at the %.
>
> Is it possible (in theory) to achieve this, any tips would be much
> appreciated!
>
> thanks for any suggestions,
> mehmet
>
> -------------------------
> To contact me use:
> m -dot- r -dot- karatay -at- domain as above


Reinhold Bader

2006-12-14, 4:13 am

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello Mehmet,

what probably should work is
type an_example
class(object_B), private, pointer :: bar
contains
procedure, nopass, public :: foo => foo_impl
end type an_example

provided that foo_impl is an accessible subroutine in
module object_A_class. Note the nopass attribute since
you will not be able to pass the object itself as first (or any other)
argument. So usage would be

type(an_example) :: ex
: ! typed allocation of ex%bar
call ex%foo(ex%bar,...)

Regards

Mehmet Karatay wrote:
> Hello,
>
> I'm still playing about with the new f2003 standard as far as my
> compiler will let me to get a feel for it. There is one thing which is
> causing me issues at the minute. I don't even know if what I'm trying
> to do is possible.
>
> I have one object (A) which has several objects of the same class (B)
> in it. I would like these objects to be private and only accessed with
> accessor functions. Is there anyway to call the procedures of class B
> without writing a wrapper in A for each case? I was thinking something
> along the lines of:
>
> module object_A_class
> use object_B_class
> implicit none
>
> type an_example
> class(object_B), private, pointer :: bar
> contains
> procedure, public :: foo => bar%get() !The key line
> end type an_example
> end module object_A_class
>
> The key line doesn't work, and I wasn't really expecting it to.
> Hopefully, though, this explains what I am trying to achieve? My
> compiler says there is a syntax error at the %.
>
> Is it possible (in theory) to achieve this, any tips would be much
> appreciated!
>
> thanks for any suggestions,
> mehmet
>
> -------------------------
> To contact me use:
> m -dot- r -dot- karatay -at- domain as above
>


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFgSNVFVLhKuD7VgsRArjOAJ4/5fH33cEw8AxWW0B9e4iPEqMYHACgp7GN
apE6MfSFj9UXZ1419r+eOAw=
=fgQm
-----END PGP SIGNATURE-----
Reinhold Bader

2006-12-14, 8:57 am

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


> So usage would be


only within host scope of module defining type an_example though,
or else no private clause on component bar.


>
> type(an_example) :: ex
> : ! typed allocation of ex%bar
> call ex%foo(ex%bar,...)
>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFgSSeFVLhKuD7VgsRAtyvAJsHZ6F9vIwH
N1QLDmH9cMr7p1nSlgCgjoxz
Apswk+lUInSuAeilAY5I6C8=
=ygwN
-----END PGP SIGNATURE-----
Michael Metcalf

2006-12-14, 8:57 am


"Mehmet Karatay" <nospam.mehmet@gmail.com> wrote in message
news:1166018351.097710.293270@f1g2000cwa.googlegroups.com...

> I'm still playing about with the new f2003 standard as far as my
> compiler will let me to get a feel for it. There is one thing which is
> causing me issues at the minute. I don't even know if what I'm trying
> to do is possible.


No, it is not.

> I have one object (A) which has several objects of the same class (B)
> in it. I would like these objects to be private and only accessed with
> accessor functions. Is there anyway to call the procedures of class B
> without writing a wrapper in A for each case?


No.

> I was thinking something along the lines of:
>
> module object_A_class
> use object_B_class
> implicit none
>
> type an_example
> class(object_B), private, pointer :: bar
> contains
> procedure, public :: foo => bar%get() !The key line


There is a fundamental issue here: GET expects a class(object_B)
argument, but FOO is going to be passed a class(object_A) argument.

That is, you are attempting to do much more than simply bringing
in another procedure, you are attempting to munge the argument list
as well. That's just not possible: a type-bound procedure is just
a (dynamically dispatched) procedure, not something magical.

> end type an_example
> end module object_A_class
>
> The key line doesn't work, and I wasn't really expecting it to.
> Hopefully, though, this explains what I am trying to achieve? My
> compiler says there is a syntax error at the %.


That is right.

> Is it possible (in theory) to achieve this, any tips would be much
> appreciated!


You can only avoid writing a wrapper in the case of type extension,
where you don't need to "wrap" the inherited type-bound procedures
(there is no argument list massaging involved or required).

That doesn't really help here, since
(a) you want several objects,
(b) you want them to be private.

Writing a wrapper means you get to say
(a) what arguments "get" is going to be called with
(b) an opportunity to handle the case of BAR being a null
pointer gracefully.

OTOH, if object B is itself opaque (has no public components, only public
operations), one solution is to make them public components, e.g.

module object_A_class
use object_B_class
implicit none
type an_example
class(object_B), pointer :: bar
end type an_example
end module object_A_class

and then when you have a class(object_A) x, do "call x%bar%get"
(instead of "call x%foo").

Cheers,
--
.........................Malcolm Cohen (malcolm@nag-j.co.jp), Nihon NAG,
Tokyo.


Mehmet Karatay

2006-12-15, 8:07 am

Hi again,

Thanks a lot for all the useful replies. Michael, thank you for
explaining how foo and get want different objects passed in. It seems
obvious now! I'll have a play and see what I come up with. No doubt
I'll be back when some other issue gets beyond me, I do try to figure
things out myself first though.

Thanks,
mehmet

-------------------------
To contact me use:
m -dot- r -dot- karatay -at- domain as above

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com