PageRenderTime 30ms CodeModel.GetById 17ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

/core/externals/google-toolbox-for-mac/Foundation/GTMCalculatedRange.h

http://macfuse.googlecode.com/
C++ Header | 105 lines | 15 code | 8 blank | 82 comment | 0 complexity | ff4854304b3de0fe91f472f14d9a6e98 MD5 | raw file
  1//
  2//  GTMCalculatedRange.h
  3//
  4//  This is a collection that allows you to calculate a value based on
  5//  defined stops in a range.
  6//
  7//  Copyright 2006-2008 Google Inc.
  8//
  9//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
 10//  use this file except in compliance with the License.  You may obtain a copy
 11//  of the License at
 12//
 13//  http://www.apache.org/licenses/LICENSE-2.0
 14//
 15//  Unless required by applicable law or agreed to in writing, software
 16//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 17//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 18//  License for the specific language governing permissions and limitations under
 19//  the License.
 20//
 21
 22#import <Foundation/Foundation.h>
 23#import "GTMDefines.h"
 24#if GTM_IPHONE_SDK
 25#import <CoreGraphics/CoreGraphics.h>
 26#endif //  GTM_IPHONE_SDK
 27
 28///  Allows you to calculate a value based on defined stops in a range.
 29//
 30///  For example if you have a range from 0.0 to 1.0 where the stop
 31///  located at 0.0 is red and the stop located at 1.0 is blue,
 32///  the value based on the position 0.5 would come out as purple assuming
 33///  that the valueAtPosition function calculates a purely linear mapping between
 34///  the stops at 0.0 and 1.0. Stops have indices and are sorted from lowest to
 35///  highest. The example above would have 2 stops. Stop 0 would be red and stop
 36///  1 would be blue.
 37///
 38///  Subclasses of GTMCalculatedRange are expected to override the valueAtPosition:
 39///  method to return a value based on the position passed in, and the stops
 40///  that are currently set in the range. Stops do not necessarily have to
 41///  be the same type as the values that are calculated, but normally they are.
 42@interface GTMCalculatedRange : NSObject {
 43  NSMutableArray *storage_;
 44}
 45
 46//  Adds a stop to the range at |position|. If there is already a stop
 47//  at position |position| it is replaced.
 48//
 49//  Args:
 50//    item: the object to place at |position|.
 51//    position: the position in the range to put |item|.
 52//
 53- (void)insertStop:(id)item atPosition:(CGFloat)position;
 54
 55//  Removes a stop from the range at |position|.
 56//
 57//  Args:
 58//    position: the position in the range to remove |item|.
 59//
 60//  Returns:
 61//    YES if there is a stop at |position| that has been removed
 62//    NO if there is not a stop at the |position|
 63- (BOOL)removeStopAtPosition:(CGFloat)position;
 64
 65//  Removes stop |index| from the range. Stops are ordered
 66//  based on position where index of x <  index of y if position
 67//  of x < position of y.
 68//
 69//  Args:
 70//    item: the object to place at |position|.
 71//    position: the position in the range to put |item|.
 72//
 73- (void)removeStopAtIndex:(NSUInteger)index;
 74
 75//  Returns the number of stops in the range.
 76//
 77//  Returns:
 78//    number of stops
 79- (NSUInteger)stopCount;
 80
 81//  Returns the value at position |position|.
 82//  This function should be overridden by subclasses to calculate a
 83//  value for any given range.
 84//  The default implementation returns a value if there happens to be
 85//  a stop for the given position. Otherwise it returns nil.
 86//
 87//  Args:
 88//    position: the position to calculate a value for.
 89//
 90//  Returns:
 91//    value for position
 92- (id)valueAtPosition:(CGFloat)position;
 93
 94//  Returns the |index|'th stop and position in the set.
 95//  Throws an exception if out of range.
 96//
 97//  Args:
 98//    index: the index of the stop
 99//    outPosition: a pointer to a value to be filled in with a position.
100//                  this can be NULL, in which case no position is returned.
101//
102//  Returns:
103//    the stop at the index.
104- (id)stopAtIndex:(NSUInteger)index position:(CGFloat*)outPosition;
105@end