From 0cd05a572e48b1e649ecdc8b24920c497e40466e Mon Sep 17 00:00:00 2001 From: randomguy3 Date: Thu, 8 Mar 2012 18:22:22 +0000 Subject: Fix how copying is implemented git-svn-id: https://tikzit.svn.sourceforge.net/svnroot/tikzit/trunk@419 7c02a99a-9b00-45e3-bf44-6f3dd7fddb64 --- tikzit/src/common/Edge.h | 8 +--- tikzit/src/common/Edge.m | 4 +- tikzit/src/common/GraphChange.m | 33 +--------------- tikzit/src/common/GraphElementData.h | 2 - tikzit/src/common/GraphElementData.m | 4 +- tikzit/src/common/GraphElementProperty.h | 8 +--- tikzit/src/common/GraphElementProperty.m | 8 ++-- tikzit/src/common/Node.h | 8 +--- tikzit/src/common/Node.m | 64 ++++++-------------------------- 9 files changed, 25 insertions(+), 114 deletions(-) diff --git a/tikzit/src/common/Edge.h b/tikzit/src/common/Edge.h index 959a724..43c7b76 100644 --- a/tikzit/src/common/Edge.h +++ b/tikzit/src/common/Edge.h @@ -48,7 +48,7 @@ typedef enum { also contains methods for computing the bezier control points and the midpoint of the curve. */ -@interface Edge : NSObject { +@interface Edge : NSObject { Node *source; Node *target; Node *edgeNode; @@ -352,12 +352,6 @@ typedef enum { */ - (void)reverse; -/*! - @brief Copy this edge. - @result A copy of this edge. - */ -- (id)copy; - /*! @brief Factory method to make a blank edge. @result An edge. diff --git a/tikzit/src/common/Edge.m b/tikzit/src/common/Edge.m index 9e983d5..ed25333 100644 --- a/tikzit/src/common/Edge.m +++ b/tikzit/src/common/Edge.m @@ -571,8 +571,8 @@ [super dealloc]; } -- (id)copy { - Edge *cp = [[Edge alloc] init]; +- (id)copyWithZone:(NSZone*)zone { + Edge *cp = [[Edge allocWithZone:zone] init]; [cp setSource:[self source]]; [cp setTarget:[self target]]; [cp setPropertiesFromEdge:self]; diff --git a/tikzit/src/common/GraphChange.m b/tikzit/src/common/GraphChange.m index 7375150..9707a19 100644 --- a/tikzit/src/common/GraphChange.m +++ b/tikzit/src/common/GraphChange.m @@ -40,41 +40,12 @@ @synthesize shiftPoint, horizontal; @synthesize affectedEdges, affectedNodes; @synthesize edgeRef, nodeRef; - -// For some reason, gcc screws up the typing for these -// properties when we use @synthesize, so instead we -// define them manually. -- (Node*) nwNode { return nwNode; } -- (void) setNwNode:(Node*)e { - Node *cp = [e copy]; - [nwNode release]; - nwNode = cp; -} -- (Node*) oldNode { return oldNode; } -- (void) setOldNode:(Node*)e { - Node *cp = [e copy]; - [oldNode release]; - oldNode = cp; -} -- (Edge*) nwEdge { return nwEdge; } -- (void) setNwEdge:(Edge*)e { - Edge *cp = [e copy]; - [nwEdge release]; - nwEdge = cp; -} -- (Edge*) oldEdge { return oldEdge; } -- (void) setOldEdge:(Edge*)e { - Edge *cp = [e copy]; - [oldEdge release]; - oldEdge = cp; -} +@synthesize nwNode, oldNode; +@synthesize nwEdge, oldEdge; @synthesize oldNodeTable, nwNodeTable; @synthesize oldEdgeTable, nwEdgeTable; - @synthesize oldBoundingBox, nwBoundingBox; - @synthesize oldGraphData, nwGraphData; - @synthesize oldNodeOrder, newNodeOrder; @synthesize oldEdgeOrder, newEdgeOrder; diff --git a/tikzit/src/common/GraphElementData.h b/tikzit/src/common/GraphElementData.h index 1136dbd..0353be6 100644 --- a/tikzit/src/common/GraphElementData.h +++ b/tikzit/src/common/GraphElementData.h @@ -87,8 +87,6 @@ */ - (NSString*)stringList; -- (id)copy; - @end // vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/GraphElementData.m b/tikzit/src/common/GraphElementData.m index 02b747b..c05cb4b 100644 --- a/tikzit/src/common/GraphElementData.m +++ b/tikzit/src/common/GraphElementData.m @@ -119,8 +119,8 @@ return ([s isEqualToString:@""]) ? @"" : [NSString stringWithFormat:@"[%@]", s]; } -- (id)copy { - GraphElementData *cp = [[GraphElementData alloc] init]; +- (id)copyWithZone:(NSZone *)zone { + GraphElementData *cp = [[GraphElementData allocWithZone:zone] init]; NSEnumerator *en = [properties objectEnumerator]; GraphElementProperty *p, *p2; while ((p = [en nextObject]) != nil) { diff --git a/tikzit/src/common/GraphElementProperty.h b/tikzit/src/common/GraphElementProperty.h index e8fe2a2..3ca93dc 100644 --- a/tikzit/src/common/GraphElementProperty.h +++ b/tikzit/src/common/GraphElementProperty.h @@ -28,7 +28,7 @@ @brief A property. I.e. a single entry in a node's/edge's/graph's GraphElementData table. */ -@interface GraphElementProperty : NSObject { +@interface GraphElementProperty : NSObject { NSString *key; NSString *value; BOOL isAtom; @@ -80,12 +80,6 @@ */ - (BOOL)isEqual:(id)object; -/*! - @brief Make a deep copy of this property. - @result A new property. - */ -- (id)copy; - @end // vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/GraphElementProperty.m b/tikzit/src/common/GraphElementProperty.m index 79abe79..9751230 100644 --- a/tikzit/src/common/GraphElementProperty.m +++ b/tikzit/src/common/GraphElementProperty.m @@ -102,13 +102,13 @@ return [self matches:object]; } -- (id)copy { +- (id)copyWithZone:(NSZone*)zone { if (isAtom) { - return [[GraphElementProperty alloc] initWithAtomName:[self key]]; + return [[GraphElementProperty allocWithZone:zone] initWithAtomName:[self key]]; } else if (isKeyMatch) { - return [[GraphElementProperty alloc] initWithKeyMatching:[self key]]; + return [[GraphElementProperty allocWithZone:zone] initWithKeyMatching:[self key]]; } else { - return [[GraphElementProperty alloc] initWithPropertyValue:[self value] forKey:[self key]]; + return [[GraphElementProperty allocWithZone:zone] initWithPropertyValue:[self value] forKey:[self key]]; } } diff --git a/tikzit/src/common/Node.h b/tikzit/src/common/Node.h index c3a604d..844af83 100644 --- a/tikzit/src/common/Node.h +++ b/tikzit/src/common/Node.h @@ -36,7 +36,7 @@ @class Node @brief A graph node, with associated location and style data. */ -@interface Node : NSObject { +@interface Node : NSObject { NSPoint point; NodeStyle *style; NSString *name; @@ -140,12 +140,6 @@ */ - (void)updateData; -/*! - @brief Copy this node. - @result A copy of this node. - */ -- (id)copy; - /*! @brief Set properties of this node to match the given node. @param nd a node to mimic. diff --git a/tikzit/src/common/Node.m b/tikzit/src/common/Node.m index 136fe20..39b1e75 100644 --- a/tikzit/src/common/Node.m +++ b/tikzit/src/common/Node.m @@ -34,7 +34,6 @@ style = nil; label = @""; point = p; - //[self updateData]; return self; } @@ -122,12 +121,6 @@ [self setLabel:[nd label]]; } -- (id)copy { - Node *cp = [[Node alloc] init]; - [cp setPropertiesFromNode:self]; - return cp; -} - + (Node*)nodeWithPoint:(NSPoint)p { return [[[Node alloc] initWithPoint:p] autorelease]; } @@ -149,56 +142,21 @@ } } - -- (NSString*)name { - return name; -} - -- (void)setName:(NSString *)s { - if (name != s) { - [name release]; - name = [s copy]; - } -} - -- (NSString*)label { - return label; -} - -- (void)setLabel:(NSString *)s { - if (label != s) { - [label release]; - label = [s copy]; - } -} - -- (GraphElementData*)data { - return data; -} - -- (void)setData:(GraphElementData*)dt { - if (data != dt) { - [data release]; - data = [dt copy]; - } -} - -- (NSPoint)point { - return point; -} - -- (void)setPoint:(NSPoint)value { - point = value; -} +@synthesize name; +@synthesize label; +@synthesize point; +@synthesize data; - (NodeStyle*)style { return style; } - (void)setStyle:(NodeStyle *)st { - NodeStyle *oldStyle = style; - style = [st retain]; - [oldStyle release]; + if (style != st) { + NodeStyle *oldStyle = style; + style = [st retain]; + [oldStyle release]; + } [self updateData]; } @@ -210,7 +168,9 @@ } - (id)copyWithZone:(NSZone*)z { - return nil; + Node *cp = [[Node allocWithZone:z] init]; + [cp setPropertiesFromNode:self]; + return cp; } @end -- cgit v1.2.3