/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. #import <Foundation/Foundation.h>
  22. #import "GTMDefines.h"
  23. #if GTM_IPHONE_SDK
  24. #import <CoreGraphics/CoreGraphics.h>
  25. #endif // GTM_IPHONE_SDK
  26. /// Allows you to calculate a value based on defined stops in a range.
  27. //
  28. /// For example if you have a range from 0.0 to 1.0 where the stop
  29. /// located at 0.0 is red and the stop located at 1.0 is blue,
  30. /// the value based on the position 0.5 would come out as purple assuming
  31. /// that the valueAtPosition function calculates a purely linear mapping between
  32. /// the stops at 0.0 and 1.0. Stops have indices and are sorted from lowest to
  33. /// highest. The example above would have 2 stops. Stop 0 would be red and stop
  34. /// 1 would be blue.
  35. ///
  36. /// Subclasses of GTMCalculatedRange are expected to override the valueAtPosition:
  37. /// method to return a value based on the position passed in, and the stops
  38. /// that are currently set in the range. Stops do not necessarily have to
  39. /// be the same type as the values that are calculated, but normally they are.
  40. @interface GTMCalculatedRange : NSObject {
  41. NSMutableArray *storage_;
  42. }
  43. // Adds a stop to the range at |position|. If there is already a stop
  44. // at position |position| it is replaced.
  45. //
  46. // Args:
  47. // item: the object to place at |position|.
  48. // position: the position in the range to put |item|.
  49. //
  50. - (void)insertStop:(id)item atPosition:(CGFloat)position;
  51. // Removes a stop from the range at |position|.
  52. //
  53. // Args:
  54. // position: the position in the range to remove |item|.
  55. //
  56. // Returns:
  57. // YES if there is a stop at |position| that has been removed
  58. // NO if there is not a stop at the |position|
  59. - (BOOL)removeStopAtPosition:(CGFloat)position;
  60. // Removes stop |index| from the range. Stops are ordered
  61. // based on position where index of x < index of y if position
  62. // of x < position of y.
  63. //
  64. // Args:
  65. // item: the object to place at |position|.
  66. // position: the position in the range to put |item|.
  67. //
  68. - (void)removeStopAtIndex:(NSUInteger)index;
  69. // Returns the number of stops in the range.
  70. //
  71. // Returns:
  72. // number of stops
  73. - (NSUInteger)stopCount;
  74. // Returns the value at position |position|.
  75. // This function should be overridden by subclasses to calculate a
  76. // value for any given range.
  77. // The default implementation returns a value if there happens to be
  78. // a stop for the given position. Otherwise it returns nil.
  79. //
  80. // Args:
  81. // position: the position to calculate a value for.
  82. //
  83. // Returns:
  84. // value for position
  85. - (id)valueAtPosition:(CGFloat)position;
  86. // Returns the |index|'th stop and position in the set.
  87. // Throws an exception if out of range.
  88. //
  89. // Args:
  90. // index: the index of the stop
  91. // outPosition: a pointer to a value to be filled in with a position.
  92. // this can be NULL, in which case no position is returned.
  93. //
  94. // Returns:
  95. // the stop at the index.
  96. - (id)stopAtIndex:(NSUInteger)index position:(CGFloat*)outPosition;
  97. @end