Permalink
Browse files

Major refactoring of library. KissXML is now faster and fully read-ac…

…cess thread-safe.
  • Loading branch information...
1 parent a1218bf commit eee566382f5a2acf622f1e4a04a4d4b9ad2f69e3 @robbiehanson committed Apr 22, 2011
View
@@ -1,79 +0,0 @@
-#import "DDXMLNode.h"
-#import "DDXMLElement.h"
-#import "DDXMLDocument.h"
-
-// We can't rely solely on NSAssert, because many developers disable them for release builds.
-// Our API contract requires us to keep these assertions intact.
-#define DDCheck(condition, desc, ...) { if(!(condition)) { [[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd object:self file:[NSString stringWithUTF8String:__FILE__] lineNumber:__LINE__ description:(desc), ##__VA_ARGS__]; } }
-
-#define DDLastErrorKey @"DDXML:LastError"
-
-
-@interface DDXMLNode (PrivateAPI)
-
-+ (id)nodeWithUnknownPrimitive:(xmlKindPtr)kindPtr;
-
-+ (id)nodeWithPrimitive:(xmlKindPtr)kindPtr;
-- (id)initWithCheckedPrimitive:(xmlKindPtr)kindPtr;
-
-+ (id)nodeWithPrimitive:(xmlNsPtr)ns nsParent:(xmlNodePtr)parent;
-- (id)initWithCheckedPrimitive:(xmlNsPtr)ns nsParent:(xmlNodePtr)parent;
-
-+ (BOOL)isXmlAttrPtr:(xmlKindPtr)kindPtr;
-- (BOOL)isXmlAttrPtr;
-
-+ (BOOL)isXmlNodePtr:(xmlKindPtr)kindPtr;
-- (BOOL)isXmlNodePtr;
-
-+ (BOOL)isXmlDocPtr:(xmlKindPtr)kindPtr;
-- (BOOL)isXmlDocPtr;
-
-+ (BOOL)isXmlDtdPtr:(xmlKindPtr)kindPtr;
-- (BOOL)isXmlDtdPtr;
-
-+ (BOOL)isXmlNsPtr:(xmlKindPtr)kindPtr;
-- (BOOL)isXmlNsPtr;
-
-- (BOOL)hasParent;
-
-+ (void)recursiveStripDocPointersFromNode:(xmlNodePtr)node;
-
-+ (void)detachAttribute:(xmlAttrPtr)attr fromNode:(xmlNodePtr)node;
-+ (void)removeAttribute:(xmlAttrPtr)attr fromNode:(xmlNodePtr)node;
-+ (void)removeAllAttributesFromNode:(xmlNodePtr)node;
-
-+ (void)detachNamespace:(xmlNsPtr)ns fromNode:(xmlNodePtr)node;
-+ (void)removeNamespace:(xmlNsPtr)ns fromNode:(xmlNodePtr)node;
-+ (void)removeAllNamespacesFromNode:(xmlNodePtr)node;
-
-+ (void)detachChild:(xmlNodePtr)child fromNode:(xmlNodePtr)node;
-+ (void)removeChild:(xmlNodePtr)child fromNode:(xmlNodePtr)node;
-+ (void)removeAllChildrenFromNode:(xmlNodePtr)node;
-
-+ (void)removeAllChildrenFromDoc:(xmlDocPtr)doc;
-
-- (void)nodeRetain;
-- (void)nodeRelease;
-
-+ (NSError *)lastError;
-
-@end
-
-@interface DDXMLElement (PrivateAPI)
-
-+ (id)nodeWithPrimitive:(xmlKindPtr)kindPtr;
-- (id)initWithCheckedPrimitive:(xmlKindPtr)kindPtr;
-
-- (NSArray *)elementsWithName:(NSString *)name uri:(NSString *)URI;
-
-+ (DDXMLNode *)resolveNamespaceForPrefix:(NSString *)prefix atNode:(xmlNodePtr)nodePtr;
-+ (NSString *)resolvePrefixForURI:(NSString *)uri atNode:(xmlNodePtr)nodePtr;
-
-@end
-
-@interface DDXMLDocument (PrivateAPI)
-
-+ (id)nodeWithPrimitive:(xmlKindPtr)kindPtr;
-- (id)initWithCheckedPrimitive:(xmlKindPtr)kindPtr;
-
-@end
File renamed without changes.
File renamed without changes.
@@ -2,7 +2,7 @@
#import <libxml/tree.h>
-@interface NSString (NSStringAdditions)
+@interface NSString (DDXML)
/**
* xmlChar - A basic replacement for char, a byte in a UTF-8 encoded string.
@@ -1,7 +1,7 @@
-#import "NSStringAdditions.h"
+#import "NSString+DDXML.h"
-@implementation NSString (NSStringAdditions)
+@implementation NSString (DDXML)
- (const xmlChar *)xmlChar
{
File renamed without changes.
File renamed without changes.
@@ -1,40 +1,41 @@
-#import "DDXMLDocument.h"
-#import "NSStringAdditions.h"
#import "DDXMLPrivate.h"
+#import "NSString+DDXML.h"
@implementation DDXMLDocument
/**
* Returns a DDXML wrapper object for the given primitive node.
* The given node MUST be non-NULL and of the proper type.
- *
- * If the wrapper object already exists, it is retained/autoreleased and returned.
- * Otherwise a new wrapper object is alloc/init/autoreleased and returned.
**/
-+ (id)nodeWithPrimitive:(xmlKindPtr)kindPtr
++ (id)nodeWithDocPrimitive:(xmlDocPtr)doc freeOnDealloc:(BOOL)flag
{
- // If a wrapper object already exists, the _private variable is pointing to it.
-
- xmlDocPtr doc = (xmlDocPtr)kindPtr;
- if(doc->_private == NULL)
- return [[[DDXMLDocument alloc] initWithCheckedPrimitive:kindPtr] autorelease];
- else
- return [[((DDXMLDocument *)(doc->_private)) retain] autorelease];
+ return [[[DDXMLDocument alloc] initWithDocPrimitive:doc freeOnDealloc:flag] autorelease];
}
-/**
- * Returns a DDXML wrapper object for the given primitive node.
- * The given node MUST be non-NULL and of the proper type.
- *
- * The given node is checked, meaning a wrapper object for it does not already exist.
-**/
-- (id)initWithCheckedPrimitive:(xmlKindPtr)kindPtr
+- (id)initWithDocPrimitive:(xmlDocPtr)doc freeOnDealloc:(BOOL)flag
{
- self = [super initWithCheckedPrimitive:kindPtr];
+ self = [super initWithPrimitive:(xmlKindPtr)doc freeOnDealloc:flag];
return self;
}
++ (id)nodeWithPrimitive:(xmlKindPtr)kindPtr freeOnDealloc:(BOOL)flag
+{
+ // Promote initializers which use proper parameter types to enable compiler to catch more mistakes
+ NSAssert(NO, @"Use nodeWithDocPrimitive:freeOnDealloc:");
+
+ return nil;
+}
+
+- (id)initWithPrimitive:(xmlKindPtr)kindPtr freeOnDealloc:(BOOL)flag
+{
+ // Promote initializers which use proper parameter types to enable compiler to catch more mistakes.
+ NSAssert(NO, @"Use initWithDocPrimitive:freeOnDealloc:");
+
+ [self release];
+ return nil;
+}
+
/**
* Initializes and returns a DDXMLDocument object created from an NSData object.
*
@@ -43,7 +44,9 @@ - (id)initWithCheckedPrimitive:(xmlKindPtr)kindPtr
**/
- (id)initWithXMLString:(NSString *)string options:(NSUInteger)mask error:(NSError **)error
{
- return [self initWithData:[string dataUsingEncoding:NSUTF8StringEncoding] options:mask error:error];
+ return [self initWithData:[string dataUsingEncoding:NSUTF8StringEncoding]
+ options:mask
+ error:error];
}
/**
@@ -54,9 +57,9 @@ - (id)initWithXMLString:(NSString *)string options:(NSUInteger)mask error:(NSErr
**/
- (id)initWithData:(NSData *)data options:(NSUInteger)mask error:(NSError **)error
{
- if(data == nil || [data length] == 0)
+ if (data == nil || [data length] == 0)
{
- if(error) *error = [NSError errorWithDomain:@"DDXMLErrorDomain" code:0 userInfo:nil];
+ if (error) *error = [NSError errorWithDomain:@"DDXMLErrorDomain" code:0 userInfo:nil];
[self release];
return nil;
@@ -70,15 +73,15 @@ - (id)initWithData:(NSData *)data options:(NSUInteger)mask error:(NSError **)err
xmlKeepBlanksDefault(0);
xmlDocPtr doc = xmlParseMemory([data bytes], [data length]);
- if(doc == NULL)
+ if (doc == NULL)
{
- if(error) *error = [NSError errorWithDomain:@"DDXMLErrorDomain" code:1 userInfo:nil];
+ if (error) *error = [NSError errorWithDomain:@"DDXMLErrorDomain" code:1 userInfo:nil];
[self release];
return nil;
}
- return [self initWithCheckedPrimitive:(xmlKindPtr)doc];
+ return [self initWithDocPrimitive:doc freeOnDealloc:YES];
}
/**
@@ -92,8 +95,8 @@ - (DDXMLElement *)rootElement
xmlNodePtr rootNode = xmlDocGetRootElement(doc);
- if(rootNode != NULL)
- return [DDXMLElement nodeWithPrimitive:(xmlKindPtr)rootNode];
+ if (rootNode != NULL)
+ return [DDXMLElement nodeWithElementPrimitive:rootNode freeOnDealloc:NO];
else
return nil;
}
File renamed without changes.
Oops, something went wrong.

0 comments on commit eee5663

Please sign in to comment.