Permalink
Browse files

Added 'String To Data' patch to convert a string to UTF8-encoded byte…

…s. [#2170]
  • Loading branch information...
1 parent a31cc5f commit b8eecc68269b67b63bbc8c3c29e6e129984e111e @jlstrecker jlstrecker committed May 1, 2012
Showing with 131 additions and 0 deletions.
  1. +14 −0 DTStringToDataPatch.h
  2. +46 −0 DTStringToDataPatch.m
  3. +41 −0 DTStringToDataPatch.xml
  4. +14 −0 DataTools.xcodeproj/project.pbxproj
  5. +2 −0 DataToolsPrincipal.m
  6. +14 −0 TestDTConvert.m
View
14 DTStringToDataPatch.h
@@ -0,0 +1,14 @@
+@interface DTStringToDataPatch : QCPatch
+{
+ QCStringPort *inputString;
+ QCVirtualPort *outputRawData;
+}
+
++(BOOL)isSafe;
++(BOOL)allowsSubpatchesWithIdentifier:(id)identifier;
++(QCPatchExecutionMode)executionModeWithIdentifier:(id)identifier;
++(QCPatchTimeMode)timeModeWithIdentifier:(id)identifier;
+-(id)initWithIdentifier:(id)identifier;
+-(BOOL)execute:(QCOpenGLContext*)context time:(double)time arguments:(NSDictionary*)arguments;
+
+@end
View
46 DTStringToDataPatch.m
@@ -0,0 +1,46 @@
+#import "DTStringToDataPatch.h"
+
+@implementation DTStringToDataPatch
+
++(BOOL)isSafe
+{
+ return NO;
+}
+
++(BOOL)allowsSubpatchesWithIdentifier:(id)identifier
+{
+ return NO;
+}
+
++(QCPatchExecutionMode)executionModeWithIdentifier:(id)identifier
+{
+ return kQCPatchExecutionModeProcessor;
+}
+
++(QCPatchTimeMode)timeModeWithIdentifier:(id)identifier
+{
+ return kQCPatchTimeModeNone;
+}
+
+-(id)initWithIdentifier:(id)identifier
+{
+ if(self = [super initWithIdentifier:identifier])
+ {
+ [[self userInfo] setObject:@"Kineme String To Data" forKey:@"name"];
+ }
+ return self;
+}
+
+-(BOOL)execute:(QCOpenGLContext*)context time:(double)time arguments:(NSDictionary*)arguments
+{
+ if ([inputString wasUpdated])
+ {
+ NSData *data = [[inputString stringValue] dataUsingEncoding:NSUTF8StringEncoding];
+ [outputRawData setRawValue:data];
+ NSLog(@"%@", data);
+ }
+
+ return YES;
+}
+
+@end
View
41 DTStringToDataPatch.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>nodeAttributes</key>
+ <dict>
+ <key>name</key>
+ <string>String To Data</string>
+ <key>categories</key>
+ <array>
+ <string>Kineme DataTools</string>
+ </array>
+ <key>copyright</key>
+ <string>Copyright 2011 Kosada Incorporated. All rights reserved.</string>
+ <key>description</key>
+ <string>This patch converts a string to UTF8-encoded bytes.
+
+http://kineme.net/</string>
+ </dict>
+ <key>inputAttributes</key>
+ <dict>
+ <key>inputString</key>
+ <dict>
+ <key>name</key>
+ <string>String</string>
+ <key>description</key>
+ <string>The string to convert</string>
+ </dict>
+ </dict>
+ <key>outputAttributes</key>
+ <dict>
+ <key>outputBar</key>
+ <dict>
+ <key>name</key>
+ <string>Raw Data</string>
+ <key>description</key>
+ <string>The UTF8-encoded bytes of the string</string>
+ </dict>
+ </dict>
+</dict>
+</plist>
View
14 DataTools.xcodeproj/project.pbxproj
@@ -84,6 +84,9 @@
E72971A113B6ECFB001BBB7F /* DTOrderManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B21F28D1156A57D0099FED4 /* DTOrderManager.m */; };
E72971A213B6ED00001BBB7F /* DTMultiSplitterPatchUI.m in Sources */ = {isa = PBXBuildFile; fileRef = 2AC86FDC110A4654006CE09E /* DTMultiSplitterPatchUI.m */; };
E72971A313B6ED0C001BBB7F /* DTStructureBreakOutPatchUI.m in Sources */ = {isa = PBXBuildFile; fileRef = 2A5A195610FF8C7C00C90673 /* DTStructureBreakOutPatchUI.m */; };
+ E74FE0A015502957009E29D6 /* DTStringToDataPatch.m in Sources */ = {isa = PBXBuildFile; fileRef = E74FE09F15502957009E29D6 /* DTStringToDataPatch.m */; };
+ E74FE0A115502957009E29D6 /* DTStringToDataPatch.m in Sources */ = {isa = PBXBuildFile; fileRef = E74FE09F15502957009E29D6 /* DTStringToDataPatch.m */; };
+ E74FE0CB15502E3F009E29D6 /* DTStringToDataPatch.xml in Resources */ = {isa = PBXBuildFile; fileRef = E74FE0CA15502E3F009E29D6 /* DTStringToDataPatch.xml */; };
E78586E913E9F64A000BBF4B /* DTStructureKeyPatch.m in Sources */ = {isa = PBXBuildFile; fileRef = E78586E813E9F64A000BBF4B /* DTStructureKeyPatch.m */; };
E78586EB13E9F7DB000BBF4B /* DTStructureKeyPatch.xml in Resources */ = {isa = PBXBuildFile; fileRef = E78586EA13E9F7DB000BBF4B /* DTStructureKeyPatch.xml */; };
E785870513E9F967000BBF4B /* DTStructureKeyPatch.m in Sources */ = {isa = PBXBuildFile; fileRef = E78586E813E9F64A000BBF4B /* DTStructureKeyPatch.m */; };
@@ -188,6 +191,9 @@
8D5B49B6048680CD000E48DA /* DataTools.plugin */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DataTools.plugin; sourceTree = BUILT_PRODUCTS_DIR; };
8D5B49B7048680CD000E48DA /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
E72970AC13B6E886001BBB7F /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
+ E74FE09E15502957009E29D6 /* DTStringToDataPatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DTStringToDataPatch.h; sourceTree = "<group>"; };
+ E74FE09F15502957009E29D6 /* DTStringToDataPatch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DTStringToDataPatch.m; sourceTree = "<group>"; };
+ E74FE0CA15502E3F009E29D6 /* DTStringToDataPatch.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = DTStringToDataPatch.xml; sourceTree = "<group>"; };
E78586E713E9F64A000BBF4B /* DTStructureKeyPatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DTStructureKeyPatch.h; sourceTree = "<group>"; };
E78586E813E9F64A000BBF4B /* DTStructureKeyPatch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DTStructureKeyPatch.m; sourceTree = "<group>"; };
E78586EA13E9F7DB000BBF4B /* DTStructureKeyPatch.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = DTStructureKeyPatch.xml; sourceTree = "<group>"; };
@@ -364,6 +370,7 @@
2B7D9A4C12C85CD2002E1EA8 /* DTStructurePopPatch.xml */,
E7DC1662134E13A700DBDFC8 /* DTConvertToDataPatch.xml */,
E7DC1664134E13E600DBDFC8 /* DTConvertFromDataPatch.xml */,
+ E74FE0CA15502E3F009E29D6 /* DTStringToDataPatch.xml */,
);
name = XML;
sourceTree = "<group>";
@@ -458,6 +465,8 @@
E7DC161B134E0D1400DBDFC8 /* DTConvertToDataPatch.m */,
E7DC1620134E0F9E00DBDFC8 /* DTConvertFromDataPatch.h */,
E7DC1621134E0F9E00DBDFC8 /* DTConvertFromDataPatch.m */,
+ E74FE09E15502957009E29D6 /* DTStringToDataPatch.h */,
+ E74FE09F15502957009E29D6 /* DTStringToDataPatch.m */,
);
name = Convert;
sourceTree = "<group>";
@@ -562,6 +571,7 @@
E7DC1663134E13A700DBDFC8 /* DTConvertToDataPatch.xml in Resources */,
E7DC1665134E13E600DBDFC8 /* DTConvertFromDataPatch.xml in Resources */,
E78586EB13E9F7DB000BBF4B /* DTStructureKeyPatch.xml in Resources */,
+ E74FE0CB15502E3F009E29D6 /* DTStringToDataPatch.xml in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -619,6 +629,7 @@
E72971A213B6ED00001BBB7F /* DTMultiSplitterPatchUI.m in Sources */,
E72971A313B6ED0C001BBB7F /* DTStructureBreakOutPatchUI.m in Sources */,
E785870513E9F967000BBF4B /* DTStructureKeyPatch.m in Sources */,
+ E74FE0A115502957009E29D6 /* DTStringToDataPatch.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -652,6 +663,7 @@
E7DC161C134E0D1400DBDFC8 /* DTConvertToDataPatch.m in Sources */,
E7DC1622134E0F9E00DBDFC8 /* DTConvertFromDataPatch.m in Sources */,
E78586E913E9F64A000BBF4B /* DTStructureKeyPatch.m in Sources */,
+ E74FE0A015502957009E29D6 /* DTStringToDataPatch.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -675,6 +687,7 @@
INFOPLIST_FILE = Info.plist;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_NAME = DataTools;
+ RUN_CLANG_STATIC_ANALYZER = NO;
SDKROOT = macosx10.5;
};
name = Release;
@@ -725,6 +738,7 @@
);
PREBINDING = NO;
PRODUCT_NAME = Tests;
+ RUN_CLANG_STATIC_ANALYZER = NO;
};
name = Release;
};
View
2 DataToolsPrincipal.m
@@ -16,6 +16,7 @@
#import "DTSampleHoldPatch.h"
#import "DTConvertToDataPatch.h"
#import "DTConvertFromDataPatch.h"
+#import "DTStringToDataPatch.h"
#import "SpookySendPatch.h"
#import "SpookyReceivePatch.h"
@@ -77,6 +78,7 @@ +(void)registerNodesWithManager:(QCNodeManager*)manager
KIRegisterPatch(ValueHistorianPatch);
KIRegisterPatch(DTConvertToDataPatch);
KIRegisterPatch(DTConvertFromDataPatch);
+ KIRegisterPatch(DTStringToDataPatch);
/* disabled for now, since this hack results in input splitters that require DataTools (which is kinda misleading)
{
View
14 TestDTConvert.m
@@ -1,6 +1,7 @@
#import "SkankySDK/SkankySDK-TestCase.h"
#import "DTConvertToDataPatch.h"
#import "DTConvertFromDataPatch.h"
+#import "DTStringToDataPatch.h"
@interface TestDTConvert : SkankySDK_TestCase
@@ -42,4 +43,17 @@ - (void)testConvert
[fromPatch release];
}
+- (void)testStringToData
+{
+ DTStringToDataPatch *patch = [[DTStringToDataPatch alloc] initWithIdentifier:nil];
+
+ NSString *originalString = @"abc";
+ [self setInputValue:originalString forPort:@"inputString" onPatch:patch];
+ [self executePatch:patch];
+ NSData *data = [self getOutputForPort:@"outputRawData" onPatch:patch];
+ NSString *dataString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
+ GHAssertEqualStrings(originalString, dataString, @"");
+ [dataString release];
+}
+
@end

0 comments on commit b8eecc6

Please sign in to comment.