Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow OSC arrays to deduce their own type

  • Loading branch information...
commit 38ce122de96a4c9da4d8ba17dfc3adec50eba7bc 1 parent 89f3c8e
Jonathan del Strother authored
Showing with 39 additions and 17 deletions.
  1. +39 −17 OSCExtensions.m
View
56 OSCExtensions.m
@@ -41,12 +41,12 @@ -(void)addNSValue:(id)newValue withBias:(BBOSCType)bias {
}
}
--(id)readNSValueFromPosition:(NSUInteger*)pos withBias:(BBOSCType)bias {
+-(id)readNSValueFromPosition:(NSUInteger*)pos withBias:(BBOSCType)bias forceType:(BOOL)forceType{
if (bias >= BBOSCTypeArrayOfInt) {
NSMutableArray* result = [NSMutableArray array];
while(*pos<self.valueCount) {
- id subvalue = [self readNSValueFromPosition:pos withBias:bias-4];
+ id subvalue = [self readNSValueFromPosition:pos withBias:bias-4 forceType:NO]; // Treat the arrays as loosely typed so strings don't get mangled
if (!subvalue)
break;
[result addObject:subvalue];
@@ -54,8 +54,6 @@ -(id)readNSValueFromPosition:(NSUInteger*)pos withBias:(BBOSCType)bias {
return result;
}
- id outputValue = nil;
-
OSCValue* oscValue;
if (*pos >= self.valueCount)
oscValue = nil;
@@ -67,20 +65,44 @@ -(id)readNSValueFromPosition:(NSUInteger*)pos withBias:(BBOSCType)bias {
if ([oscValue type] == OSCValNil)
return [NSNull null];
- switch (bias) {
- case BBOSCTypeBool:
- outputValue = [NSNumber numberWithBool:[oscValue boolValue]];
- break;
- case BBOSCTypeInt:
- outputValue = [NSNumber numberWithInt:[oscValue intValue]];
- break;
- case BBOSCTypeFloat:
- outputValue = [NSNumber numberWithFloat:[oscValue floatValue]];
- break;
- case BBOSCTypeString:
- outputValue = [oscValue stringValue];
- break;
+
+ id outputValue = nil;
+ if (forceType) { // Use the 'bias' type, assume the user knows what he's doing.
+ switch (bias) {
+ case BBOSCTypeBool:
+ outputValue = [NSNumber numberWithBool:[oscValue boolValue]];
+ break;
+ case BBOSCTypeInt:
+ outputValue = [NSNumber numberWithInt:[oscValue intValue]];
+ break;
+ case BBOSCTypeFloat:
+ outputValue = [NSNumber numberWithFloat:[oscValue floatValue]];
+ break;
+ case BBOSCTypeString:
+ outputValue = [oscValue stringValue];
+ break;
+ }
+ } else { // Use the OSC type
+ switch([oscValue type]) {
+ case OSCValBool:
+ outputValue = [NSNumber numberWithBool:[oscValue boolValue]];
+ break;
+ case OSCValInt:
+ outputValue = [NSNumber numberWithInt:[oscValue intValue]];
+ break;
+ case OSCValFloat:
+ outputValue = [NSNumber numberWithFloat:[oscValue floatValue]];
+ break;
+ case OSCValString:
+ outputValue = [oscValue stringValue];
+ break;
+ }
}
+
return outputValue;
}
+
+-(id)readNSValueFromPosition:(NSUInteger*)pos withBias:(BBOSCType)bias {
+ return [self readNSValueFromPosition:pos withBias:bias forceType:YES];
+}
@end
Please sign in to comment.
Something went wrong with that request. Please try again.