forked from robbiehanson/XMPPFramework
/
DDList.h
61 lines (48 loc) · 1.5 KB
/
DDList.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#import <Foundation/Foundation.h>
@class DDListEnumerator;
struct DDListNode {
void * element;
struct DDListNode * prev;
struct DDListNode * next;
};
typedef struct DDListNode DDListNode;
/**
* The DDList class is designed as a simple list class.
* It can store objective-c objects as well as non-objective-c pointers.
* It does not retain objective-c objects as it treats all elements as simple pointers.
*
* Example usages:
* - Storing a list of delegates, where there is a desire to not retain the individual delegates.
* - Storing a list of dispatch timers, which are not NSObjects, and cannot be stored in NSCollection classes.
*
* This class is NOT thread-safe.
* It is designed to be used within a thread-safe context (e.g. within a single dispatch_queue).
**/
@interface DDList : NSObject <NSFastEnumeration>
{
DDListNode *listHead;
DDListNode *listTail;
}
- (void)add:(void *)element;
- (void)remove:(void *)element;
- (void)removeAll:(void *)element;
- (void)removeAllElements;
- (BOOL)contains:(void *)element;
- (NSUInteger)count;
/**
* The enumerators return a snapshot of the list that can be enumerated.
* The list can later be altered (elements added/removed) without affecting enumerator snapshots.
**/
- (DDListEnumerator *)listEnumerator;
- (DDListEnumerator *)reverseListEnumerator;
@end
@interface DDListEnumerator : NSObject
{
NSUInteger numElements;
NSUInteger currentElementIndex;
void **elements;
}
- (NSUInteger)numTotal;
- (NSUInteger)numLeft;
- (void *)nextElement;
@end