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