Permalink
Browse files

Add target/action queue. Misc. updates.

  • Loading branch information...
1 parent ddb7c11 commit 0bf3810c600a62f1bfebd9593bfe869cba188fa3 @ldandersen committed Sep 10, 2012
@@ -4,34 +4,21 @@
// Created by Buzz Andersen on 2/19/11.
// Copyright 2011 System of Touch. All rights reserved.
//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
#import <Foundation/Foundation.h>
@interface NSMutableString (STAdditions)
+// Predicates
- (void)appendPredicateCondition:(NSString *)predicateCondition;
+- (void)appendPredicateConditionWithOperator:(NSString *)inOperator string:(NSString *)inPredicateConditionString;
+
+- (void)appendPredicateConditionWithFormat:(NSString *)inPredicateConditionString, ...;
+- (void)appendPredicateConditionWithOperator:(NSString *)inOperator format:(NSString *)inPredicateCondition, ...;
+- (void)appendPredicateConditionWithOperator:(NSString *)inOperator format:(NSString *)inPredicateCondition arguments:(va_list)inArguments;
+
+// Paths
- (void)appendPathComponent:(NSString *)inPathComponent;
- (void)appendPathComponent:(NSString *)inPathComponent queryString:(NSString *)inQueryString;
- (void)appendPathComponents:(NSArray *)inPathComponents;
@@ -4,50 +4,70 @@
// Created by Buzz Andersen on 2/19/11.
// Copyright 2011 System of Touch. All rights reserved.
//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
#import "STUtils.h"
@implementation NSMutableString (STAdditions)
-- (void)appendPredicateCondition:(NSString *)predicateCondition;
+#pragma mark Predicates
+
+- (void)appendPredicateCondition:(NSString *)inPredicateConditionString;
+{
+ [self appendPredicateConditionWithOperator:@"AND" string:inPredicateConditionString];
+}
+
+- (void)appendPredicateConditionWithOperator:(NSString *)inOperator string:(NSString *)inPredicateConditionString;
{
if (self.length) {
- [self appendString:@" AND "];
+ [self appendFormat:@" %@ ", inOperator];
}
- [self appendString:predicateCondition];
+ [self appendString:inPredicateConditionString];
+}
+
+- (void)appendPredicateConditionWithFormat:(NSString *)inPredicateConditionString, ...;
+{
+ va_list args;
+ va_start(args, inPredicateConditionString);
+
+ [self appendPredicateConditionWithOperator:@"AND" format:inPredicateConditionString arguments:args];
+
+ va_end(args);
}
+- (void)appendPredicateConditionWithOperator:(NSString *)inOperator format:(NSString *)inPredicateConditionString, ...;
+{
+ va_list args;
+ va_start(args, inPredicateConditionString);
+
+ [self appendPredicateConditionWithOperator:inOperator format:inPredicateConditionString arguments:args];
+
+ va_end(args);
+}
+
+- (void)appendPredicateConditionWithOperator:(NSString *)inOperator format:(NSString *)inPredicateConditionString arguments:(va_list)inArguments;
+{
+ NSString *formattedString = [[NSString alloc] initWithFormat:inPredicateConditionString arguments:inArguments];
+ [self appendPredicateConditionWithOperator:inOperator string:formattedString];
+ [formattedString release];
+}
+
+#pragma mark Paths
+
- (void)appendPathComponent:(NSString *)inPathComponent;
{
[self appendPathComponent:inPathComponent queryString:nil];
}
- (void)appendPathComponent:(NSString *)inPathComponent queryString:(NSString *)inQueryString;
{
- if (!inPathComponent.length || [inPathComponent isEqualToString:@"/"]) {
+ if (!inPathComponent.length) {
+ return;
+ }
+
+ if ([inPathComponent isEqualToString:@"/"]) {
+ [self appendString:inPathComponent];
return;
}
@@ -1,40 +1,19 @@
//
// NSOutputStream+STAdditions.h
+// Hipflask
//
// Created by Buzz Andersen on 4/10/12.
// Copyright (c) 2012 System of Touch. All rights reserved.
//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-
#import <Foundation/Foundation.h>
@interface NSOutputStream (STAdditions)
-- (void)writeUTF8StringWithFormat:(NSString *)inString, ...;
-- (void)writeUTF8String:(NSString *)inUTF8String;
-- (void)writeString:(NSString *)inString usingEncoding:(NSStringEncoding)inEncoding;
-- (void)writeData:(NSData *)inData;
-- (void)writeFileDataAtPath:(NSString *)inPath withBufferSize:(NSInteger)inBufferSize;
+- (NSInteger)writeUTF8StringWithFormat:(NSString *)inString, ...;
+- (NSInteger)writeUTF8String:(NSString *)inUTF8String;
+- (NSInteger)writeString:(NSString *)inString usingEncoding:(NSStringEncoding)inEncoding;
+- (NSInteger)writeData:(NSData *)inData;
+- (NSInteger)writeFileDataAtPath:(NSString *)inPath withBufferSize:(NSInteger)inBufferSize;
@end
@@ -1,88 +1,82 @@
//
// NSOutputStream+STAdditions.m
-// Hipflask
//
// Created by Buzz Andersen on 4/10/12.
// Copyright (c) 2012 System of Touch. All rights reserved.
//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
#import "STUtils.h"
@implementation NSOutputStream (STAdditions)
-- (void)writeUTF8StringWithFormat:(NSString *)inString, ...;
+- (NSInteger)writeUTF8StringWithFormat:(NSString *)inString, ...;
{
va_list args;
va_start(args, inString);
NSString *formattedString = [[NSString alloc] initWithFormat:inString arguments:args];
- [self writeUTF8String:formattedString];
+ NSInteger bytesWritten = [self writeUTF8String:formattedString];
[formattedString release];
va_end(args);
+
+ return bytesWritten;
}
-- (void)writeUTF8String:(NSString *)inUTF8String;
+- (NSInteger)writeUTF8String:(NSString *)inUTF8String;
{
- [self writeString:inUTF8String usingEncoding:NSUTF8StringEncoding];
+ return [self writeString:inUTF8String usingEncoding:NSUTF8StringEncoding];
}
-- (void)writeString:(NSString *)inString usingEncoding:(NSStringEncoding)inEncoding;
+- (NSInteger)writeString:(NSString *)inString usingEncoding:(NSStringEncoding)inEncoding;
{
NSUInteger byteLength = [inString lengthOfBytesUsingEncoding:inEncoding];
-
if (!byteLength) {
- return;
+ return -1;
}
- char *buffer = malloc(byteLength);
+ uint8_t *buffer = malloc(byteLength);
+ NSInteger bytesWritten = 0;
- if ([inString getBytes:buffer maxLength:byteLength usedLength:NULL encoding:inEncoding options:NSStringEncodingConversionExternalRepresentation range:NSMakeRange(0,byteLength) remainingRange:NULL]) {
- [self write:(const uint8_t *)buffer maxLength:byteLength];
+ size_t usedByteLength;
+ if ([inString getBytes:buffer maxLength:byteLength usedLength:&usedByteLength encoding:inEncoding options:NSStringEncodingConversionExternalRepresentation range:NSMakeRange(0,byteLength) remainingRange:NULL]) {
+ if (!self.hasSpaceAvailable) {
+ NSLog(@"Output stream has no space available.");
+ }
+
+ bytesWritten = [self write:(const uint8_t *)buffer maxLength:usedByteLength];
}
free(buffer);
+
+ return bytesWritten;
}
-- (void)writeData:(NSData *)inData;
+- (NSInteger)writeData:(NSData *)inData;
{
- [self write:[inData bytes] maxLength:inData.length];
+ return [self write:[inData bytes] maxLength:inData.length];
}
-- (void)writeFileDataAtPath:(NSString *)inPath withBufferSize:(NSInteger)inBufferSize;
+- (NSInteger)writeFileDataAtPath:(NSString *)inPath withBufferSize:(NSInteger)inBufferSize;
{
if (!inPath.length || ![[NSFileManager defaultManager] fileExistsAtPath:inPath]) {
- return;
+ return -1;
}
- NSInputStream *fileInputStream = [NSInputStream inputStreamWithFileAtPath:inPath];
+ /*NSInputStream *fileInputStream = [NSInputStream inputStreamWithFileAtPath:inPath];
+ [fileInputStream open];
+
+ NSInteger bytesWritten = 0;
while ([fileInputStream hasBytesAvailable]) {
uint8_t fileBuffer[inBufferSize];
[fileInputStream read:fileBuffer maxLength:inBufferSize];
- [self write:fileBuffer maxLength:inBufferSize];
+ bytesWritten = [self write:fileBuffer maxLength:inBufferSize];
}
+
+ [fileInputStream close];*/
+
+ return [self writeData:[NSData dataWithContentsOfFile:inPath]];
}
@end
@@ -4,27 +4,6 @@
// Created by Buzz Andersen on 12/29/09.
// Copyright 2011 System of Touch. All rights reserved.
//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
#import <Foundation/Foundation.h>
@@ -4,27 +4,6 @@
// Created by Buzz Andersen on 12/29/09.
// Copyright 2011 System of Touch. All rights reserved.
//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
#import "STUtils.h"
View
@@ -0,0 +1,30 @@
+//
+// STTargetActionQueue.h
+//
+// Created by Buzz Andersen on 6/28/12.
+// Copyright (c) 2012 System of Touch. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+
+@interface STTargetActionQueue : NSObject
+
+- (NSArray *)allKeys;
+- (void)addTarget:(id)inTarget action:(SEL)inAction forKey:(NSString *)inKey;
+- (void)removeTarget:(id)inTarget;
+- (void)removeTarget:(id)inTarget forKey:(NSString *)inKey;
+- (void)performActionsForKey:(NSString *)inKey;
+- (void)performActionsForKey:(NSString *)inKey withObject:(NSDictionary *)inObject;
+
+@end
+
+
+@interface STTargetAction : NSObject
+
+@property (nonatomic, retain) NSString *key;
+@property (nonatomic, assign) id target;
+@property (nonatomic, assign) SEL action;
+@property (nonatomic, copy) void(^actionBlock)();
+
+@end
Oops, something went wrong.

0 comments on commit 0bf3810

Please sign in to comment.