summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomguy3 <randomguy3@7c02a99a-9b00-45e3-bf44-6f3dd7fddb64>2012-03-08 18:22:22 +0000
committerrandomguy3 <randomguy3@7c02a99a-9b00-45e3-bf44-6f3dd7fddb64>2012-03-08 18:22:22 +0000
commit0cd05a572e48b1e649ecdc8b24920c497e40466e (patch)
tree3f6e2aa5543c809fc7727e070c5e7ae11f3eaa3e
parentd26e56e2fd57da2dadddf760b2984956f7daa069 (diff)
Fix how copying is implemented
git-svn-id: https://tikzit.svn.sourceforge.net/svnroot/tikzit/trunk@419 7c02a99a-9b00-45e3-bf44-6f3dd7fddb64
-rw-r--r--tikzit/src/common/Edge.h8
-rw-r--r--tikzit/src/common/Edge.m4
-rw-r--r--tikzit/src/common/GraphChange.m33
-rw-r--r--tikzit/src/common/GraphElementData.h2
-rw-r--r--tikzit/src/common/GraphElementData.m4
-rw-r--r--tikzit/src/common/GraphElementProperty.h8
-rw-r--r--tikzit/src/common/GraphElementProperty.m8
-rw-r--r--tikzit/src/common/Node.h8
-rw-r--r--tikzit/src/common/Node.m64
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<NSCopying> {
Node *source;
Node *target;
Node *edgeNode;
@@ -353,12 +353,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<NSCopying> {
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<NSCopying> {
NSPoint point;
NodeStyle *style;
NSString *name;
@@ -141,12 +141,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