On Mon, 2 Oct 2000, Brian S. Julin wrote:
>
> On Sat, 30 Sep 2000, Lee Brown wrote:
> > I think I see what you are trying to do. You could use a structure to associate
>the filename with the visual.
> >
> > struct texture {
> > ggi_visual vis;
> > char* filename;
> > };
I did so, even I don't like that.
> > Then work with the texture structure instead, dereferencing each member as
>appropriate when neccessary.
>
> I think that he's trying to avoid the syntactical ugliness of
> the dereference while calling normal LibGGI api functions.
Exactly. That's the reason, I don't like the solution above.
> What about if we came up with a libGGI extension specifically
> _for_ carrying application specific data in a visual that would take
> care of everyone who ever wanted to do it for any reason in one
> swell foop.
Very good idea. I like it.
> It would look something like this:
>
> struct mydata {
> int foo;
> char *filename;
> };
>
> struct mydata *dh;
>
> ggiMetaDataInit();
>
> /* open a visual, yada yada */
> mydataname = "mydata";
> ggiMetaDataCalloc(vis, &mydataname, sizeof(struct mydata), 1);
>
> /* Regular data can be accessed with no nuance */
> #define TextureNum(vis) ((struct mydata *)(ggiMetaDataPtr(vis, "mydata"))->num)
>
> /* e.g. */
> TextureNum(vis)++;
>
> /* Nested dereference requires a little more work if you want all the
> data cleaned up when the visual is closed or for any other reason want
> to keep it all inside the object. Probably this simple string example
> is worthy of convenience macros in the extension header. */
> #define TextureFilenamePtr(vis) \
> ((struct mydata *)(ggiMetaDataPtr(vis, "mydata"))->filename)
>
> #define setTextureFilename(vis, str) \
> { ggiMetaDataFreePtr(TextureFilenamePtr(vis)); \
> TextureFileNamePtr(vis) = \
> ggiMetaDataAnonCalloc(vis, "mydata", strlen(str) + 1, 1); \
> strncpy(TextureFileNamePtr(vis), str, strlen(str)); \
> }
>
> /* By-hand deallocation has two forms, named and anonymous. */
> ggi MetaDataAnonCalloc is anonymous allocation, but still needs
> string argument so this: */
> ggiMetaDataFree(vis, "mydata");
> /* Will clear any nested data structure as well. */
That all is too lowlevel and complex.
I would prefer to having a simpler solution like that:
/* allocates sizeof(struct mydata) bytes memory
* and set it to the visual
* struct mydata can be any kind of a structure
*/
ggiOpenMetaData(vis, sizeof(struct mydata));
/* fill the private data allocated with ggiOpenMetaData()
* with the data given by the &mydata
*/
ggiSetMetaData(vis, &mydata);
/* read out the private data, set by ggiSetMetaData()
*/
ggiGetMetaData(vis, &mydata);
/* removes the private data and free()'s the memory
* allocated by ggiOpenMetaData()
*/
ggiCloseMetaData(vis);
[snip]
> Alternatively, the Christoph could write his program in Perl
> and simply subclass GGI:: :-).
Well, it's more than a simple program.
Have a look at http://home.t-online.de/home/christoph_egger/3dtk/
CU,
Christoph Egger
E-Mail: [EMAIL PROTECTED]