Introduce DebuggerModel, which will be updated by the BackEnd.
[macgdbp.git] / Source / Breakpoint.m
1 /*
2 * MacGDBp
3 * Copyright (c) 2007 - 2011, Blue Static <http://www.bluestatic.org>
4 *
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17 #import "Breakpoint.h"
18
19
20 @implementation Breakpoint
21
22 @synthesize file = file_;
23 @synthesize line = line_;
24 @synthesize debuggerId = debuggerId_;
25
26 /**
27 * Initializes a breakpoint with a file and line
28 */
29 - (id)initWithLine:(NSUInteger)l inFile:(NSString*)f
30 {
31 if (self = [super init])
32 {
33 file_ = [f retain];
34 line_ = l;
35 }
36 return self;
37 }
38
39 /**
40 * Dealloc
41 */
42 - (void)dealloc
43 {
44 [file_ release];
45 [super dealloc];
46 }
47
48 /**
49 * Creates a Breakpoint from the values of an NSDictionary
50 */
51 - (id)initWithDictionary:(NSDictionary*)dict
52 {
53 if (self = [super init])
54 {
55 file_ = [[dict valueForKey:@"file"] retain];
56 line_ = [[dict valueForKey:@"line"] intValue];
57 }
58 return self;
59 }
60
61 /**
62 * Returns the transformed path for the breakpoint, as Xdebug needs it
63 */
64 - (NSString*)transformedPath
65 {
66 NSString* path = self.file;
67
68 NSMutableArray* transforms = [[NSUserDefaults standardUserDefaults] mutableArrayValueForKey:@"PathReplacements"];
69 if (!transforms || [transforms count] < 1)
70 return path;
71
72 for (NSDictionary* replacement in transforms)
73 {
74 path = [path
75 stringByReplacingOccurrencesOfString:[replacement valueForKey:@"local"]
76 withString:[replacement valueForKey:@"remote"]
77 ];
78 }
79
80 return path;
81 }
82
83 /**
84 * Determines if two breakpoints are equal
85 */
86 - (BOOL)isEqual:(id)obj
87 {
88 return ([[obj file] isEqualToString:self.file] && [obj line] == self.line);
89 }
90
91 /**
92 * Returns the hash value of a breakpoint
93 */
94 - (NSUInteger)hash
95 {
96 return ([self.file hash] << 8) + self.line;
97 }
98
99 /**
100 * Returns an NSDictionary of the data so it can be stored in NSUserDefaults
101 */
102 - (NSDictionary*)dictionary
103 {
104 return [NSDictionary dictionaryWithObjectsAndKeys:
105 self.file, @"file",
106 [NSNumber numberWithInt:self.line], @"line",
107 nil
108 ];
109 }
110
111 /**
112 * Pretty-print
113 */
114 - (NSString*)description
115 {
116 return [NSString stringWithFormat:@"%@:%i", self.file, self.line];
117 }
118
119 @end