Comment out the saving of breakpoints to NSUserDefaults because it's generating a...
[macgdbp.git] / Source / BreakpointManager.m
1 /*
2 * MacGDBp
3 * Copyright (c) 2007 - 2008, 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 "BreakpointManager.h"
18
19 NSString *kdBreakpoints = @"breakpoints";
20
21 @implementation BreakpointManager
22
23 /**
24 * Initializer
25 */
26 - (id)init
27 {
28 if (self = [super init])
29 {
30 breakpoints = (NSMutableDictionary *)[[NSUserDefaults standardUserDefaults] objectForKey:kdBreakpoints];
31 if (!breakpoints)
32 {
33 breakpoints = [NSMutableDictionary dictionary];
34 }
35 }
36 return self;
37 }
38
39 /**
40 * Returns the shared manager (singleton)
41 */
42 + (BreakpointManager *)sharedManager
43 {
44 static BreakpointManager *manager;
45 if (!manager)
46 {
47 manager = [[BreakpointManager alloc] init];
48 }
49 return manager;
50 }
51
52 /**
53 * Registers a breakpoint at a given line
54 */
55 - (void)addBreakpoint:(Breakpoint *)bp;
56 {
57 NSMutableSet *lines = [breakpoints valueForKey:[bp file]];
58 if (lines == nil)
59 {
60 lines = [NSMutableSet setWithObject:bp];
61 [breakpoints setValue:lines forKey:[bp file]];
62 }
63 else
64 {
65 [lines addObject:bp];
66 }
67 // TODO: use NSDictionary to store breakoints because we can only archive defaults in NSUserDefaults
68 //[[NSUserDefaults standardUserDefaults] setObject:breakpoints forKey:kdBreakpoints];
69 //NSLog(@"breakpoints = %@", breakpoints);
70 }
71
72 /**
73 * Removes a breakpoint at a given line/file combination, or nil if nothing was removed
74 */
75 - (Breakpoint *)removeBreakpointAt:(int)line inFile:(NSString *)file
76 {
77 NSMutableSet *lines = [breakpoints valueForKey:file];
78 for (Breakpoint *b in lines)
79 {
80 if ([b line] == line)
81 {
82 [lines removeObject:b];
83 // TODO: use NSDictionary
84 //[[NSUserDefaults standardUserDefaults] setObject:breakpoints forKey:kdBreakpoints];
85 return b;
86 }
87 }
88 return nil;
89 }
90
91 /**
92 * Returns all the breakpoints for a given file
93 */
94 - (NSSet *)breakpointsForFile:(NSString *)file
95 {
96 return [breakpoints valueForKey:file];
97 }
98
99 /**
100 * Checks to see if a given file has a breakpoint on a given line
101 */
102 - (BOOL)hasBreakpointAt:(int)line inFile:(NSString *)file
103 {
104 NSSet *lines = [breakpoints valueForKey:file];
105 if (!lines)
106 {
107 return NO;
108 }
109 for (Breakpoint *b in lines)
110 {
111 if ([b line] == line)
112 {
113 return YES;
114 }
115 }
116 return NO;
117 }
118
119 @end