Amiga.org
Operating System Specific Discussions => Amiga OS => Amiga OS -- Development => Topic started by: Jose on January 18, 2006, 04:02:02 PM
-
Hi. I'm not at home so can't read anything to confirm but I'd like to clarify this doubt anway.
I want to be able to pass multiple indetical Tags (in ti_Tag), among other different ones, to be able to pass multiple items of a certain type (the type being identified by ti_Tag). GetTagData() will get me the first TagItem in the array that has the ti_Tag I requested but how do I call the next ones ? If call GetTagData() again with the TagItem returned by the 1st call to it, I suspect it will return the same TagItem so the solution seems to be calling NexTagItem after that and then use the returned value to call GetTagData() again. Now NextTagItem() uses a double indirect pointer.
All this makes the process cumbersome and, to me the most important, inefficient, is there another way ?
-
Hmm, I guess I'll make another array with those repeated items and pass a pointer to it in a TagItem...
Still the former method was more flexible to other people writting code for it (this is a function the makes part of a very small API for other people to be able to extend my own program's actions)...
Cheers
José
-
;/*
gcc -noixemul -Wall -O2 tagtest.c -o tagtest
quit
*/
#include <utility/tagitem.h>
#include <proto/utility.h>
#include <proto/dos.h>
#define MYTAG_Base (TAG_USER + 0xbad000)
#define MYTAG_FOO (MYTAG_Base + 0)
#define MYTAG_BAR (MYTAG_Base + 1)
void myfunc(struct TagItem *taglist);
int main(void)
{
struct TagItem tags[] =
{
{MYTAG_FOO, 1},
{MYTAG_FOO, 2},
{MYTAG_BAR, 666},
{MYTAG_BAR, 0},
{TAG_DONE,}
};
myfunc(tags);
return 0;
}
void myfunc(struct TagItem *taglist)
{
struct TagItem *tstate = taglist;
struct TagItem *tag;
while ((tag = NextTagItem(&tstate)))
{
switch (tag->ti_Tag)
{
case MYTAG_FOO:
Printf("MYTAG_FOO %ld\n", tag->ti_Data);
break;
case MYTAG_BAR:
Printf("MYTAG_BAR %ld\n", tag->ti_Data);
break;
}
}
}
-
@Piru
Thanks. That's more or less similar to the example they have on the NextTagItem autodoc IIRC.
In my case it's a bit more complicated because inside the function I want to make up an array from all the Tags of a certain type, so I have to first count how many there are before allocating the array (wich I could do easily by raising a counter everytime the case statement correponding to that Tag type is executed). But after allocating the array I have to copy the items to it and hence my question about going from one Tag type to the next one of the same type. That's why I'm almost decided to pass pointers to arrays in ti_Data instead of condensing all information in a TagArray.
BTW I'm using TAG_USER + 1, 2, ... as the start of my Tags, why the "+ 0xbad000" ?
Cheers