* Added $apply and some other collection utils.
* Moved logging code to a separate code segment.
* Fixed uninitialized variable in Target.
5 // Created by Jens Alfke on 3/25/08.
6 // Copyright 2008 __MyCompanyName__. All rights reserved.
12 #include <CoreServices/CoreServices.h>
13 #include <mach/mach.h>
14 #include <mach/mach_time.h>
18 /** Absolute time (since 'reference date') to NSDate. 0.0 -> nil. */
19 NSDate* $date( CFAbsoluteTime time )
21 CAssert(time>=0.0 && time < 1.0e15, @"Bogus timestamp %g",time);
22 return time ?[NSDate dateWithTimeIntervalSinceReferenceDate: time] :nil;
26 /** NSDate to absolute time (since 'reference date'). nil -> 0.0 */
27 CFAbsoluteTime $time( NSDate* date )
29 return date ?[date timeIntervalSinceReferenceDate] :0.0;
34 NSTimeInterval TimeIntervalSinceBoot(void)
36 // From http://developer.apple.com/qa/qa2004/qa1398.html
37 uint64_t abstime = mach_absolute_time();
38 // Have to do some pointer fun because AbsoluteToNanoseconds
39 // works in terms of UnsignedWide, which is a structure rather
40 // than a proper 64-bit integer.
41 Nanoseconds elapsedNano = AbsoluteToNanoseconds( *(AbsoluteTime *) &abstime );
42 return *(uint64_t*)&elapsedNano / 1.0e9;