Skip to content

Commit

Permalink
First commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
kishikawakatsumi committed Sep 6, 2009
0 parents commit 97b58a7
Show file tree
Hide file tree
Showing 14 changed files with 885 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pbxproj -crlf -diff -merge
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
build
.DS_Store
*.o
*.ob
*.pbxuser
*.tmproj
*.mode1*
*.build
*~.nib

24 changes: 24 additions & 0 deletions Classes/DescriptionBuilder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// DescriptionBuilder.h
// DescriptionBuilder
//
// Created by KISHIKAWA Katsumi on 09/09/07.
// Copyright 2009 KISHIKAWA Katsumi. All rights reserved.
//

#import <Foundation/Foundation.h>

typedef enum DescriptionStyle {
DescriptionStyleDefault,
DescriptionStyleMultiLine,
DescriptionStyleNoNames,
DescriptionStyleShortPrefix,
DescriptionStyleSimple,
} DescriptionStyle;

@interface DescriptionBuilder : NSObject

+ (NSString *)reflectDescription:(id)obj;
+ (NSString *)reflectDescription:(id)obj style:(DescriptionStyle)style;

@end
200 changes: 200 additions & 0 deletions Classes/DescriptionBuilder.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
//
// DescriptionBuilder.m
// DescriptionBuilder
//
// Created by KISHIKAWA Katsumi on 09/09/07.
// Copyright 2009 KISHIKAWA Katsumi. All rights reserved.
//

#import "DescriptionBuilder.h"
#import <objc/runtime.h>

@implementation DescriptionBuilder

+ (NSString *)reflectDescription:(id)obj {
return [DescriptionBuilder reflectDescription:obj style:DescriptionStyleDefault];
}

/**
c char
C unsigned char
i int
I unsigned int
s short
S unsigned short
l long
L unsigned long
q long long
Q unsigned long long
f float
d double
B C++のbool、またはC99の_Bool
^v void*
* 文字列(char*)
@ オブジェクト (静的に型定義されているもの、または id として型定義されているもの)
# クラスオブジェクト(Class)
: メソッドセレクタ(SEL)
*/
+ (NSString *)reflectDescription:(id)obj style:(DescriptionStyle)style {
id objValue;
Class classValue;
SEL selValue;
signed char charValue;
unsigned char ucharValue;
signed int intValue;
unsigned int uintValue;
signed short shortValue;
unsigned short ushortValue;
signed long longValue;
unsigned long ulongValue;
signed long long longlongValue;
unsigned long long ulonglongValue;
float floatValue;
double doubleValue;
char *charPtrValue;
void *voidPtrValue;

NSMutableString *description = [[[NSMutableString alloc] init] autorelease];

Class clazz = [obj class];
unsigned int outCount = 0;
Ivar *ivars = class_copyIvarList(clazz, &outCount);

if (style == DescriptionStyleMultiLine) {
[description appendFormat:@"<%s: 0x%x;\n", class_getName(clazz), [obj hash]];
} else if (style == DescriptionStyleNoNames) {
[description appendFormat:@"<%s: 0x%x; ", class_getName(clazz), [obj hash]];
} else if (style == DescriptionStyleShortPrefix) {
[description appendFormat:@"<%s; ", class_getName(clazz)];
} else if (style == DescriptionStyleSimple) {
[description appendString:@"<"];
} else {
[description appendFormat:@"<%s: 0x%x; ", class_getName(clazz), [obj hash]];
}

for (int i = 0; i < outCount; i++) {
if (i > 0) {
if (style == DescriptionStyleMultiLine) {
[description appendString:@";\n"];
} else if (style == DescriptionStyleNoNames) {
[description appendString:@"; "];
} else if (style == DescriptionStyleShortPrefix) {
[description appendString:@"; "];
} else if (style == DescriptionStyleSimple) {
[description appendString:@"; "];
} else {
[description appendString:@"; "];
}
}

Ivar ivar = ivars[i];
const char *ivar_name = ivar_getName(ivar);
const char *ivar_type = ivar_getTypeEncoding(ivar);

if (style == DescriptionStyleMultiLine) {
[description appendFormat:@"%s = ", ivar_name];
} else if (style == DescriptionStyleNoNames) {
//Nothing to do.;
} else if (style == DescriptionStyleShortPrefix) {
[description appendFormat:@"%s = ", ivar_name];
} else if (style == DescriptionStyleSimple) {
//Nothing to do.;
} else {
[description appendFormat:@"%s = ", ivar_name];
}

switch(*ivar_type) {
case '@':
object_getInstanceVariable(obj, ivar_name, (void **)&objValue);

if (!objValue) {
[description appendFormat:@"%@", [NSNull null]];
} else if ([objValue respondsToSelector:@selector(description)]) {
NSString *type = [NSString stringWithUTF8String:ivar_type];
NSString *className = [type substringWithRange:NSMakeRange(2, [type length] - 3)];
Class ivarClass = NSClassFromString(className);
if ([NSString isSubclassOfClass:ivarClass]) {
[description appendFormat:@"\"%@\"", [objValue description]];
} else {
[description appendFormat:@"%@", [objValue description]];
}
} else {
[description appendFormat:@"<%s: 0x%x>", class_getName([objValue class]), [objValue hash]];
}
break;
case '#':
object_getInstanceVariable(obj, ivar_name, (void **)&classValue);
[description appendFormat:@"%@", NSStringFromClass(classValue)];
break;
case ':':
object_getInstanceVariable(obj, ivar_name, (void **)&selValue);
[description appendFormat:@"%@", NSStringFromSelector(selValue)];
break;
case 'c':
object_getInstanceVariable(obj, ivar_name, (void **)&charValue);
[description appendFormat:@"%@", charValue == 0 ? @"NO" : @"YES"];
break;
case 'C':
object_getInstanceVariable(obj, ivar_name, (void **)&ucharValue);
[description appendFormat:@"%c", ucharValue];
break;
case 'i':
object_getInstanceVariable(obj, ivar_name, (void **)&intValue);
[description appendFormat:@"%d", intValue];
break;
case 'I':
object_getInstanceVariable(obj, ivar_name, (void **)&uintValue);
[description appendFormat:@"%u", uintValue];
break;
case 's':
object_getInstanceVariable(obj, ivar_name, (void **)&shortValue);
[description appendFormat:@"%hi", shortValue];
break;
case 'S':
object_getInstanceVariable(obj, ivar_name, (void **)&ushortValue);
[description appendFormat:@"%hu", ushortValue];
break;
case 'l':
object_getInstanceVariable(obj, ivar_name, (void **)&longValue);
[description appendFormat:@"%d", longValue];
break;
case 'L':
object_getInstanceVariable(obj, ivar_name, (void **)&ulongValue);
[description appendFormat:@"%u", ulongValue];
break;
case 'q':
object_getInstanceVariable(obj, ivar_name, (void **)&longlongValue);
[description appendFormat:@"%qi", longlongValue];
break;
case 'Q':
object_getInstanceVariable(obj, ivar_name, (void **)&ulonglongValue);
[description appendFormat:@"%qu", ulonglongValue];
break;
case 'f':
object_getInstanceVariable(obj, ivar_name, (void **)&floatValue);
[description appendFormat:@"%f", floatValue];
break;
case 'd':
object_getInstanceVariable(obj, ivar_name, (void **)&doubleValue);
[description appendFormat:@"f", doubleValue];
break;
case 'B':
object_getInstanceVariable(obj, ivar_name, (void **)&intValue);
[description appendFormat:@"%@", intValue == 0 ? @"false" : @"true"];
break;
case '*':
object_getInstanceVariable(obj, ivar_name, (void **)&charPtrValue);
[description appendFormat:@"%s", charPtrValue];
break;
case '^':
object_getInstanceVariable(obj, ivar_name, (void **)&voidPtrValue);
[description appendFormat:@"%p", voidPtrValue];
break;
}
}
[description appendString:@">"];
if (outCount > 0) { free(ivars); }
return description;
}

