| 1 |
/* $Id$ */ |
|---|
| 2 |
|
|---|
| 3 |
/* |
|---|
| 4 |
* Copyright (c) 2005-2008 Axel Andersson |
|---|
| 5 |
* All rights reserved. |
|---|
| 6 |
* |
|---|
| 7 |
* Redistribution and use in source and binary forms, with or without |
|---|
| 8 |
* modification, are permitted provided that the following conditions |
|---|
| 9 |
* are met: |
|---|
| 10 |
* 1. Redistributions of source code must retain the above copyright |
|---|
| 11 |
* notice, this list of conditions and the following disclaimer. |
|---|
| 12 |
* 2. Redistributions in binary form must reproduce the above copyright |
|---|
| 13 |
* notice, this list of conditions and the following disclaimer in the |
|---|
| 14 |
* documentation and/or other materials provided with the distribution. |
|---|
| 15 |
* |
|---|
| 16 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
|---|
| 17 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|---|
| 18 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|---|
| 19 |
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
|---|
| 20 |
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|---|
| 21 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|---|
| 22 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|---|
| 23 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|---|
| 24 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|---|
| 25 |
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|---|
| 26 |
* POSSIBILITY OF SUCH DAMAGE. |
|---|
| 27 |
*/ |
|---|
| 28 |
|
|---|
| 29 |
#import "TNPerlNode.h" |
|---|
| 30 |
|
|---|
| 31 |
@interface TNPerlNode(Private) |
|---|
| 32 |
|
|---|
| 33 |
- (void)_refreshPercentForTotalTime:(NSTimeInterval)time; |
|---|
| 34 |
|
|---|
| 35 |
@end |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
@implementation TNPerlNode(Private) |
|---|
| 39 |
|
|---|
| 40 |
- (void)_refreshPercentForTotalTime:(NSTimeInterval)time { |
|---|
| 41 |
NSUInteger i, count; |
|---|
| 42 |
|
|---|
| 43 |
_percent = time > 0.0 ? (_time / time) * 100.0 : 100.0; |
|---|
| 44 |
_cumulativePercent = time > 0.0 ? (_cumulativeTime / time) * 100.0 : 100.0; |
|---|
| 45 |
|
|---|
| 46 |
count = [_children count]; |
|---|
| 47 |
|
|---|
| 48 |
for(i = 0; i < count; i++) |
|---|
| 49 |
[[_children objectAtIndex:i] _refreshPercentForTotalTime:time]; |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
@end |
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
@implementation TNPerlNode |
|---|
| 57 |
|
|---|
| 58 |
- (id)copyWithZone:(NSZone *)zone { |
|---|
| 59 |
TNPerlNode *node; |
|---|
| 60 |
|
|---|
| 61 |
node = [super copyWithZone:zone]; |
|---|
| 62 |
node->_time = _time; |
|---|
| 63 |
node->_cumulativeTime = _cumulativeTime; |
|---|
| 64 |
|
|---|
| 65 |
return node; |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
#pragma mark - |
|---|
| 71 |
|
|---|
| 72 |
- (NSComparisonResult)compareValue:(TNPerlNode *)node { |
|---|
| 73 |
if(_time < node->_time) |
|---|
| 74 |
return (_sortOrder == TNSortAscending) ? NSOrderedAscending : NSOrderedDescending; |
|---|
| 75 |
else if(_time > node->_time) |
|---|
| 76 |
return (_sortOrder == TNSortAscending) ? NSOrderedDescending : NSOrderedAscending; |
|---|
| 77 |
|
|---|
| 78 |
return NSOrderedSame; |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
- (NSComparisonResult)compareCumulativeValue:(TNPerlNode *)node { |
|---|
| 84 |
if(_cumulativeTime < node->_cumulativeTime) |
|---|
| 85 |
return (_sortOrder == TNSortAscending) ? NSOrderedAscending : NSOrderedDescending; |
|---|
| 86 |
else if(_cumulativeTime > node->_cumulativeTime) |
|---|
| 87 |
return (_sortOrder == TNSortAscending) ? NSOrderedDescending : NSOrderedAscending; |
|---|
| 88 |
|
|---|
| 89 |
return NSOrderedSame; |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
#pragma mark - |
|---|
| 95 |
|
|---|
| 96 |
- (void)joinWithNode:(TNPerlNode *)node { |
|---|
| 97 |
_time += node->_time; |
|---|
| 98 |
_cumulativeTime += node->_cumulativeTime; |
|---|
| 99 |
|
|---|
| 100 |
[super joinWithNode:node]; |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
- (void)unlink { |
|---|
| 106 |
TNPerlNode *node; |
|---|
| 107 |
|
|---|
| 108 |
for(node = (TNPerlNode *) _parent; node != NULL; node = (TNPerlNode *) node->_parent) |
|---|
| 109 |
node->_cumulativeTime -= _cumulativeTime; |
|---|
| 110 |
|
|---|
| 111 |
[super unlink]; |
|---|
| 112 |
} |
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
#pragma mark - |
|---|
| 117 |
|
|---|
| 118 |
- (void)addTime:(NSTimeInterval)time { |
|---|
| 119 |
TNPerlNode *node; |
|---|
| 120 |
|
|---|
| 121 |
for(node = self; node != NULL; node = (TNPerlNode *) node->_parent) |
|---|
| 122 |
node->_cumulativeTime += time; |
|---|
| 123 |
|
|---|
| 124 |
_time += time; |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
- (void)refreshPercent { |
|---|
| 130 |
NSUInteger i, count; |
|---|
| 131 |
NSTimeInterval time; |
|---|
| 132 |
|
|---|
| 133 |
time = 0.0; |
|---|
| 134 |
count = [_children count]; |
|---|
| 135 |
|
|---|
| 136 |
for(i = 0; i < count; i++) |
|---|
| 137 |
time += ((TNPerlNode *) [_children objectAtIndex:i])->_cumulativeTime; |
|---|
| 138 |
|
|---|
| 139 |
[self _refreshPercentForTotalTime:time]; |
|---|
| 140 |
} |
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
#pragma mark - |
|---|
| 145 |
|
|---|
| 146 |
- (NSTimeInterval)time { |
|---|
| 147 |
return _time; |
|---|
| 148 |
} |
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
- (NSTimeInterval)cumulativeTime { |
|---|
| 153 |
return _cumulativeTime; |
|---|
| 154 |
} |
|---|
| 155 |
|
|---|
| 156 |
@end |
|---|