SemysAnyReference

01
typedef struct tagSemysAnyReference
{
  ListEntry mListEntry;
  void *mpRef;
} SemysAnyReference;
02 Members:
  • mListEntry: List link.
  • mpRef: Pointing to the referenced data.
03 Occasionally, a structure needs to be in another list as well, other than its main list. Within the Semys Library, these situations are predictable.
04 Because additional list membership is predictable (often only as a temporary situation) and the required list links should not be extra allocated (and freed) for such a situation (because of managment overhead), an SemysAnyReference is always encountered as another member of the structure.

Example

05
struct tagTest
{
  ListEntry mListEntry;

  uint32 mMember1;
  SemysAnyReference mReference;
} Test;

ListEntry list1 = C_SEMYS_LIST_NULL, list2 = C_SEMYS_LIST_NULL, *le = 0;
Test test1;

/* List initialization */
ListInit(&list1);
ListInit(&list2);

/* Item initialization */
test1.mReference.mpRef = &test1;

/* Insert items */
ListPushBack(&list1, &test1.mListEntry);
ListPushBack(&list2, &test1.mReference.mListEntry);

/* Iterate (forward) through list */
le = list2.mpNext;
while (le != &list2)
{
  Test *pTest = (Test *)(((SemysAnyReference *)ListGetNext(&le))->mpRef);

  /* Remove entry */
  ListRemoveEntry(&pTest->mReference.mListEntry);
  ListRemoveEntry(&pTest->mListEntry);
}
06 Reference: SemysList.h
Implementation: Semys Library
See Also: List Sub-System, ListEntry

Goto: Main Page; This page is part of the Semys software documentation. See About: Documentation for details.