forked from pixmeo/osirix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathN2Debug.mm
81 lines (59 loc) · 2.08 KB
/
N2Debug.mm
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
/*=========================================================================
Program: OsiriX
Copyright (c) OsiriX Team
All rights reserved.
Distributed under GNU - LGPL
See http://www.osirix-viewer.com/copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
=========================================================================*/
#import "N2Debug.h"
#import "NSException+N2.h"
@implementation N2Debug
static BOOL _active = NO;
+(BOOL)isActive {
return _active;
}
+(void)setActive:(BOOL)active {
_active = active;
}
@end
extern "C" {
NSString* RectString(NSRect r) {
return [NSString stringWithFormat:@"[%f,%f,%f,%f]", r.origin.x, r.origin.y, r.size.width, r.size.height];
}
NSString* PointString(NSPoint p) {
return [NSString stringWithFormat:@"[%f,%f]", p.x, p.y];
}
void _N2LogErrorImpl(const char* pf, const char* fileName, int lineNumber, id arg, ...) {
va_list args;
va_start(args, arg);
NSString* message = @"no details";
if ([arg isKindOfClass:[NSString class]])
message = [[[NSString alloc] initWithFormat:arg arguments:args] autorelease];
if ([arg isKindOfClass:[NSError class] ])
message = [(NSError*)arg description];
va_end(args);
NSLog(@"Error (in %s): %@ (%s:%d)", pf, message, fileName, lineNumber);
}
void _N2LogExceptionVImpl(NSException* e, BOOL logStack, const char* pf, NSString* format, va_list args) {
NSString* message = format? [[[NSString alloc] initWithFormat:format arguments:args] autorelease] : e.name;
@synchronized(NSApp) {
NSLog(@"%@ (in %s): %@%@", message, pf, e, logStack? [NSString stringWithFormat:@"\n%@", e.stackTrace] : @"");
}
}
void _N2LogExceptionImpl(NSException* e, BOOL logStack, const char* pf) {
_N2LogExceptionVImpl(e, logStack, pf, nil, nil);
}
extern void N2LogStackTrace(NSString* format, ...) {
va_list args;
va_start(args, format);
@try {
[NSException raise:NSGenericException format:@""];
} @catch (NSException* e) {
_N2LogExceptionVImpl(e, YES, "", format, args);
}
va_end(args);
}
}