diff options
Diffstat (limited to 'tikzit/src/common')
-rw-r--r-- | tikzit/src/common/Graph.h | 35 | ||||
-rw-r--r-- | tikzit/src/common/Graph.m | 20 | ||||
-rw-r--r-- | tikzit/src/common/NSString+Tikz.m | 1 | ||||
-rw-r--r-- | tikzit/src/common/TikzShape.m | 3 |
4 files changed, 55 insertions, 4 deletions
diff --git a/tikzit/src/common/Graph.h b/tikzit/src/common/Graph.h index f5d8bed..1f98858 100644 --- a/tikzit/src/common/Graph.h +++ b/tikzit/src/common/Graph.h @@ -361,6 +361,41 @@ */ + (Graph*)graph; +/** + * Initialize an empty graph + */ +- (id)init; + +/** + * Constructs a graph from the given tikz code + * + * See TikzGraphAssembler for more information about the error argument. + */ ++ (Graph*)graphFromTikz:(NSString*)tikz error:(NSError**)e; + +/** + * Constructs a graph from the given tikz code + */ ++ (Graph*)graphFromTikz:(NSString*)tikz; + +/** + * Initialize an empty graph from the given tikz code + * + * Note that this may not return the same object it was called on, + * and will return nil if parsing failed. + * + * See TikzGraphAssembler for more information about the error argument. + */ +- (id)initFromTikz:(NSString*)tikz error:(NSError**)e; + +/** + * Initialize an empty graph from the given tikz code + * + * Note that this may not return the same object it was called on, + * and will return nil if parsing failed. + */ +- (id)initFromTikz:(NSString*)tikz; + @end // vi:ft=objc:noet:ts=4:sts=4:sw=4 diff --git a/tikzit/src/common/Graph.m b/tikzit/src/common/Graph.m index d18e4db..2a01bae 100644 --- a/tikzit/src/common/Graph.m +++ b/tikzit/src/common/Graph.m @@ -22,10 +22,11 @@ // #import "Graph.h" +#import "TikzGraphAssembler.h" @implementation Graph -- (Graph*)init { +- (id)init { self = [super init]; if (self != nil) { data = [[GraphElementData alloc] init]; @@ -39,6 +40,15 @@ return self; } +- (id)initFromTikz:(NSString*)tikz error:(NSError**)e { + [self release]; + return [[TikzGraphAssembler parseTikz:tikz error:e] retain]; +} + +- (id)initFromTikz:(NSString*)tikz { + return [self initFromTikz:tikz error:NULL]; +} + - (id) copyWithZone:(NSZone*)zone { Graph *newGraph = [self copyOfSubgraphWithNodes:[NSSet setWithArray:nodes] zone:zone]; [newGraph setData:[self data]]; @@ -765,6 +775,14 @@ return [[[self alloc] init] autorelease]; } ++ (Graph*)graphFromTikz:(NSString*)tikz error:(NSError**)e { + return [TikzGraphAssembler parseTikz:tikz error:e]; +} + ++ (Graph*)graphFromTikz:(NSString*)tikz { + return [self graphFromTikz:tikz error:NULL]; +} + + (NSMapTable*)nodeTableForNodes:(NSSet*)nds { return [self nodeTableForNodes:nds withZone:NSDefaultMallocZone()]; } diff --git a/tikzit/src/common/NSString+Tikz.m b/tikzit/src/common/NSString+Tikz.m index 85a51d3..8b11ad2 100644 --- a/tikzit/src/common/NSString+Tikz.m +++ b/tikzit/src/common/NSString+Tikz.m @@ -16,7 +16,6 @@ */ #import "NSString+Tikz.h" -#import "TikzGraphAssembler.h" @implementation NSString (Tikz) diff --git a/tikzit/src/common/TikzShape.m b/tikzit/src/common/TikzShape.m index 722275c..8cf823b 100644 --- a/tikzit/src/common/TikzShape.m +++ b/tikzit/src/common/TikzShape.m @@ -22,7 +22,6 @@ // #import "TikzShape.h" -#import "TikzGraphAssembler.h" #import "Graph.h" @implementation TikzShape @@ -35,7 +34,7 @@ error:NULL]; if (tikz == nil) return nil; - Graph *graph = [TikzGraphAssembler parseTikz:tikz]; + Graph *graph = [Graph graphFromTikz:tikz]; if (graph == nil) return nil; NSRect graphBounds = ([graph hasBoundingBox]) ? [graph boundingBox] : [graph bounds]; |