From a8a8dfb90d6a51ae369c042c95162f45754c7c4b Mon Sep 17 00:00:00 2001 From: randomguy3 Date: Mon, 9 Jan 2012 11:00:50 +0000 Subject: Move tikzit into "trunk" directory git-svn-id: https://tikzit.svn.sourceforge.net/svnroot/tikzit/trunk@365 7c02a99a-9b00-45e3-bf44-6f3dd7fddb64 --- tikzit/src/common/GraphElementProperty.m | 127 +++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 tikzit/src/common/GraphElementProperty.m (limited to 'tikzit/src/common/GraphElementProperty.m') diff --git a/tikzit/src/common/GraphElementProperty.m b/tikzit/src/common/GraphElementProperty.m new file mode 100644 index 0000000..79abe79 --- /dev/null +++ b/tikzit/src/common/GraphElementProperty.m @@ -0,0 +1,127 @@ +// +// +// GraphElementProperty.m +// TikZiT +// +// Copyright 2010 Aleks Kissinger. All rights reserved. +// +// +// This file is part of TikZiT. +// +// TikZiT is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// TikZiT is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with TikZiT. If not, see . +// + +#import "GraphElementProperty.h" + + +@implementation GraphElementProperty + +- (id)initWithAtomName:(NSString*)n { + [super init]; + [self setKey:n]; + [self setValue:nil]; + isAtom = YES; + isKeyMatch = NO; + return self; +} + +- (id)initWithPropertyValue:(NSString*)v forKey:(NSString*)k { + [super init]; + [self setKey:k]; + [self setValue:v]; + isAtom = NO; + isKeyMatch = NO; + return self; +} + +- (id)initWithKeyMatching:(NSString*)k { + [super init]; + [self setKey:k]; + [self setValue:nil]; + isAtom = NO; + isKeyMatch = YES; + return self; +} + +- (void)setValue:(NSString *)v { + if (value != v) { + [value release]; + value = [v copy]; + } +} + +- (NSString*)value { + if (isAtom) { + return @"(atom)"; + } else { + return value; + } +} + + +- (void)setKey:(NSString *)k { + if (k == nil) k = @""; // don't allow nil keys + if (key != k) { + [key release]; + key = [k retain]; + } +} + +- (NSString*)key { + return key; +} + +- (BOOL)isAtom { return isAtom; } +- (BOOL)isKeyMatch { return isKeyMatch; } + +- (BOOL)matches:(GraphElementProperty*)object { + // properties and atoms are taken to be incomparable + if ([self isAtom] != [object isAtom]) return NO; + + // only compare keys if (a) we are both atoms, (b) i am a key match, or (c) object is a key match + if (([self isAtom] && [object isAtom]) || [self isKeyMatch] || [object isKeyMatch]) { + return [[self key] isEqual:[object key]]; + } + + // otherwise compare key and value + return [[self key] isEqual:[object key]] && [[self value] isEqual:[object value]]; +} + +- (BOOL)isEqual:(id)object { + return [self matches:object]; +} + +- (id)copy { + if (isAtom) { + return [[GraphElementProperty alloc] initWithAtomName:[self key]]; + } else if (isKeyMatch) { + return [[GraphElementProperty alloc] initWithKeyMatching:[self key]]; + } else { + return [[GraphElementProperty alloc] initWithPropertyValue:[self value] forKey:[self key]]; + } +} + +- (NSString*)description { + if ([self isAtom]) { + return [self key]; + } else if ([self isKeyMatch]) { + return [NSString stringWithFormat:@"%@=*", [self key]]; + } else { + return [NSString stringWithFormat:@"%@=%@", [self key], [self value]]; + } +} + +@end + +// vi:ft=objc:ts=4:noet:sts=4:sw=4 -- cgit v1.2.3