Skip to content

Commit 21ac4e7

Browse files
committed
adding external frameworks
1 parent 05bcd0d commit 21ac4e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3098
-0
lines changed

external_frameworks/.DS_Store

6 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Versions/Current/Headers
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Versions/Current/Resources
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Versions/Current/VVBasics
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
#import <TargetConditionals.h>
2+
#if TARGET_OS_IPHONE
3+
#import <UIKit/UIKit.h>
4+
#else
5+
#import <Cocoa/Cocoa.h>
6+
#endif
7+
#import <pthread.h>
8+
9+
10+
11+
/// Similar to NSMutableArray, but thread-safe. Internally, uses an NSMutableArray and a rwlock.
12+
/**
13+
\ingroup VVBasics
14+
This class exists because NSMutableArray is not thread-safe by default: if you call methods on it from two different threads at the same time, it will try to execute both, often crashing in the process. I found myself writing a lot of lock/array pairs, so simplified everything by combining them into a single class. MutLockArray has methods which allow you to work with a mutable array in a transparent and thread-safe manner- it will automatically establish the read-/write-locks necessary to perform the relevant task. By avoiding the "lock" methods, you can also work with the array without performing any locking- so you can get a read-/write-lock, perform a number of actions, and then unlock.
15+
16+
It is important to remember, when working with it, that MutLockArray is NOT a subclass of NSMutableArray; rather, it is a subclass of NSObject with an instance of an NSMutableArray and a rwlock for working with it safely. This means that you can't pass an instance of MutLockArray to anything which is expecting to be passed an NSMutableArray- internally, apple's frameworks will probably be doing some dark voodoo bullshit which will result in a spectacular failure. If you want to work with an actual NSMutableArray, check out the "array", "createArrayCopy", and "lockCreateArrayCopy" methods below.
17+
18+
...and remember- when looking for stuff in an NSMutableArray, the array will use the "isEqualTo:" comparator method, which is slower than comparing the address of two pointers. if you know the pointer address hasn't changed (if you're *not* working with NSStrings), use the "indexOfIdenticalPtr", "removeIdenticalPtr", etc. methods to work with the array.
19+
*/
20+
21+
@interface MutLockArray : NSObject <NSCopying> {
22+
NSMutableArray *array;
23+
pthread_rwlock_t arrayLock;
24+
}
25+
26+
/// Creates and returns an auto-released MutLockArray with a given capacity. The capacity may be 0.
27+
+ (id) arrayWithCapacity:(NSInteger)c;
28+
/// Inits and returns a MutLockArray with a given capacity; the capacity may be 0.
29+
- (id) initWithCapacity:(NSInteger)c;
30+
- (id) init;
31+
32+
/// Establishes a read-lock for the array; multiple read locks may exist simultaneously (if it's not changing, anything can look at the contents of the array). This method does not return until it has been able to get the lock.
33+
- (void) rdlock;
34+
- (BOOL) tryRdLock; // returns YES if i got a read-lock successfully!
35+
/// Establishes a write-lock for the array. Only one write-lock may exist at any given time, and all read-locks must be relinquished before the write-lock may be established (if you're going to change the array, nothing else can be changing or observing it).
36+
- (void) wrlock;
37+
/// Unlocks the array.
38+
- (void) unlock;
39+
40+
/// Returns the NSMutableArray with everything in it. This returns the actual array, so be careful- it's possible to do something which ISN'T threadsafe with this...
41+
- (NSMutableArray *) array;
42+
/// Returns an NSMutableArray which was created by calling "mutableCopy" on my array. Again, it's possible to do something which ISN'T threadsafe by calling this...
43+
- (NSMutableArray *) createArrayCopy;
44+
/// Returns an NSMutableArray which was created while a read-lock was established; this is threadsafe.
45+
- (NSMutableArray *) lockCreateArrayCopy;
46+
47+
/// Calls "addObject" on my array; not threadsafe.
48+
- (void) addObject:(id)o;
49+
/// Establishes a write-lock, then calls "addObject" on self; threadsafe.
50+
- (void) lockAddObject:(id)o;
51+
/// Calls "addObjectsFromArray" on my array; not threadsafe.
52+
- (void) addObjectsFromArray:(id)a;
53+
/// Establishes a write-lock, then calls "addObjectsFromArray" on self; threadsafe.
54+
- (void) lockAddObjectsFromArray:(id)a;
55+
/// Calls "addObjectsFromArray" on my array; not threadsafe.
56+
- (void) replaceWithObjectsFromArray:(id)a;
57+
/// Establishes a write-lock, then calls "replaceWithObjectsFromArray" on self; threadsafe.
58+
- (void) lockReplaceWithObjectsFromArray:(id)a;
59+
/// Calls "insertObject:atIndex:" on my array; not threadsafe.
60+
- (BOOL) insertObject:(id)o atIndex:(NSInteger)i;
61+
/// Establishes a write-lock, then calls "insertObject:atIndex:" on self; threadsafe.
62+
- (BOOL) lockInsertObject:(id)o atIndex:(NSInteger)i;
63+
/// Calls "removeAllObjects" on my array; not threadsafe.
64+
- (void) removeAllObjects;
65+
/// Establishes a write-lock, then calls "removeAllObjects" on self; threadsafe.
66+
- (void) lockRemoveAllObjects;
67+
/// Calls "objectAtIndex:0" on my array; not threadsafe.
68+
- (id) firstObject;
69+
/// Establishes a read-lock, then calls "firstObject" on self; threadsafe
70+
- (id) lockFirstObject;
71+
/// Calls "removeObjectAtIndex:0" on my array; not threadsafe
72+
- (void) removeFirstObject;
73+
/// Establishes a write-lock, then calls "removeFirstObject" on self; threadsafe.
74+
- (void) lockRemoveFirstObject;
75+
/// Calls "lastObject" on my array; not threadsafe.
76+
- (id) lastObject;
77+
/// Establishes a read-lock, then calls "lastObject" on self; threadsafe.
78+
- (id) lockLastObject;
79+
/// Calls "removeLastObject" on my array; not threadsafe.
80+
- (void) removeLastObject;
81+
/// Establishes a write-lock, then calls "removeLastObject" on self; threadsafe.
82+
- (void) lockRemoveLastObject;
83+
/// Calls "removeObject:" on my array; not threadsafe.
84+
- (void) removeObject:(id)o;
85+
/// Establishes a write-lock, then calls "removeObject:" on self; threadsafe.
86+
- (void) lockRemoveObject:(id)o;
87+
/// Calls "removeObjectAtIndex:" on my array; not threadsafe.
88+
- (void) removeObjectAtIndex:(NSInteger)i;
89+
/// Establishes a write-lock, then calls "removeObjectAtIndex:" on self; threadsafe.
90+
- (void) lockRemoveObjectAtIndex:(NSInteger)i;
91+
/// Calls "removeObjectsAtIndexes:" on my array; not threadsafe.
92+
- (void) removeObjectsAtIndexes:(NSIndexSet *)i;
93+
/// Establishes a write-lock, then calls "removeObjectsAtIndexes:" on self; threadsafe.
94+
- (void) lockRemoveObjectsAtIndexes:(NSIndexSet *)i;
95+
/// Calls "removeObjectsInArray:" on my array; not threadsafe.
96+
- (void) removeObjectsInArray:(NSArray *)otherArray;
97+
/// Establishes a write-lock, then calls "removeObjectsInArray:" on self; threadsafe.
98+
- (void) lockRemoveObjectsInArray:(NSArray *)otherArray;
99+
/// Calls "removeIdenticalPtrsInArray:" on my array; not threadsafe
100+
- (void) removeIdenticalPtrsInArray:(NSArray *)a;
101+
/// Establishes a write-lock, then calls "removeIdenticalPtrsInArray:" on self; threadsafe.
102+
- (void) lockRemoveIdenticalPtrsInArray:(NSArray *)a;
103+
104+
/// Calls "replaceObjectsAtIndexes:withObjects" on my array; not threadsafe.
105+
- (void) replaceObjectsAtIndexes:(NSIndexSet *)indexes withObjects:(NSArray *)objects;
106+
// Establishes a write-lock, then calls "replaceObjectsAtIndexes:withObjects on self; threadsafe
107+
- (void) lockReplaceObjectsAtIndexes:(NSIndexSet *)indexes withObjects:(NSArray *)objects;
108+
109+
/// Calls "valueForKey:" on my array; not threadsafe.
110+
- (id) valueForKey:(NSString *)key;
111+
/// Establishes a read-lock, then calls "valueForKey:" on self; threadsafe.
112+
- (id) lockValueForKey:(NSString *)key;
113+
114+
115+
/// Calls "containsObject:" on my array; not threadsafe.
116+
- (BOOL) containsObject:(id)o;
117+
/// Establishes a read-lock, then calls "containsObject:" on self; threadsafe.
118+
- (BOOL) lockContainsObject:(id)o;
119+
/// Calls "objectAtIndex:" on my array; not threadsafe.
120+
- (id) objectAtIndex:(NSInteger)i;
121+
/// Establishes a read-lock, then calls "objectAtIndex:" on self; threadsafe.
122+
- (id) lockObjectAtIndex:(NSInteger)i;
123+
/// Calls "objectsAtIndexes:" on my array; not threadsafe.
124+
- (NSArray *) objectsAtIndexes:(NSIndexSet *)indexes;
125+
/// Establishes a read-lock, then calls "objectsAtIndexes:" on self; threadsafe.
126+
- (NSArray *) lockObjectsAtIndexes:(NSIndexSet *)indexes;
127+
/// Calls "indexOfObject:" on my array; not threadsafe.
128+
- (NSInteger) indexOfObject:(id)o;
129+
/// Establishes a read-lock, then calls "indexOfObject:" on self; threadsafe.
130+
- (NSInteger) lockIndexOfObject:(id)o;
131+
132+
133+
/// Enumerates through my array- compares the address of each item in the array to the passed pointer. Unlike NSMutableArray, this method does NOT call isEqualTo:, it's just a simple == operator.
134+
- (BOOL) containsIdenticalPtr:(id)o;
135+
/// Establishes a read-lock, then calls "containsIdenticalPtr:" on self; threadsafe.
136+
- (BOOL) lockContainsIdenticalPtr:(id)o;
137+
/// Enumerates through my array- compares the address of each item in the array to the passed pointer. Unlike NSMutableArray, this method does NOT call isEqualTo:, it's just a simple == operator.
138+
- (long) indexOfIdenticalPtr:(id)o;
139+
/// Establishes a read-lock, then calls "indexOfIdenticalPtr:" on self; threadsafe.
140+
- (long) lockIndexOfIdenticalPtr:(id)o;
141+
/// Locates an item in my array by enumerating through it and comparing the address of each item in the array to the passed ptr, and then deletes the matching item from the array; not threadsafe.
142+
- (void) removeIdenticalPtr:(id)o;
143+
/// Establishes a write-lock, then calls "removeIdenticalPtr:" on self; threadsafe.
144+
- (void) lockRemoveIdenticalPtr:(id)o;
145+
146+
// Calls "filteredArrayUsingPredicate:" on my array; not threadsafe
147+
- (NSArray *)filteredArrayUsingPredicate:(NSPredicate *)predicate;
148+
// Establishes a read-lock, then calls "filteredArrayUsingPredicate:" on self; threadsafe
149+
- (NSArray *) lockFilteredArrayUsingPredicate:(NSPredicate *)predicate;
150+
151+
/// Calls "makeObjectsPerformSelector:" on my array; not threadsafe.
152+
- (void) makeObjectsPerformSelector:(SEL)s;
153+
/// Establishes a read-lock, then calls "makeObjectsPerformSelector:" on self; threadsafe.
154+
- (void) lockMakeObjectsPerformSelector:(SEL)s;
155+
/// Calls "makeObjectsPerformSelector:withObject:" on my array; not threadsafe.
156+
- (void) makeObjectsPerformSelector:(SEL)s withObject:(id)o;
157+
/// Establishes a read-lock, then calls "makeObjectsPerformSelector:withObject:" on self; threadsafe.
158+
- (void) lockMakeObjectsPerformSelector:(SEL)s withObject:(id)o;
159+
160+
161+
162+
/*
163+
- (void) makeCopyPerformSelector:(SEL)s;
164+
- (void) lockMakeCopyPerformSelector:(SEL)s;
165+
- (void) makeCopyPerformSelector:(SEL)s withObject:(id)o;
166+
- (void) lockMakeCopyPerformSelector:(SEL)s withObject:(id)o;
167+
*/
168+
169+
170+
171+
/// Calls "sortUsingSelector:" on my array; not threadsafe.
172+
- (void) sortUsingSelector:(SEL)s;
173+
/// Establishes a write-lock, then calls "sortUsingSelector:" on self; threadsafe.
174+
- (void) lockSortUsingSelector:(SEL)s;
175+
176+
/// Calls "sortUsingDescriptors:" on my array; not threadsafe.
177+
- (void) sortUsingDescriptors:(NSArray *)descriptors;
178+
/// Establishes a write-lock, then calls "sortUsingDescriptors:" on self; threadsafe.
179+
- (void) lockSortUsingDescriptors:(NSArray *)descriptors;
180+
181+
- (void) sortUsingComparator:(NSComparator)c;
182+
- (void) lockSortUsingComparator:(NSComparator)c;
183+
184+
- (NSEnumerator *) objectEnumerator;
185+
- (NSEnumerator *) reverseObjectEnumerator;
186+
- (long) count;
187+
- (long) lockCount;
188+
189+
@end
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#import <TargetConditionals.h>
2+
#if TARGET_OS_IPHONE
3+
#import <UIKit/UIKit.h>
4+
#else
5+
#import <Cocoa/Cocoa.h>
6+
#endif
7+
#import <pthread.h>
8+
9+
10+
11+
/// MutLockDict is a thread-safe version of NSMutableDictionary.
12+
/*!
13+
\ingroup VVBasics
14+
This class exists because NSMutableDictionary is not thread-safe by default: if you call methods on it from two different threads at the same time, it will try to execute both, often crashing in the process. This class has methods which allow you to work with a mutable dictionary in a transparent and thread-safe manner.
15+
*/
16+
17+
@interface MutLockDict : NSObject {
18+
NSMutableDictionary *dict;
19+
pthread_rwlock_t dictLock;
20+
}
21+
22+
/// functions similarly to the NSDictionary method
23+
+ (id) dictionaryWithCapacity:(NSInteger)c;
24+
/// functions similarly to the NSDictionary method- creates and returns an auto-released instance of MutLockDict populated with the contents of the passed dictionary
25+
+ (id) dictionaryWithDict:(NSDictionary *)d;
26+
/// functions similarly to the NSDictionary method- inits a MutLockDict with the supplied capacity
27+
- (id) initWithCapacity:(NSInteger)c;
28+
29+
/// blocks until it can establish a read-lock on the array, and then returns. try to avoid calling this- using the built-in methods (which unlock before they return) is generally preferable/safer!
30+
- (void) rdlock;
31+
/// blocks until it can establish a write-lock on the array, and then returns. try to avoid calling this- using the built-in methods (which unlock before they return) is generally preferable/safer!
32+
- (void) wrlock;
33+
/// unlocks and returns immediately
34+
- (void) unlock;
35+
36+
/// returns the NSMutableDictionary used as the basis for this class- useful if you want to use fast iteration/that sort of thing
37+
- (NSMutableDictionary *) dict;
38+
/// creates a mutable, autoreleased copy of the dict and returns it. be careful, this method isn't threadsafe!
39+
- (NSMutableDictionary *) createDictCopy;
40+
/// creates a mutable, autoreleased copy of the dict and returns it. this method is threadsafe.
41+
- (NSMutableDictionary *) lockCreateDictCopy;
42+
43+
/// functions similar to the NSDictionary method, but checks to make sure you aren't trying to insert a nil value or use a nil key. not threadsafe!
44+
- (void) setObject:(id)o forKey:(NSString *)s;
45+
/// establishes a write-lock, then calls setObject:forKey:. threadsafe.
46+
- (void) lockSetObject:(id)o forKey:(NSString *)s;
47+
/// functions similar to the NSDictionary method- not threadsafe
48+
- (void) setValue:(id)v forKey:(NSString *)s;
49+
/// establishes a write-lock, then calls setValue:forKey:. threadsafe.
50+
- (void) lockSetValue:(id)v forKey:(NSString *)s;
51+
/// removes all objects from the underlying dict- not threadsafe
52+
- (void) removeAllObjects;
53+
/// establishes a write-lock, then removes all objects from the underlying dict. threadsafe.
54+
- (void) lockRemoveAllObjects;
55+
/// returns the object stored in the underlying dict at the passed key- not threadsafe
56+
- (id) objectForKey:(NSString *)k;
57+
/// establihes a read-lock, then returns the object stored in the underlying dict at the passed key. threadsafe.
58+
- (id) lockObjectForKey:(NSString *)k;
59+
/// attempts to remove any object stored in the underlying dict at the passed key- not threadsafe.
60+
- (void) removeObjectForKey:(NSString *)k;
61+
/// establishes a write-lock, then removes any object stored in the underlying dict at the passed key. threadsafe.
62+
- (void) lockRemoveObjectForKey:(NSString *)k;
63+
/// adds all entries from the passed dict to the receiver's underlying dictionary- not threadsafe.
64+
- (void) addEntriesFromDictionary:(NSDictionary *)otherDictionary;
65+
/// establishes a write-lock, then calls "addEntriesFromDictionary:". threadsafe.
66+
- (void) lockAddEntriesFromDictionary:(NSDictionary *)otherDictionary;
67+
/// returns an array with all the keys from the underlying dictionary- not threadsafe
68+
- (NSArray *) allKeys;
69+
/// establishes a read-lock, then calls "allKeys". threadsafe.
70+
- (NSArray *) lockAllKeys;
71+
/// returns an array with all the values from the underlying dictionary- not threadsafe.
72+
- (NSArray *) allValues;
73+
/// establishes a read-lock, then calls "allValues". threadsafe.
74+
- (NSArray *) lockAllValues;
75+
76+
/// calls "makeObjectsPerformSelector" on the array of values returned by the underlying dictionary- not threadsafe.
77+
- (void) makeObjectsPerformSelector:(SEL)s;
78+
/// establishes a read-lock, then calls "makeObjectsPerformSelector:". threadsafe.
79+
- (void) lockMakeObjectsPerformSelector:(SEL)s;
80+
81+
/// returns the number of objects in the underlying dictionary- not threadsafe.
82+
- (NSInteger) count;
83+
/// establishes a read-lock, then returns the number of objects in the underlying dictionary. threadsafe.
84+
- (NSInteger) lockCount;
85+
86+
@end
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#import <TargetConditionals.h>
2+
#if TARGET_OS_IPHONE
3+
#import <UIKit/UIKit.h>
4+
#else
5+
#import <Cocoa/Cocoa.h>
6+
#endif
7+
8+
#import "MutLockArray.h"
9+
#import "ObjectHolder.h"
10+
11+
12+
13+
/// Subclass of MutLockArray; this class does NOT retain the objects in its array!
14+
/**
15+
\ingroup VVBasics
16+
this class exists because i frequently find myself in situations where i want to add an instance of an object to an array/dict/[any class which retains the passed instance], but i don't actually want the item to be retained.
17+
18+
Instead of adding (and therefore retaining) objects to an array like my superclass, this class makes an ObjectHolder for objects which are added to it (so they don't get retained), and adds the ObjectHolder to me. when other classes ask me for the index of an object, or ask for the object at a particular index, i'll find the relevant ObjectHolder and then return the object it's storing.
19+
*/
20+
21+
@interface MutNRLockArray : MutLockArray {
22+
}
23+
24+
+ (id) arrayWithCapacity:(NSInteger)c;
25+
26+
- (NSMutableArray *) createArrayCopy;
27+
- (NSMutableArray *) lockCreateArrayCopyFromObjects;
28+
- (NSMutableArray *) createArrayCopyFromObjects;
29+
- (void) addObject:(id)o;
30+
- (void) addObjectsFromArray:(id)a;
31+
- (void) replaceWithObjectsFromArray:(id)a;
32+
- (BOOL) insertObject:(id)o atIndex:(NSInteger)i;
33+
- (id) lastObject;
34+
- (void) removeObject:(id)o;
35+
- (BOOL) containsObject:(id)o;
36+
- (id) objectAtIndex:(NSInteger)i;
37+
- (NSArray *) objectsAtIndexes:(NSIndexSet *)indexes;
38+
- (NSInteger) indexOfObject:(id)o;
39+
- (BOOL) containsIdenticalPtr:(id)o;
40+
- (long) indexOfIdenticalPtr:(id)o;
41+
- (void) removeIdenticalPtr:(id)o;
42+
43+
// these methods exist because the lookup cost for an ObjectHolder can be significant for high-performance applications- these methods get the object from the ObjectHolder and call the method directly on it!
44+
- (void) bruteForceMakeObjectsPerformSelector:(SEL)s;
45+
- (void) lockBruteForceMakeObjectsPerformSelector:(SEL)s;
46+
- (void) bruteForceMakeObjectsPerformSelector:(SEL)s withObject:(id)o;
47+
- (void) lockBruteForceMakeObjectsPerformSelector:(SEL)s withObject:(id)o;
48+
49+
- (void) lockPurgeEmptyHolders;
50+
- (void) purgeEmptyHolders;
51+
52+
53+
@end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#import <TargetConditionals.h>
2+
#if TARGET_OS_IPHONE
3+
#import <UIKit/UIKit.h>
4+
#else
5+
#import <Cocoa/Cocoa.h>
6+
#endif
7+
8+
#import "MutLockDict.h"
9+
#import "ObjectHolder.h"
10+
11+
12+
13+
/// Subclass of MutLockDict; this class does NOT retain the objects in its array!
14+
/**
15+
\ingroup VVBasics
16+
this class exists because i frequently find myself in situations where i want to add an instance of an object to an array/dict/[any class which retains the passed instance], but i don't actually want the item to be retained.
17+
18+
Instead of adding (and therefore retaining) objects to an array like my superclass, this class makes an ObjectHolder for objects which are added to it (so they don't get retained), and adds the ObjectHolder to me. when other classes ask me for the index of an object, or ask for the object at a particular index, i'll find the relevant ObjectHolder and then return the object it's storing.
19+
*/
20+
21+
22+
@interface MutNRLockDict : MutLockDict {
23+
24+
}
25+
26+
27+
- (void) setObject:(id)o forKey:(NSString *)s;
28+
- (void) setValue:(id)v forKey:(NSString *)s;
29+
- (id) objectForKey:(NSString *)k;
30+
- (void) addEntriesFromDictionary:(id)otherDictionary;
31+
- (NSArray *) allValues;
32+
33+
@end

0 commit comments

Comments
 (0)