-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathDataMatrix.mm
More file actions
55 lines (43 loc) · 1.11 KB
/
DataMatrix.mm
File metadata and controls
55 lines (43 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#import "DataMatrix.h"
@implementation DataMatrix
- (id)initWith:(int)dimension {
if (self = [super init]) {
self->dim = dimension;
self->data = (bool**)malloc(sizeof(bool*) * self->dim);
for (int y=0; y<self->dim; y++) {
self->data[y] = (bool*)malloc(sizeof(bool) * self->dim);
if (self->data[y]==NULL) {
NSLog(@"null!");
}
}
}
return self;
}
- (int)dimension {
return self->dim;
}
- (void)set:(bool)value x:(int)x y:(int)y {
self->data[y][x] = value;
}
- (bool)valueAt:(int)x y:(int)y {
return self->data[y][x];
}
- (NSString*)toString {
NSString* string = [NSString string];
for (int y=0; y<self->dim; y++) {
for (int x=0; x<self->dim; x++) {
bool value = self->data[y][x];
string = [string stringByAppendingFormat:@"%d", value];
}
string = [string stringByAppendingString:@"\n"];
}
return string;
}
- (void)dealloc {
for (int y=0; y<self->dim; y++) {
free(self->data[y]);
}
free(self->data);
[super dealloc];
}
@end