Monotone-Parent: 197b4e59b74c3885e6492eae1e2e5da0feb5fcdd

Monotone-Revision: f74fba51bc9192fdfa33bb77d0e290fd3b30ae08

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2007-11-18T09:43:52
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Wolfgang Sourdeau
2007-11-18 09:43:52 +00:00
parent 3a753c2c96
commit 302e7592e6
5 changed files with 94 additions and 49 deletions

View File

@@ -33,7 +33,7 @@
@class CardGroup;
@interface CardElement : NSObject <NSCopying>
@interface CardElement : NSObject <NSCopying, NSMutableCopying>
{
NSString *tag;
NSMutableArray *values;
@@ -56,7 +56,7 @@
values: (NSArray *) someValues;
- (void) setParent: (CardGroup *) aParent;
- (CardGroup *) parent;
- (id) parent;
- (void) setTag: (NSString *) aTag;

View File

@@ -116,7 +116,7 @@
parent = aParent;
}
- (CardGroup *) parent
- (id) parent
{
return parent;
}
@@ -524,4 +524,19 @@
return new;
}
/* NSMutableCopying */
- (id) mutableCopyWithZone: (NSZone *) aZone
{
CardElement *new;
new = [[self class] new];
[new setTag: [tag mutableCopyWithZone: aZone]];
[new setGroup: [group mutableCopyWithZone: aZone]];
[new setParent: parent];
[new setValuesAsCopy: [values mutableCopyWithZone: aZone]];
[new setAttributesAsCopy: [attributes mutableCopyWithZone: aZone]];
return new;
}
@end

View File

@@ -29,7 +29,7 @@
@class NSMutableArray;
@class NSString;
@interface CardGroup : CardElement <NSCopying>
@interface CardGroup : CardElement <NSCopying, NSMutableCopying>
{
NSMutableArray *children;
}

View File

@@ -159,29 +159,32 @@ static NGCardsSaxHandler *sax = nil;
NSString *childTag;
CardElement *newChild;
childTag = [aChild tag];
newChild = nil;
mappedClass = [self classForTag: [childTag uppercaseString]];
if (mappedClass)
if (aChild)
{
if (![aChild isKindOfClass: mappedClass])
{
NSLog (@"warning: new child to entity '%@': '%@' converted to '%@'",
tag, childTag, NSStringFromClass(mappedClass));
if ([aChild isKindOfClass: [CardGroup class]])
newChild = [(CardGroup *) aChild groupWithClass: mappedClass];
else
newChild = [aChild elementWithClass: mappedClass];
}
}
// else
// NSLog (@"warning: no mapped class for tag '%@'",
// childTag);
childTag = [aChild tag];
newChild = nil;
mappedClass = [self classForTag: [childTag uppercaseString]];
if (mappedClass)
{
if (![aChild isKindOfClass: mappedClass])
{
NSLog (@"warning: new child to entity '%@': '%@' converted to '%@'",
tag, childTag, NSStringFromClass(mappedClass));
if ([aChild isKindOfClass: [CardGroup class]])
newChild = [(CardGroup *) aChild groupWithClass: mappedClass];
else
newChild = [aChild elementWithClass: mappedClass];
}
}
// else
// NSLog (@"warning: no mapped class for tag '%@'",
// childTag);
if (!newChild)
newChild = aChild;
[children addObject: newChild];
[newChild setParent: self];
if (!newChild)
newChild = aChild;
[children addObject: newChild];
[newChild setParent: self];
}
}
- (CardElement *) uniqueChildWithTag: (NSString *) aTag
@@ -214,17 +217,20 @@ static NGCardsSaxHandler *sax = nil;
NSString *childTag;
NSEnumerator *existing;
childTag = [aChild tag];
existing = [[self childrenWithTag: childTag] objectEnumerator];
currentChild = [existing nextObject];
while (currentChild)
if (aChild)
{
[children removeObject: currentChild];
currentChild = [existing nextObject];
}
childTag = [aChild tag];
existing = [[self childrenWithTag: childTag] objectEnumerator];
[self addChild: aChild];
currentChild = [existing nextObject];
while (currentChild)
{
[children removeObject: currentChild];
currentChild = [existing nextObject];
}
[self addChild: aChild];
}
}
- (CardElement *) firstChildWithTag: (NSString *) aTag;
@@ -260,12 +266,8 @@ static NGCardsSaxHandler *sax = nil;
NSEnumerator *newChildren;
newChildren = [someChildren objectEnumerator];
currentChild = [newChildren nextObject];
while (currentChild)
{
[self addChild: currentChild];
currentChild = [newChildren nextObject];
}
while ((currentChild = [newChildren nextObject]))
[self addChild: currentChild];
}
- (NSArray *) children
@@ -343,9 +345,14 @@ static NGCardsSaxHandler *sax = nil;
- (void) setChildrenAsCopy: (NSMutableArray *) someChildren
{
[children release];
children = someChildren;
[children retain];
NSEnumerator *list;
CardElement *currentChild;
ASSIGN (children, someChildren);
list = [children objectEnumerator];
while ((currentChild = [list nextObject]))
[currentChild setParent: self];
}
- (void) addChildWithTag: (NSString *) aTag
@@ -358,12 +365,8 @@ static NGCardsSaxHandler *sax = nil;
newChild = [CardElement simpleElementWithTag: aTag value: aValue];
types = [someTypes objectEnumerator];
type = [types nextObject];
while (type)
{
[newChild addType: type];
type = [types nextObject];
}
while ((type = [types nextObject]))
[newChild addType: type];
[self addChild: newChild];
}
@@ -400,6 +403,8 @@ static NGCardsSaxHandler *sax = nil;
[children replaceObjectAtIndex: index withObject: newElement];
}
/* NSCopying */
- (id) copyWithZone: (NSZone *) aZone
{
CardGroup *new;
@@ -410,4 +415,16 @@ static NGCardsSaxHandler *sax = nil;
return new;
}
/* NSMutableCopying */
- (id) mutableCopyWithZone: (NSZone *) aZone
{
CardGroup *new;
new = [super mutableCopyWithZone: aZone];
[new setChildrenAsCopy: [children mutableCopyWithZone: aZone]];
return new;
}
@end

View File

@@ -1,3 +1,16 @@
2007-11-18 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* CardGroup.m ([CardGroup -addChild:aChild]): don't process nil
values for aChild.
([CardGroup -setUniqueChild:aChild]): same as above.
([CardGroup -setChildrenAsCopy:someChildren]): reparent the copied
children.
([CardGroup -mutableCopyWithZone:aZone]): implemented
NSMutableCopying protocol.
* CardElement.m ([CardElement -mutableCopyWithZone:aZone]):
implemented NSMutableCopying protocol.
2007-11-12 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* iCalTimeZonePeriod.m ([iCalTimeZonePeriod