Archived
1

Added Documentation

This commit is contained in:
Kim Wittenburg
2014-11-10 21:45:50 +01:00
parent f4f924bd71
commit 10f0e73ad3
32 changed files with 1847 additions and 318 deletions

View File

@@ -8,16 +8,21 @@
#import "MPRangePath.h"
@implementation MPRangePath
#pragma mark Creation Methods
- (instancetype)init
{
return [self initWithLocation:[[NSIndexPath alloc] init]
length:0];
}
- (instancetype)initWithLocation:(NSIndexPath *)location
length:(NSUInteger)length
{
@@ -29,17 +34,26 @@
return self;
}
- (instancetype)initWithRange:(NSRange)aRange
{
return [self initWithLocation:[[NSIndexPath alloc] initWithIndex:aRange.location]
length:aRange.length];
}
+ (instancetype)emptyRangePath
+ (instancetype)rangePath
{
return [[self alloc] init];
}
+ (instancetype)rangePathWithRange:(NSRange)aRange
{
return [[self alloc] initWithRange:aRange];
}
+ (instancetype)rangePathWithLocation:(NSIndexPath *)location
length:(NSUInteger)length
{
@@ -47,13 +61,10 @@
length:length];
}
+ (instancetype)rangePathWithRange:(NSRange)aRange
{
return [[self alloc] initWithRange:aRange];
}
#pragma mark Properties
- (NSIndexPath *)maxRangePath
{
NSUInteger lastIndex = [self.location indexAtPosition:self.location.length-1];
@@ -61,12 +72,21 @@
return [[self.location indexPathByRemovingLastIndex] indexPathByAddingIndex:newLastIndex];
}
- (NSRange)rangeAtLastIndex
{
return NSMakeRange([self.location indexAtPosition:self.location.length-1], self.length);
}
#pragma mark Working with Ranges
#pragma mark Working With Ranges
- (BOOL)containsLocation:(NSIndexPath *)location
{
return [self containsRangePath:[[MPRangePath alloc] initWithLocation:location length:0]];
}
- (BOOL)containsRangePath:(MPRangePath *)aRangePath
{
@@ -91,10 +111,6 @@
}
}
- (BOOL)containsLocation:(NSIndexPath *)location
{
return [self containsRangePath:[[MPRangePath alloc] initWithLocation:location length:0]];
}
- (BOOL)isEqual:(id)object
{
@@ -110,11 +126,13 @@
return [self isEqualToRangePath:(MPRangePath *)object];
}
- (BOOL)isEqualToRangePath:(MPRangePath *)aRangePath
{
return [self.location isEqual:aRangePath.location] && self.length == aRangePath.length;
}
- (NSString *)description
{
NSMutableString *description = [[NSMutableString alloc] initWithString:@"MPRangePath<location="];
@@ -129,30 +147,38 @@
return description.copy;
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
{
MPRangePath *copy = [[MPRangePath allocWithZone:zone] initWithLocation:self.location.copy length:self.length];
return copy;
}
#pragma mark - NSCoding
- (id)initWithCoder:(NSCoder *)aDecoder
{
return [self initWithLocation:[aDecoder decodeObjectForKey:@"location"]
length:[aDecoder decodeIntegerForKey:@"length"]];
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:self.location forKey:@"location"];
[aCoder encodeInteger:self.length forKey:@"length"];
}
@end
@implementation MPExpression (MPRangeExtension)
- (NSArray *)itemsInRangePath:(MPRangePath *)rangePath
@@ -162,6 +188,7 @@
return [targetExpression itemsInRange:rangePath.rangeAtLastIndex referenceFrame:referenceFrame];
}
- (MPExpression *)subexpressionWithRangePath:(MPRangePath *)aRangePath
referenceFrame:(MPReferenceFrame)referenceFrame
{
@@ -174,6 +201,7 @@
referenceFrame:referenceFrame];
}
- (void)replaceItemsInRangePath:(MPRangePath *)rangePath
referenceFrame:(MPReferenceFrame)referenceFrame
withElements:(NSArray *)elements