Created
November 21, 2010 06:33
-
-
Save jonsterling/708514 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct arr : obj | |
| { | |
| arr(id *input) | |
| { | |
| size_t s = sizeof(input) - 1; | |
| this->substrate_object = [NSArray arrayWithObjects:input count:s]; | |
| } | |
| arr(NSArray *input) : obj::obj(input) {} | |
| id operator[](int index) | |
| { | |
| return [this->substrate_object objectAtIndex:index]; | |
| } | |
| id operator[](NSRange r) | |
| { | |
| id is = [NSIndexSet indexSetWithIndexesInRange:r]; | |
| return [this->substrate_object objectsAtIndexes:is]; | |
| } | |
| id operator id() | |
| { | |
| return this->substrate_object; | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| id a = [NSArray arrayWithObjects:@"a",@"b",@"c",nil]; | |
| arr b = a; | |
| arr c = (id[]){@"a",@"b",@"c"}; | |
| NSLog(@"%@ == %@ == %@ == %@", | |
| [a objectAtIndex:0], | |
| [b objectAtIndex:0], | |
| [c objectAtIndex:0], | |
| b[0], | |
| c[0]); | |
| // => a == a == a== a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct dict : obj | |
| { | |
| dict(NSDictionary *input) : obj::obj(input) {} | |
| dict::dict(id *input) | |
| { | |
| size_t s = sizeof(input) - 1; | |
| NSMutableDictionary *buffer = [NSMutableDictionary dictionaryWithCapacity:s/2]; | |
| for (int i = 0; i < s; i = i+2) | |
| { | |
| id key = input[i]; | |
| id values = input[i+1]; | |
| [buffer setObject:value forKey:key]; | |
| } | |
| this->substrate_object = [[buffer copy] autorelease]; | |
| } | |
| id dict::operator[](id key) | |
| { | |
| return [this->substrate_object objectForKey:key]; | |
| } | |
| dict::operator id() | |
| { | |
| return this->substrate_object; | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dict d = (id[]){ | |
| @"aKey",@"myValue", | |
| @"awesome",@"puppies", | |
| @"omg",@"z" | |
| }; | |
| NSLog(@"%@ == %@", | |
| d[@"awesome"], | |
| [d objectForKey:@"awesome"]); | |
| // => puppies == puppies |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct obj | |
| { | |
| obj(id substrate) | |
| { | |
| this->substrate_object = substrate; | |
| } | |
| operator id() | |
| { | |
| return this->substrate_object; | |
| } | |
| protected: | |
| obj() { } | |
| id substrate_object; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment