This looks like the construction of some sort of linked list.
If I had to guess, I'd say a1 is a linked list, a2 an array of elements to add, and a0 some kind of list of authorized values to add to the a1.
Line 7 looks like it checks to see if *v3 is registered in a0, and if that's the case it returns a pointer v4 somehow linked to it.
It then creates a new node using *(v3-1) and v4 and adds it to a1.
Line 14 the fact the only the first byte is checked could be explained by the fact that the first member of a ACTION_TO_TYPE structure is in fact a boolean.
A compiler will generally add padding bytes after a boolean to align the memory address of the next member properly, which could explain why 4 bytes are taken but only 1 is used.
With that hypothesis, I can suggest the following structures:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
struct ACTION_TO_TYPE
{
bool booleanValue;
int value;
int action;
};
struct SYS_DI_PROFILE_ITEM
{
int value;
SYS_DI_ADAPTER_OBJECT * actionPtr;
SYS_DI_PROFILE_ITEM * nextNode;
// constructor
SYS_DI_PROFILE_ITEM(val,actPtr) : value(val), actionPtr(actPtr), nextNode(NULL) {;}
};
struct SYS_DI_PROFILE
{
SYS_DI_PROFILE_ITEM * listHead;
/* ... */
};
|
And your code could be rewritten like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
SYS_ERROR MapProfile(SYS_DI_ADAPTER const * a0, SYS_DI_PROFILE * a1, ACTION_TO_TYPE const * a2)
{
a1->ClearItems();
for(int n = 0; a2[n].action != 0; n++)
{
SYS_DI_ADAPTER_OBJECT * actionPtr = a0->FindObject(a2[n].action, 0xFFFFFFu);
if(actionPtr != NULL)
{
SYS_DI_PROFILE_ITEM* newNode = new SYS_DI_PROFILE_ITEM(a2[n].value, actionPtr);
newNode->nextNode = a1->listHead;
a1->listHead = newNode;
}
else if( a2[n].booleanValue == true )
{
a1->ClearItems();
return SYS_ERROR_UNKNOWN;
}
}
return SYS_ERROR_NO;
}
|