mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 01:31:08 +00:00
Cleanup of ivars
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/branches/nsxml_using_libxml2@34514 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
f7aff866ac
commit
3fd92857a4
4 changed files with 67 additions and 69 deletions
|
@ -208,17 +208,7 @@ GS_PRIVATE_INTERNAL(NSXMLDocument)
|
|||
|
||||
- (void) setRootElement: (NSXMLNode*)root
|
||||
{
|
||||
/*
|
||||
NSArray *children;
|
||||
|
||||
NSAssert(root == nil, NSInvalidArgumentException);
|
||||
|
||||
// this method replaces *all* children with the specified element.
|
||||
children = [[NSArray alloc] initWithObjects: &root count: 1];
|
||||
[self setChildren: children];
|
||||
[children release];
|
||||
internal->rootElement = (NSXMLElement*)root;
|
||||
*/
|
||||
#warning properly dispose of old root element.
|
||||
xmlNodePtr newrootnode;
|
||||
NSAssert(root != nil, NSInvalidArgumentException);
|
||||
// Set
|
||||
|
@ -258,7 +248,7 @@ GS_PRIVATE_INTERNAL(NSXMLDocument)
|
|||
NSXMLNodeKind kind;
|
||||
|
||||
NSAssert(nil != child, NSInvalidArgumentException);
|
||||
NSAssert(index <= internal->childCount, NSInvalidArgumentException);
|
||||
NSAssert(index <= [self childCount], NSInvalidArgumentException);
|
||||
NSAssert(nil == [child parent], NSInvalidArgumentException);
|
||||
kind = [child kind];
|
||||
NSAssert(NSXMLAttributeKind != kind, NSInvalidArgumentException);
|
||||
|
|
|
@ -269,22 +269,17 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
|||
- (void) removeChildAtIndex: (NSUInteger)index
|
||||
{
|
||||
NSXMLNode *child;
|
||||
xmlNodePtr n;
|
||||
|
||||
if (index >= internal->childCount)
|
||||
if (index >= [self childCount])
|
||||
{
|
||||
[NSException raise: NSRangeException
|
||||
format: @"index to large"];
|
||||
}
|
||||
child = [internal->children objectAtIndex: index];
|
||||
GSIVar(child, parent) = nil;
|
||||
[internal->children removeObjectAtIndex: index];
|
||||
if (0 == --internal->childCount)
|
||||
{
|
||||
/* The -children method must return nil if there are no children,
|
||||
* so we destroy the container.
|
||||
*/
|
||||
DESTROY(internal->children);
|
||||
}
|
||||
|
||||
child = [[self children] objectAtIndex: index];
|
||||
n = [child _node];
|
||||
xmlUnlinkNode(n);
|
||||
}
|
||||
|
||||
- (void) setChildren: (NSArray*)children
|
||||
|
@ -310,7 +305,8 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
|
|||
|
||||
- (void) addChild: (NSXMLNode*)child
|
||||
{
|
||||
[self insertChild: child atIndex: internal->childCount];
|
||||
int count = [self childCount];
|
||||
[self insertChild: child atIndex: count];
|
||||
}
|
||||
|
||||
- (void) replaceChildAtIndex: (NSUInteger)index withNode: (NSXMLNode*)node
|
||||
|
|
|
@ -51,11 +51,11 @@ GS_PRIVATE_INTERNAL(NSXMLNode)
|
|||
|
||||
+ (NSXMLNode *) _objectForNode: (xmlNodePtr)node
|
||||
{
|
||||
if (!node)
|
||||
return nil;
|
||||
NSXMLNode *result = nil;
|
||||
|
||||
if (node)
|
||||
{
|
||||
xmlElementType type = node->type;
|
||||
NSXMLNode *result = (id)node->_private;
|
||||
xmlChar *name = NULL;
|
||||
// NSXMLNodeKind kind = 0;
|
||||
|
||||
|
@ -82,10 +82,32 @@ GS_PRIVATE_INTERNAL(NSXMLNode)
|
|||
parent = [self _objectForNode:node->parent];
|
||||
[parent _addSubNode:result];
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
+ (xmlNodePtr) _nodeForObject: (NSXMLNode *)object
|
||||
{
|
||||
xmlNodePtr node = NULL;
|
||||
if(object)
|
||||
{
|
||||
NSXMLNodeKind kind = [object kind];
|
||||
switch (kind)
|
||||
{
|
||||
case(NSXMLAttributeKind):
|
||||
node = xmlNewProp(NULL,
|
||||
XMLSTRING([object name]),
|
||||
XMLSTRING([object stringValue]));
|
||||
break;
|
||||
case(NSXMLElementKind):
|
||||
node = xmlNewNode(NULL,XMLSTRING([object name]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
- (void) _addSubNode:(NSXMLNode *)subNode
|
||||
{
|
||||
if (!internal->subNodes)
|
||||
|
@ -93,7 +115,6 @@ GS_PRIVATE_INTERNAL(NSXMLNode)
|
|||
if ([internal->subNodes indexOfObjectIdenticalTo:subNode] == NSNotFound)
|
||||
[internal->subNodes addObject:subNode];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSXMLNode
|
||||
|
@ -107,9 +128,6 @@ GS_PRIVATE_INTERNAL(NSXMLNode)
|
|||
n = [[[self alloc] initWithKind: NSXMLAttributeKind] autorelease];
|
||||
[n setStringValue: stringValue];
|
||||
[n setName: name];
|
||||
node = xmlNewProp(NULL,
|
||||
XMLSTRING(name),
|
||||
XMLSTRING(stringValue));
|
||||
[n _setNode: node];
|
||||
|
||||
return n;
|
||||
|
@ -283,18 +301,18 @@ GS_PRIVATE_INTERNAL(NSXMLNode)
|
|||
|
||||
- (NSUInteger) childCount
|
||||
{
|
||||
NSUInteger childCount = 0;
|
||||
NSUInteger count = 0;
|
||||
xmlNodePtr children = NULL;
|
||||
xmlNodePtr node = (xmlNodePtr)(internal->node);
|
||||
xmlNodePtr node = MY_NODE;
|
||||
if (node->type == XML_DOCUMENT_NODE)
|
||||
node = xmlDocGetRootElement((xmlDocPtr)node);
|
||||
|
||||
for (children = node->children; children; children = children->next)
|
||||
{
|
||||
childCount++;
|
||||
count++;
|
||||
}
|
||||
|
||||
return childCount;
|
||||
return count;
|
||||
}
|
||||
|
||||
- (NSArray*) children
|
||||
|
@ -335,11 +353,8 @@ GS_PRIVATE_INTERNAL(NSXMLNode)
|
|||
if (GS_EXISTS_INTERNAL)
|
||||
{
|
||||
[self detach];
|
||||
[internal->name release];
|
||||
[internal->URI release];
|
||||
[internal->children release];
|
||||
[internal->objectValue release];
|
||||
[internal->stringValue release];
|
||||
[internal->subNodes release];
|
||||
GS_DESTROY_INTERNAL(NSXMLNode);
|
||||
}
|
||||
|
@ -433,7 +448,6 @@ GS_PRIVATE_INTERNAL(NSXMLNode)
|
|||
*/
|
||||
internal->kind = kind;
|
||||
internal->options = theOptions;
|
||||
internal->stringValue = @"";
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -458,7 +472,7 @@ GS_PRIVATE_INTERNAL(NSXMLNode)
|
|||
}
|
||||
|
||||
s = [other name];
|
||||
if (s != internal->name && NO == [s isEqual: internal->name])
|
||||
if (s != [self name] && NO == [s isEqual: [self name]])
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
|
|
@ -81,7 +81,9 @@ StringFromXMLString(const unsigned char *bytes, unsigned length)
|
|||
}
|
||||
|
||||
#define MY_DOC ((xmlDoc *)internal->node)
|
||||
|
||||
#define MY_NODE ((xmlNode *)internal->node)
|
||||
#define MY_ATTR ((xmlAttr *)internal->node)
|
||||
#define MY_ELEM ((xmlElement *)internal->node)
|
||||
|
||||
/* Instance variables for NSXMLNode. This macro needs to be defined before
|
||||
* the NSXMLNode.h header is imported and before GSInternal.h is imported.
|
||||
|
@ -103,11 +105,7 @@ StringFromXMLString(const unsigned char *bytes, unsigned length)
|
|||
NSXMLNode *parent; \
|
||||
NSUInteger index; \
|
||||
id objectValue; \
|
||||
NSString *stringValue; \
|
||||
NSString *name; \
|
||||
NSString *URI; \
|
||||
NSMutableArray *children; \
|
||||
NSUInteger childCount; \
|
||||
NSXMLNode *previousSibling; \
|
||||
NSXMLNode *nextSibling;\
|
||||
NSUInteger options; \
|
||||
|
|
Loading…
Reference in a new issue