-
Notifications
You must be signed in to change notification settings - Fork 0
/
pattern.m
148 lines (120 loc) · 3.5 KB
/
pattern.m
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//
// pattern.m
// gesture-recognition_test
//
// Created by divol on 28/06/11.
/*
* This work is based on Action Script Mouse Gesture Recognizer
*
* from Didier Brun
* @link http://www.bytearray.org/?p=91
* This class is under RECIPROCAL PUBLIC LICENSE.
* http://www.opensource.org/licenses/rpl.php
*
* Please, keep this header and the list of all authors
*/
#import "pattern.h"
#import "Matcher.h"
@implementation pattern
@synthesize name;
@synthesize pathpattern;
@synthesize matcher;
+(NSArray*)getConfiguredPatterns{
NSString *defaultsFilePath = [[NSBundle mainBundle] pathForResource:@"patterns" ofType:@"plist"] ;
NSArray *arr=[NSArray arrayWithContentsOfFile:defaultsFilePath] ;
NSMutableArray *result= [[NSMutableArray alloc]initWithCapacity:[arr count]];
for (NSDictionary *pat in arr){
NSString* name =[pat objectForKey:@"name"];
NSString* pathpattern=[pat objectForKey:@"pattern"];;
NSString* matcher=[pat objectForKey:@"matcher"];;
pattern *p = [[pattern alloc]initWithParams:name pattern:pathpattern matcher:matcher];
[result addObject:p];
[p release];
}
return [result autorelease] ;
}
//init part
-(id)initWithParams:(NSString*) aname pattern:(NSString*)apattern matcher:(NSString*)amatcher{
if ((self = [super init])){
self.name =[aname retain ];
self.pathpattern=[apattern retain ];
self.matcher=[amatcher retain ];
}
return self;
}
-(NSArray*) pathpatternAsNumbers{
NSMutableArray *result= [NSMutableArray array];
for (NSUInteger i=0;i< self.pathpattern.length;i++){
unichar ch = [self.pathpattern characterAtIndex:i];
switch (ch) {
case '0':
{
[result addObject:[NSNumber numberWithInt:0]];
}
break;
case '1':
{
[result addObject:[NSNumber numberWithInt:1]];
}
break;
case '2':
{
[result addObject:[NSNumber numberWithInt:2]];
}
break;
case '3':
{
[result addObject:[NSNumber numberWithInt:3]];
}
break;
case '4':
{
[result addObject:[NSNumber numberWithInt:4]];
}
break;
case '5':
{
[result addObject:[NSNumber numberWithInt:5]];
}
break;
case '6':
{
[result addObject:[NSNumber numberWithInt:6]];
}
break;
case '7':
{
[result addObject:[NSNumber numberWithInt:7]];
}
break;
case '8':
{
[result addObject:[NSNumber numberWithInt:8]];
}
break;
case '9':
{
[result addObject:[NSNumber numberWithInt:9]];
}
break;
default:
break;
}
}
return result;
}
-(unsigned int)match:(Info *) info{
Matcher* m =[[ Matcher alloc]initWithName:self.matcher];
unsigned int result = [m match:info];
NSLog(@"match pattern,y (%@,%f)",self.name, result*1.0f );
[m release];
return result;
}
- (void)dealloc
{
self.name =nil;
self.pathpattern=nil;
self.matcher=nil;
[super dealloc];
}
@end