www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Access private member

reply Pierre <cathary.pierre neuf.fr> writes:
Hi,
I would like to know how can i access private member of class 
from outside ?
I think about serialization for instance, serializer must have 
access to protected attributes. How this is done ?
Thank you.
Jun 13 2016
next sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2016-06-13 09:43, Pierre wrote:
 Hi,
 I would like to know how can i access private member of class from
 outside ?
 I think about serialization for instance, serializer must have access to
 protected attributes. How this is done ?
 Thank you.
For fields, used .tupleof, for other symbols, use a pointer. -- /Jacob Carlborg
Jun 13 2016
parent reply Jacob Carlborg <doob me.com> writes:
On 2016-06-13 09:49, Jacob Carlborg wrote:

 For fields, used .tupleof, for other symbols, use a pointer.
Here's an example [1] of accessing a field using the name of the field as a string. It will bypass private. That module [1] contains some generic functionality for working with fields which you would need for serialization. Or you can use the whole serialization library directly [2] ;) [1] https://github.com/jacob-carlborg/orange/blob/master/orange/util/Reflection.d#L123 [2] https://github.com/jacob-carlborg/orange -- /Jacob Carlborg
Jun 13 2016
parent Basile B. <b2.temp gmx.com> writes:
On Monday, 13 June 2016 at 07:53:08 UTC, Jacob Carlborg wrote:
 On 2016-06-13 09:49, Jacob Carlborg wrote:

 For fields, used .tupleof, for other symbols, use a pointer.
Here's an example [1] of accessing a field using the name of the field as a string. It will bypass private. That module [1] contains some generic functionality for working with fields which you would need for serialization. Or you can use the whole serialization library directly [2] ;) [1] https://github.com/jacob-carlborg/orange/blob/master/orange/util/Reflection.d#L123 [2] https://github.com/jacob-carlborg/orange
There's also the IZ serializer. It's based on accessors (called property descriptor) to read and write private or protected fields. Actually it's never a good idea to directly access them. Usually they're not hidden for anything (e.g the count of items in a list, the setter update the list...) pd: https://github.com/BBasile/iz/blob/master/import/iz/properties.d ser: https://github.com/BBasile/iz/blob/master/import/iz/serializer.d
Jun 13 2016
prev sibling parent reply Basile B. <b2.temp gmx.com> writes:
On Monday, 13 June 2016 at 07:43:09 UTC, Pierre wrote:
 Hi,
 I would like to know how can i access private member of class 
 from outside ?
 I think about serialization for instance, serializer must have 
 access to protected attributes. How this is done ?
 Thank you.
You can perform the introspection in the class itself, e .g in the __ctor.
Jun 13 2016
parent reply Pierre <cathary.pierre neuf.fr> writes:
Thank you i will try it.
Jun 13 2016
parent reply Jacob Carlborg <doob me.com> writes:
On 2016-06-13 09:54, Pierre wrote:
 Thank you i will try it.
You don't need to involve the constructor. You can use .tupleof, as I mentioned [1] [2]. [1] http://forum.dlang.org/post/njlohq$1n99$1 digitalmars.com [2] http://forum.dlang.org/post/njlop0$1ngk$1 digitalmars.com -- /Jacob Carlborg
Jun 13 2016
parent reply Basile B. <b2.temp gmx.com> writes:
On Monday, 13 June 2016 at 11:27:31 UTC, Jacob Carlborg wrote:
 On 2016-06-13 09:54, Pierre wrote:
 Thank you i will try it.
You don't need to involve the constructor. You can use .tupleof, as I mentioned [1] [2]. [1] http://forum.dlang.org/post/njlohq$1n99$1 digitalmars.com [2] http://forum.dlang.org/post/njlop0$1ngk$1 digitalmars.com
I understand that web devels needs to dump 47 bytes and send them at 8759 miles in 200 ms, but this serialization scheme is not good for object streaming, e.g store a full GUI in a resource file. Nobody will ever use flatbuffer or message pack to store a GUI...lol.
Jun 13 2016
parent reply Basile B. <b2.temp gmx.com> writes:
On Monday, 13 June 2016 at 14:30:13 UTC, Basile B. wrote:
 On Monday, 13 June 2016 at 11:27:31 UTC, Jacob Carlborg wrote:
 On 2016-06-13 09:54, Pierre wrote:
 Thank you i will try it.
You don't need to involve the constructor. You can use .tupleof, as I mentioned [1] [2]. [1] http://forum.dlang.org/post/njlohq$1n99$1 digitalmars.com [2] http://forum.dlang.org/post/njlop0$1ngk$1 digitalmars.com
I understand that web devels needs to dump 47 bytes and send them at 8759 miles in 200 ms, but this serialization scheme is not good for object streaming, e.g store a full GUI in a resource file. Nobody will ever use flatbuffer or message pack to store a GUI...lol.
oops I think I've replied to another thread on another board :/ Unless It's you Jacob who have proposed Orange to phobos in 2012. And then since refused it's not developed at all. IIRC it's even not possible to compile it with DUB.
Jun 13 2016
next sibling parent Basile B. <b2.temp gmx.com> writes:
On Monday, 13 June 2016 at 15:00:06 UTC, Basile B. wrote:
 On Monday, 13 June 2016 at 14:30:13 UTC, Basile B. wrote:
 On Monday, 13 June 2016 at 11:27:31 UTC, Jacob Carlborg wrote:
 On 2016-06-13 09:54, Pierre wrote:
 Thank you i will try it.
You don't need to involve the constructor. You can use .tupleof, as I mentioned [1] [2]. [1] http://forum.dlang.org/post/njlohq$1n99$1 digitalmars.com [2] http://forum.dlang.org/post/njlop0$1ngk$1 digitalmars.com
I understand that web devels needs to dump 47 bytes and send them at 8759 miles in 200 ms, but this serialization scheme is not good for object streaming, e.g store a full GUI in a resource file. Nobody will ever use flatbuffer or message pack to store a GUI...lol.
oops I think I've replied to another thread on another board :/ Unless It's you Jacob who have proposed Orange to phobos in 2012. And then since refused it's not developed at all. IIRC it's even not possible to compile it with DUB.
https://www.youtube.com/watch?v=YJO4-aa6PCI&list=PLuhnsen8iS5ltHofd21TWBx-bqmR9V8RU&index=14&nohtml5=False now you know the origin of the hat ;)
Jun 13 2016
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2016-06-13 17:00, Basile B. wrote:

 Unless It's you Jacob who have proposed Orange to phobos in 2012. And
 then since refused it's not developed at all. IIRC it's even not
 possible to compile it with DUB.
Yes, I've written Orange and proposed it to Phobos. Not sure what you mean with "refused" and "not developed". Orange is a part of Mambo [1] which is avilable using Dub [2]. [1] https://github.com/jacob-carlborg/mambo/tree/master/mambo/serialization [2] http://code.dlang.org/packages/mambo -- /Jacob Carlborg
Jun 13 2016