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 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 23 #include <stddef.h> 24 #include <revolution/types.h> 25 26 27 /*---------------------------------------------------------------------------* 28 Name: MEMLink 29 30 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. 31 32 *---------------------------------------------------------------------------*/ 33 typedef struct 34 { 35 void* prevObject; // Pointer to the previous linked object 36 void* nextObject; // Pointer to the next linked object 37 38 } MEMLink; 39 40 41 /*---------------------------------------------------------------------------* 42 Name: MEMList 43 44 Description: Two-way link list structure 45 *---------------------------------------------------------------------------*/ 46 typedef struct 47 { 48 void* headObject; // Pointer for the object linked to the head 49 void* tailObject; // Pointer for the object linked to the end 50 u16 numObjects; // Number of objects linked to the list 51 u16 offset; // Offset for NNSFndLink type structure member 52 53 } MEMList; 54 55 56 /*---------------------------------------------------------------------------* 57 Name: MEM_INIT_LIST 58 59 Description: Macro to initialize list structure. Actual initialization is performed by the MEMInitList() function. 60 61 62 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. 63 64 65 66 Arguments: list: Pointer to the link structure. 67 structName: Structure name of object you wish to link to the list. 68 linkName: The Link type member variable name used to link this object. 69 70 71 Returns: None. 72 *---------------------------------------------------------------------------*/ 73 74 #define MEM_INIT_LIST(list, structName, linkName) \ 75 MEMInitList(list, offsetof(structName, linkName)) 76 77 78 /*---------------------------------------------------------------------------* 79 Function Prototypes 80 81 *---------------------------------------------------------------------------*/ 82 83 void MEMInitList( 84 MEMList* list, 85 u16 offset); 86 87 void MEMAppendListObject( 88 MEMList* list, 89 void* object); 90 91 void MEMPrependListObject( 92 MEMList* list, 93 void* object); 94 95 void MEMInsertListObject( 96 MEMList* list, 97 void* target, 98 void* object); 99 100 void MEMRemoveListObject( 101 MEMList* list, 102 void* object); 103 104 void* MEMGetNextListObject( 105 MEMList* list, 106 void* object); 107 108 void* MEMGetPrevListObject( 109 MEMList* list, 110 void* object); 111 112 void* MEMGetNthListObject( 113 MEMList* list, 114 u16 index); 115 116 117 #ifdef __cplusplus 118 } /* extern "C" */ 119 #endif 120 121 /* MEM_LIST_H__ */ 122 #endif 123