@end
18 changes: 18 additions & 0 deletions Classes/DescriptionBuilderAppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// DescriptionBuilderAppDelegate.h
// DescriptionBuilder
//
// Created by KISHIKAWA Katsumi on 09/09/07.
// Copyright KISHIKAWA Katsumi 2009. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface DescriptionBuilderAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@end

27 changes: 27 additions & 0 deletions Classes/DescriptionBuilderAppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// DescriptionBuilderAppDelegate.m
// DescriptionBuilder
//
// Created by KISHIKAWA Katsumi on 09/09/07.
// Copyright KISHIKAWA Katsumi 2009. All rights reserved.
//

#import "DescriptionBuilderAppDelegate.h"
#import "Settings.h"

@implementation DescriptionBuilderAppDelegate

@synthesize window;

- (void)applicationDidFinishLaunching:(UIApplication *)application {
Settings *settings = [Settings sharedSettings];
NSLog(@"%@", settings);
[window makeKeyAndVisible];
}

- (void)dealloc {
[window release];
[super dealloc];
}

@end
27 changes: 27 additions & 0 deletions Classes/Settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Settings.h
// TimeSignal
//
// Created by KISHIKAWA Katsumi on 09/07/20.
// Copyright 2009 KISHIKAWA Katsumi. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface Settings : NSObject {
NSUInteger version;
BOOL autoLock;
BOOL twentyFourHourTime;
NSString *alarmSound;
float alarmVolume;
}

@property (nonatomic) NSUInteger version;
@property (nonatomic) BOOL autoLock;
@property (nonatomic) BOOL twentyFourHourTime;
@property (nonatomic, retain) NSString *alarmSound;
@property (nonatomic) float alarmVolume;

+ (Settings *)sharedSettings;

@end
49 changes: 49 additions & 0 deletions Classes/Settings.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// Settings.m
// TimeSignal
//
// Created by KISHIKAWA Katsumi on 09/07/20.
// Copyright 2009 KISHIKAWA Katsumi. All rights reserved.
//

#import "Settings.h"
#import "DescriptionBuilder.h"

@implementation Settings

static Settings *sharedSettings;

@synthesize version;
@synthesize autoLock;
@synthesize twentyFourHourTime;
@synthesize alarmSound;
@synthesize alarmVolume;

+ (Settings *)sharedSettings {
if (!sharedSettings) {
sharedSettings = [[Settings alloc] init];
}
return sharedSettings;
}

- (id)init {
if (self = [super init]) {
version = 100;
autoLock = NO;
twentyFourHourTime = YES;
self.alarmSound = @"digital-alarm";
alarmVolume = 1.0f;
}
return self;
}

- (void)dealloc {
[alarmSound release];
[super dealloc];
}

- (NSString *)description {
return [DescriptionBuilder reflectDescription:self];
}

@end
30 changes: 30 additions & 0 deletions DescriptionBuilder-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSMainNibFile</key>
<string>MainWindow</string>
</dict>
</plist>
Loading

0 comments on commit 97b58a7

Please sign in to comment.