Move the Eval window into a tabbed section.
[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 #import "PreferenceNames.h"
20
21 @implementation Breakpoint
22
23 @synthesize file = file_;
24 @synthesize line = line_;
25 @synthesize debuggerId = debuggerId_;
26
27 /**
28 * Initializes a breakpoint with a file and line
29 */
30 - (id)initWithLine:(NSUInteger)l inFile:(NSString*)f
31 {
32 if (self = [super init])
33 {
34 file_ = [f retain];
35 line_ = l;
36 }
37 return self;
38 }
39
40 /**
41 * Dealloc
42 */
43 - (void)dealloc
44 {
45 [file_ release];
46 [super dealloc];
47 }
48
49 /**
50 * Creates a Breakpoint from the values of an NSDictionary
51 */
52 - (id)initWithDictionary:(NSDictionary*)dict
53 {
54 if (self = [super init])
55 {
56 file_ = [[dict valueForKey:@"file"] retain];
57 line_ = [[dict valueForKey:@"line"] intValue];
58 }
59 return self;
60 }
61
62 /**
63 * Returns the transformed path for the breakpoint, as Xdebug needs it
64 */
65 - (NSString*)transformedPath
66 {
67 NSString* path = self.file;
68
69 NSMutableArray* transforms = [[NSUserDefaults standardUserDefaults] mutableArrayValueForKey:kPrefPathReplacements];
70 if (!transforms || [transforms count] < 1)
71 return path;
72
73 for (NSDictionary* replacement in transforms)
74 {
75 path = [path
76 stringByReplacingOccurrencesOfString:[replacement valueForKey:@"local"]
77 withString:[replacement valueForKey:@"remote"]
78 ];
79 }
80
81 return path;
82 }
83
84 /**
85 * Determines if two breakpoints are equal
86 */
87 - (BOOL)isEqual:(id)obj
88 {
89 return ([[obj file] isEqualToString:self.file] && [obj line] == self.line);
90 }
91
92 /**
93 * Returns the hash value of a breakpoint
94 */
95 - (NSUInteger)hash
96 {
97 return ([self.file hash] << 8) + self.line;
98 }
99
100 /**
101 * Returns an NSDictionary of the data so it can be stored in NSUserDefaults
102 */
103 - (NSDictionary*)dictionary
104 {
105 return [NSDictionary dictionaryWithObjectsAndKeys:
106 self.file, @"file",
107 [NSNumber numberWithInt:self.line], @"line",
108 nil
109 ];
110 }
111
112 /**
113 * Pretty-print
114 */
115 - (NSString*)description
116 {
117 return [NSString stringWithFormat:@"%@:%lu", self.file, self.line];
118 }
119
120 @end