Forums > Dev

Setting and getting attributes

January 11, 2008 | 10:58 pm

Hi there,

I have a data structure as follows:

typedef struct myData {
UInt32 a;
UInt32 b;
UInt32 c;
} myData;

typedef struct _myobj {
t_object ob;
void *obex;
void *out;
myData *data;
} t_myobj;

Now I want to create attributes to get and set a, b and c.

So, clearly, all three will have a custom set and get method, however I am confused, because obviously the typical way of doing it in this case doesn’t work:

attr = attr_offset_new("a", _sym_long, attrflags, (method)myobj_a_get, (method)myobj_a_set, calcoffset(t_continuum, a));
class_addattr(c, attr);

So, what’s the correct form to declare the attributes in this case ?

Thanks.

- Luigi

————————————————————
THIS E-MAIL MESSAGE IS FOR THE SOLE USE OF THE INTENDED RECIPIENT AND MAY CONTAIN CONFIDENTIAL AND/OR PRIVILEGED INFORMATION. ANY UNAUTHORIZED REVIEW, USE, DISCLOSURE OR DISTRIBUTION IS PROHIBITED. IF YOU ARE NOT THE INTENDED RECIPIENT, CONTACT THE SENDER BY E-MAIL AT SUPERBIGIO@YAHOO.COM AND DESTROY ALL COPIES OF THE ORIGINAL MESSAGE. WITHOUT PREJUDICE UCC 1-207.
————————————————————

Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping


January 12, 2008 | 6:09 pm

On Jan 11, 2008, at 2:58 PM, Luigi Castelli wrote:

> So, clearly, all three will have a custom set and get method,
> however I am confused, because obviously the typical way of doing
> it in this case doesn’t work:
>
> attr = attr_offset_new("a", _sym_long, attrflags, (method)
> myobj_a_get, (method)myobj_a_set, calcoffset(t_continuum, a));
> class_addattr(c, attr);
>
> So, what’s the correct form to declare the attributes in this case ?

Just give an offset of zero. This is ignored if you have both custom
getter and setter–i.e.

attr = attr_offset_new("a", _sym_long, attrflags, (method)
myobj_a_get, (method)myobj_a_set, 0);

Alternately, you could avoid allocating your "myData" struct and
simply embed in your object, which would permit default accessors– i.e.

typedef struct _myobj {
t_object ob;
void *obex;
void *out;
myData data; // embed, not a pointer
} t_myobj;

// notice the data.a notation to use embedded structs.
attr = attr_offset_new("a", _sym_long, attrflags, (method)NULL,
(method)NULL, calcoffset(t_myobj, data.a));

-Joshua


Viewing 2 posts - 1 through 2 (of 2 total)