Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add FaultingArray

  • Loading branch information...
commit 6fd947ad73bf90fc790c38972cab948d1c5aba67 1 parent f44c135
@davedelong authored
View
240 FaultingArray/FaultingArray.xcodeproj/project.pbxproj
@@ -0,0 +1,240 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 46;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ 55951DBC14C9291B00E4A63E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55951DBB14C9291B00E4A63E /* Foundation.framework */; };
+ 55951DBF14C9291B00E4A63E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 55951DBE14C9291B00E4A63E /* main.m */; };
+ 55951DC314C9291B00E4A63E /* FaultingArray.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = 55951DC214C9291B00E4A63E /* FaultingArray.1 */; };
+ 55951DCB14C9292F00E4A63E /* DDFaultingArray.m in Sources */ = {isa = PBXBuildFile; fileRef = 55951DCA14C9292F00E4A63E /* DDFaultingArray.m */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXCopyFilesBuildPhase section */
+ 55951DB514C9291B00E4A63E /* CopyFiles */ = {
+ isa = PBXCopyFilesBuildPhase;
+ buildActionMask = 2147483647;
+ dstPath = /usr/share/man/man1/;
+ dstSubfolderSpec = 0;
+ files = (
+ 55951DC314C9291B00E4A63E /* FaultingArray.1 in CopyFiles */,
+ );
+ runOnlyForDeploymentPostprocessing = 1;
+ };
+/* End PBXCopyFilesBuildPhase section */
+
+/* Begin PBXFileReference section */
+ 55951DB714C9291B00E4A63E /* FaultingArray */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = FaultingArray; sourceTree = BUILT_PRODUCTS_DIR; };
+ 55951DBB14C9291B00E4A63E /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
+ 55951DBE14C9291B00E4A63E /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+ 55951DC114C9291B00E4A63E /* FaultingArray-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "FaultingArray-Prefix.pch"; sourceTree = "<group>"; };
+ 55951DC214C9291B00E4A63E /* FaultingArray.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = FaultingArray.1; sourceTree = "<group>"; };
+ 55951DC914C9292F00E4A63E /* DDFaultingArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDFaultingArray.h; sourceTree = "<group>"; };
+ 55951DCA14C9292F00E4A63E /* DDFaultingArray.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DDFaultingArray.m; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ 55951DB414C9291B00E4A63E /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 55951DBC14C9291B00E4A63E /* Foundation.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ 55951DAC14C9291B00E4A63E = {
+ isa = PBXGroup;
+ children = (
+ 55951DBD14C9291B00E4A63E /* FaultingArray */,
+ 55951DBA14C9291B00E4A63E /* Frameworks */,
+ 55951DB814C9291B00E4A63E /* Products */,
+ );
+ sourceTree = "<group>";
+ };
+ 55951DB814C9291B00E4A63E /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 55951DB714C9291B00E4A63E /* FaultingArray */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ 55951DBA14C9291B00E4A63E /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ 55951DBB14C9291B00E4A63E /* Foundation.framework */,
+ );
+ name = Frameworks;
+ sourceTree = "<group>";
+ };
+ 55951DBD14C9291B00E4A63E /* FaultingArray */ = {
+ isa = PBXGroup;
+ children = (
+ 55951DBE14C9291B00E4A63E /* main.m */,
+ 55951DC914C9292F00E4A63E /* DDFaultingArray.h */,
+ 55951DCA14C9292F00E4A63E /* DDFaultingArray.m */,
+ 55951DC214C9291B00E4A63E /* FaultingArray.1 */,
+ 55951DC014C9291B00E4A63E /* Supporting Files */,
+ );
+ path = FaultingArray;
+ sourceTree = "<group>";
+ };
+ 55951DC014C9291B00E4A63E /* Supporting Files */ = {
+ isa = PBXGroup;
+ children = (
+ 55951DC114C9291B00E4A63E /* FaultingArray-Prefix.pch */,
+ );
+ name = "Supporting Files";
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+ 55951DB614C9291B00E4A63E /* FaultingArray */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 55951DC614C9291B00E4A63E /* Build configuration list for PBXNativeTarget "FaultingArray" */;
+ buildPhases = (
+ 55951DB314C9291B00E4A63E /* Sources */,
+ 55951DB414C9291B00E4A63E /* Frameworks */,
+ 55951DB514C9291B00E4A63E /* CopyFiles */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = FaultingArray;
+ productName = FaultingArray;
+ productReference = 55951DB714C9291B00E4A63E /* FaultingArray */;
+ productType = "com.apple.product-type.tool";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ 55951DAE14C9291B00E4A63E /* Project object */ = {
+ isa = PBXProject;
+ attributes = {
+ LastUpgradeCheck = 0420;
+ };
+ buildConfigurationList = 55951DB114C9291B00E4A63E /* Build configuration list for PBXProject "FaultingArray" */;
+ compatibilityVersion = "Xcode 3.2";
+ developmentRegion = English;
+ hasScannedForEncodings = 0;
+ knownRegions = (
+ en,
+ );
+ mainGroup = 55951DAC14C9291B00E4A63E;
+ productRefGroup = 55951DB814C9291B00E4A63E /* Products */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ 55951DB614C9291B00E4A63E /* FaultingArray */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXSourcesBuildPhase section */
+ 55951DB314C9291B00E4A63E /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 55951DBF14C9291B00E4A63E /* main.m in Sources */,
+ 55951DCB14C9292F00E4A63E /* DDFaultingArray.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin XCBuildConfiguration section */
+ 55951DC414C9291B00E4A63E /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = "$(ARCHS_STANDARD_64_BIT)";
+ COPY_PHASE_STRIP = NO;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "DEBUG=1",
+ "$(inherited)",
+ );
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ MACOSX_DEPLOYMENT_TARGET = 10.7;
+ ONLY_ACTIVE_ARCH = YES;
+ SDKROOT = macosx;
+ };
+ name = Debug;
+ };
+ 55951DC514C9291B00E4A63E /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = "$(ARCHS_STANDARD_64_BIT)";
+ COPY_PHASE_STRIP = YES;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ MACOSX_DEPLOYMENT_TARGET = 10.7;
+ SDKROOT = macosx;
+ };
+ name = Release;
+ };
+ 55951DC714C9291B00E4A63E /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "FaultingArray/FaultingArray-Prefix.pch";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Debug;
+ };
+ 55951DC814C9291B00E4A63E /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "FaultingArray/FaultingArray-Prefix.pch";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ 55951DB114C9291B00E4A63E /* Build configuration list for PBXProject "FaultingArray" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 55951DC414C9291B00E4A63E /* Debug */,
+ 55951DC514C9291B00E4A63E /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ 55951DC614C9291B00E4A63E /* Build configuration list for PBXNativeTarget "FaultingArray" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 55951DC714C9291B00E4A63E /* Debug */,
+ 55951DC814C9291B00E4A63E /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = 55951DAE14C9291B00E4A63E /* Project object */;
+}
View
7 FaultingArray/FaultingArray.xcodeproj/project.xcworkspace/contents.xcworkspacedata
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Workspace
+ version = "1.0">
+ <FileRef
+ location = "self:FaultingArray.xcodeproj">
+ </FileRef>
+</Workspace>
View
19 FaultingArray/FaultingArray/DDFaultingArray.h
@@ -0,0 +1,19 @@
+//
+// DDFaultingArray.h
+// FaultingArray
+//
+// Created by Dave DeLong on 1/19/12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+typedef id(^DDFaultingArrayFaulter)(NSUInteger idx);
+
+@interface DDFaultingArray : NSArray
+
+@property (nonatomic, copy) DDFaultingArrayFaulter faulter;
+
+- (id)initWithCapacity:(NSUInteger)capacity;
+
+@end
View
57 FaultingArray/FaultingArray/DDFaultingArray.m
@@ -0,0 +1,57 @@
+//
+// DDFaultingArray.m
+// FaultingArray
+//
+// Created by Dave DeLong on 1/19/12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#import "DDFaultingArray.h"
+
+@implementation DDFaultingArray {
+ NSMutableArray *_storage;
+}
+
+@synthesize faulter=_faulter;
+
+- (id)initWithCapacity:(NSUInteger)capacity {
+ self = [super init];
+ if (self) {
+ _storage = [[NSMutableArray alloc] initWithCapacity:capacity];
+ for (NSUInteger i = 0; i < capacity; ++i) {
+ [_storage addObject:[NSNull null]];
+ }
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [_faulter release];
+ [super dealloc];
+}
+
+- (NSUInteger)count {
+ return [_storage count];
+}
+
+- (id)objectAtIndex:(NSUInteger)index {
+ id obj = [_storage objectAtIndex:index];
+ if (obj == [NSNull null]) {
+ // ask someone for our object
+
+ if (!_faulter) {
+ [NSException raise:NSInternalInconsistencyException format:@"Can't fault without a faulter! This is your fault!"];
+ }
+
+ obj = _faulter(index);
+
+ if (obj == nil) {
+ [NSException raise:NSInternalInconsistencyException format:@"May not return nil for a faulted object"];
+ }
+
+ [_storage replaceObjectAtIndex:index withObject:obj];
+ }
+ return obj;
+}
+
+@end
View
7 FaultingArray/FaultingArray/FaultingArray-Prefix.pch
@@ -0,0 +1,7 @@
+//
+// Prefix header for all source files of the 'FaultingArray' target in the 'FaultingArray' project
+//
+
+#ifdef __OBJC__
+ #import <Foundation/Foundation.h>
+#endif
View
79 FaultingArray/FaultingArray/FaultingArray.1
@@ -0,0 +1,79 @@
+.\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples.
+.\"See Also:
+.\"man mdoc.samples for a complete listing of options
+.\"man mdoc for the short list of editing options
+.\"/usr/share/misc/mdoc.template
+.Dd 1/19/12 \" DATE
+.Dt FaultingArray 1 \" Program name and manual section number
+.Os Darwin
+.Sh NAME \" Section Header - required - don't modify
+.Nm FaultingArray,
+.\" The following lines are read in generating the apropos(man -k) database. Use only key
+.\" words here as the database is built based on the words here and in the .ND line.
+.Nm Other_name_for_same_program(),
+.Nm Yet another name for the same program.
+.\" Use .Nm macro to designate other names for the documented program.
+.Nd This line parsed for whatis database.
+.Sh SYNOPSIS \" Section Header - required - don't modify
+.Nm
+.Op Fl abcd \" [-abcd]
+.Op Fl a Ar path \" [-a path]
+.Op Ar file \" [file]
+.Op Ar \" [file ...]
+.Ar arg0 \" Underlined argument - use .Ar anywhere to underline
+arg2 ... \" Arguments
+.Sh DESCRIPTION \" Section Header - required - don't modify
+Use the .Nm macro to refer to your program throughout the man page like such:
+.Nm
+Underlining is accomplished with the .Ar macro like this:
+.Ar underlined text .
+.Pp \" Inserts a space
+A list of items with descriptions:
+.Bl -tag -width -indent \" Begins a tagged list
+.It item a \" Each item preceded by .It macro
+Description of item a
+.It item b
+Description of item b
+.El \" Ends the list
+.Pp
+A list of flags and their descriptions:
+.Bl -tag -width -indent \" Differs from above in tag removed
+.It Fl a \"-a flag as a list item
+Description of -a flag
+.It Fl b
+Description of -b flag
+.El \" Ends the list
+.Pp
+.\" .Sh ENVIRONMENT \" May not be needed
+.\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1
+.\" .It Ev ENV_VAR_1
+.\" Description of ENV_VAR_1
+.\" .It Ev ENV_VAR_2
+.\" Description of ENV_VAR_2
+.\" .El
+.Sh FILES \" File used or created by the topic of the man page
+.Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact
+.It Pa /usr/share/file_name
+FILE_1 description
+.It Pa /Users/joeuser/Library/really_long_file_name
+FILE_2 description
+.El \" Ends the list
+.\" .Sh DIAGNOSTICS \" May not be needed
+.\" .Bl -diag
+.\" .It Diagnostic Tag
+.\" Diagnostic informtion here.
+.\" .It Diagnostic Tag
+.\" Diagnostic informtion here.
+.\" .El
+.Sh SEE ALSO
+.\" List links in ascending order by section, alphabetically within a section.
+.\" Please do not reference files that do not exist without filing a bug report
+.Xr a 1 ,
+.Xr b 1 ,
+.Xr c 1 ,
+.Xr a 2 ,
+.Xr b 2 ,
+.Xr a 3 ,
+.Xr b 3
+.\" .Sh BUGS \" Document known, unremedied bugs
+.\" .Sh HISTORY \" Document history if command behaves in a unique manner
View
29 FaultingArray/FaultingArray/main.m
@@ -0,0 +1,29 @@
+//
+// main.m
+// FaultingArray
+//
+// Created by Dave DeLong on 1/19/12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import "DDFaultingArray.h"
+
+int main (int argc, const char * argv[])
+{
+
+ @autoreleasepool {
+
+
+ DDFaultingArray *array = [[DDFaultingArray alloc] initWithCapacity:100];
+ [array setFaulter:^(NSUInteger idx) {
+ NSLog(@"requesting object at index: %lu", idx);
+ return [NSNumber numberWithUnsignedInteger:(idx*idx)];
+ }];
+
+ NSLog(@"%@", array);
+
+ }
+ return 0;
+}
+
View
4 README.markdown
@@ -19,6 +19,10 @@ Both should work on both iOS and Mac OS X, regardless of GC mode.
Contains `DDDynamicStorageObject`, an `NSObject` subclass that dynamically generates getters and setters for properties declared as `@dynamic`, and uses an `NSMutableDictionary` as the backing store.
+## FaultingArray
+
+An `NSArray` subclass that only loads the objects in the array when something else needs them.
+
## GrandSuper
A project showing how to invoke "grandsuper" (super's super). Uses a private method on `NSInvocation`, so you probably shouldn't use this in a production setting.
Please sign in to comment.
Something went wrong with that request. Please try again.