[PD-dev] getting the classname in an class

Mathieu Bouchard matju at artengine.ca
Tue Oct 30 16:31:58 CET 2007


On Mon, 29 Oct 2007, Hans-Christoph Steiner wrote:

> static void entry_save(t_gobj *z, t_binbuf *b)
> {
>   t_entry *x = (t_entry *)z;
>   binbuf_addv(b, "ssiisiiss", gensym("#X"),gensym("obj"),
>                   x->x_obj.te_xpix, x->x_obj.te_ypix,
>                  atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
>                  x->x_width, x->x_height, x->x_bgcolour, x->x_fgcolour);
>   binbuf_addv(b, ";");
> }

calls to binbuf_addv can be merged in the same way as fprintf calls can: 
keep the same first arg, concatenate the two second args, and then append 
the rest of the latter rest of arguments to the first. So, you never need 
a separate call for ";".

they can also be split in any way. For example you can do "ssiis" first 
and then do "iiss;", as long as the rest of arguments are also split in 
the same way. You could make a function like:

   void obj_saveheader(t_binbuf *b, t_object *x) {
     binbuf_addv(b,"ssiis", gensym("#X"), gensym("obj"),
       x->te_xpix, x->te_ypix, atom_getsymbol(binbuf_getvec(x->te_binbuf)));
   }

and then use it at the beginning of every save function that fits with 
that pattern (which is every one of them, so far).

> Perhaps atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)) could be defined in 
> m_pd.h as something like "class_getclassname"

its naming does not work. as it doesn't give you the class _name_, don't 
make it end in "_getclassname", and as it doesn't start from (nor use) a 
t_class *, don't make it start in "class_".

i think that it should be a obj_...() name, but then, if you do that, make 
sure to handle the special case in which one puts a float and only a float 
in an object box, because that would crash the above code. you never hit 
this case with savefn, but you are making a generic-sounding obj_...() 
call so it should accept any obj_... and imho it should also accept 
top-level canvases as arguments... as well as incomplete objects (objects 
that don't have a binbuf yet, while they are created).

  _ _ __ ___ _____ ________ _____________ _____________________ ...
| Mathieu Bouchard - tél:+1.514.383.3801, Montréal QC Canada


More information about the Pd-dev mailing list