1 /*---------------------------------------------------------------------------* 2 Project: MEM library 3 File: list.h 4 Programmers: Takano Makoto 5 6 Copyright 2005 Nintendo. All rights reserved. 7 8 These coded instructions, statements, and computer programs contain 9 proprietary information of Nintendo of America Inc. and/or Nintendo 10 Company Ltd., and are protected by Federal copyright law. They may 11 not be disclosed to third parties or copied or duplicated in any form, 12 in whole or in part, without the prior written consent of Nintendo. 13 *---------------------------------------------------------------------------*/ 14 15 #ifndef MEM_LIST_H__ 16 #define MEM_LIST_H__ 17 18 #include <stddef.h> 19 #include <revolution/types.h> 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 /*---------------------------------------------------------------------------* 26 Name: MEMLink 27 28 Description: Node structure for two-way link list. This structure is stored in the list structure as a member of the structure to be linked. 29 30 *---------------------------------------------------------------------------*/ 31 typedef struct 32 { 33 void* prevObject; // Pointer to the previous linked object 34 void* nextObject; // Pointer to the next linked object 35 36 } MEMLink; 37 38 39 /*---------------------------------------------------------------------------* 40 Name: MEMList 41 42 Description: Two-way link list structure 43 *---------------------------------------------------------------------------*/ 44 typedef struct 45 { 46 void* headObject; // Pointer for the object linked to the head 47 void* tailObject; // Pointer for the object linked to the end 48 u16 numObjects; // Number of objects linked to the list 49 u16 offset; // Offset for NNSFndLink type structure member 50 51 } MEMList; 52 53 54 /*---------------------------------------------------------------------------* 55 Name: MEM_INIT_LIST 56 57 Description: Macro to initialize list structure. Actual initialization is performed by the MEMInitList() function. 58 59 60 This macro finds the offset using the offsetof macro based on the name of the specified structure and the link type member variable name and then passes that offset to the InitList function. 61 62 63 64 Arguments: list: Pointer to the link structure. 65 structName: Structure name of object you wish to link to the list. 66 linkName: The Link type member variable name used to link this object. 67 68 69 Returns: None. 70 *---------------------------------------------------------------------------*/ 71 72 #define MEM_INIT_LIST(list, structName, linkName) \ 73 MEMInitList(list, offsetof(structName, linkName)) 74 75 76 /*---------------------------------------------------------------------------* 77 Function Prototypes 78 79 *---------------------------------------------------------------------------*/ 80 81 void MEMInitList( 82 MEMList* list, 83 u16 offset); 84 85 void MEMAppendListObject( 86 MEMList* list, 87 void* object); 88 89 void MEMPrependListObject( 90 MEMList* list, 91 void* object); 92 93 void MEMInsertListObject( 94 MEMList* list, 95 void* target, 96 void* object); 97 98 void MEMRemoveListObject( 99 MEMList* list, 100 void* object); 101 102 void* MEMGetNextListObject( 103 MEMList* list, 104 void* object); 105 106 void* MEMGetPrevListObject( 107 MEMList* list, 108 void* object); 109 110 void* MEMGetNthListObject( 111 MEMList* list, 112 u16 index); 113 114 115 #ifdef __cplusplus 116 } /* extern "C" */ 117 #endif 118 119 /* MEM_LIST_H__ */ 120 #endif 121