clang+llvm で objc を DataTable っぽく扱う

うれしげに、@property で DataRow を作って見た例。
もうちょっと整理しないと。

/*
clang -o main4 main4.m -I /llvm/include -I /GNUstep/GNUstep/System/Library/Headers -L c:/GNUstep/GNUstep/System/Library/Libraries -lobjc -lgnustep-base -fconstant-string-class=NSConstantString -Wno-format-security
*/
#import <stdio.h>
#import <Foundation/Foundation.h>
#import <Foundation/NSObject.h>

@interface Person : NSMutableDictionary
{
	@private
	int _id ;
	NSString *_name;
	int _age ;
}
@property (nonatomic) int id ;
@property (nonatomic,retain) NSString *name;
@property (nonatomic) int age ;
@end

@implementation Person
@synthesize id = _id ;
@synthesize name = _name ;
@synthesize age = _age ;
- (void)print 
{
	NSLog(@"%d %@(%d)", _id, _name, _age );
}
- (Person*)initWithId:(int)id Name:(NSString*)name Age:(int)age 
{
	_id = id;
	_name = name;
	_age = age;
	
	return self;
}
@end

@interface Persons : NSObject
{
	@private 
	NSMutableArray *_rows ;
}
@property (nonatomic,retain) NSMutableArray *rows ;
@end

@implementation Persons
@synthesize rows = _rows;

- (id)init
{
	[super init];
	_rows = [[NSMutableArray alloc] init];
	return self;
}
- (void)print 
{
	for ( int i=0; i< [_rows count]; i++ ) {
		Person *p = [_rows objectAtIndex:i];
		[p print];
	}
}

@end



int _main(int argc, char *argv[])
{
	Person *masuda = [[Person alloc] initWithId:1 Name:@"masuda" Age:40];
	Person *yamada = [[Person alloc] initWithId:2 Name:@"yamada" Age:50];
	Person *tanaka = [[Person alloc] initWithId:3 Name:@"tanaka" Age:20];
	Persons *persons = [[Persons alloc] init];
	[persons.rows addObject:masuda];
	[persons.rows addObject:yamada];
	[persons.rows addObject:tanaka];
	[persons print];
	
	return 0;
}

int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int retVal = _main(argc, argv);
    [pool release];
    return retVal;
}



カテゴリー: 開発, Objective-C パーマリンク