1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2024-11-14 19:49:02 +00:00
dupeguru/cocoalib/ValueTransformers.m

80 lines
1.4 KiB
Mathematica
Raw Normal View History

2013-06-23 01:32:48 +00:00
/*
2015-01-03 21:29:36 +00:00
Copyright 2015 Hardcoded Software (http://www.hardcoded.net)
2013-06-23 01:32:48 +00:00
2015-01-03 21:29:36 +00:00
This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
2013-06-23 01:32:48 +00:00
which should be included with this package. The terms are also available at
2015-01-03 21:29:36 +00:00
http://www.gnu.org/licenses/gpl-3.0.html
2013-06-23 01:32:48 +00:00
*/
#import "ValueTransformers.h"
#import "Utils.h"
@implementation VTIsIntIn
- (id)initWithValues:(NSIndexSet *)values
{
return [self initWithValues:values reverse:NO];
}
- (id)initWithValues:(NSIndexSet *)values reverse:(BOOL)doReverse
{
self = [super init];
ints = values;
[ints retain];
reverse = doReverse;
return self;
}
- (void)dealloc
{
[ints release];
[super dealloc];
}
+ (Class)transformedValueClass
{
return [NSNumber class]; //Boolean
}
+ (BOOL)allowsReverseTransformation
{
return NO;
}
- (id)transformedValue:(id)value
{
if (value == nil)
return nil;
NSNumber *i = value;
BOOL r = [ints containsIndex:[i intValue]];
if (reverse)
r = !r;
return [NSNumber numberWithBool:r];
}
@end
@implementation HSVTAdd
- (id)initWithValue:(int)value
{
self = [super init];
toAdd = value;
return self;
}
+ (Class)transformedValueClass
{
return [NSNumber class];
}
+ (BOOL)allowsReverseTransformation
{
return NO;
}
- (id)transformedValue:(id)value
{
if (value == nil)
return nil;
return i2n(n2i(value) + toAdd);
}
@end