// Managed Object Accesors #define MO_GETTER(type, attr, capattr) \ - (type)attr { \ type tmpValue; \ [self willAccessValueForKey:@#attr]; \ tmpValue = [self primitiveValueForKey:@#attr]; \ [self didAccessValueForKey:@#attr]; \ return tmpValue; } #define MO_SETTER(type, attr, capattr) \ - (void)set##capattr:(type)value { \ [self willChangeValueForKey:@#attr]; \ [self setPrimitiveValue:value forKey:@#attr]; \ [self didChangeValueForKey:@#attr]; } #define MO_ACCESSORS(type, attr, capattr) \ MO_GETTER(type, attr, capattr) \ MO_SETTER(type, attr, capattr) // Managed Object Relationship Accessors #define MO_REL_GETTER(attr) \ - (NSMutableSet*)attr { \ NSMutableSet *tmpValue; \ [self willAccessValueForKey:@#attr]; \ tmpValue = [self mutableSetValueForKey:@#attr]; \ [self didAccessValueForKey:@#attr]; \ return tmpValue; } #define MO_REL_ADD(type, attr, capattr) \ - (void)add##capattr##Object:(type)anObject { \ NSSet *changedObjects = [[NSSet alloc] initWithObjects:&anObject count:1]; \ [self willChangeValueForKey:@#attr withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects]; \ [[self primitiveValueForKey:@#attr] addObject:anObject]; \ [self didChangeValueForKey:@#attr withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects]; \ [changedObjects release]; } \ - (void)add##capattr:(NSSet *)aSet { \ [self willChangeValueForKey:@#attr withSetMutation:NSKeyValueUnionSetMutation usingObjects:aSet]; \ [[self primitiveValueForKey:@#attr] unionSet:aSet]; \ [self didChangeValueForKey:@#attr withSetMutation:NSKeyValueUnionSetMutation usingObjects:aSet]; } #define MO_REL_DEL(type, attr, capattr) \ - (void)remove##capattr##Object:(type)anObject { \ NSSet *changedObjects = [[NSSet alloc] initWithObjects:&anObject count:1]; \ [self willChangeValueForKey:@#attr withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects]; \ [[self primitiveValueForKey:@#attr] removeObject: anObject]; \ [self didChangeValueForKey:@#attr withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects]; \ [changedObjects release]; } \ - (void)remove##capattr:(NSSet *)aSet { \ [self willChangeValueForKey:@#attr withSetMutation:NSKeyValueMinusSetMutation usingObjects:aSet]; \ [[self primitiveValueForKey:@#attr] minusSet:aSet]; \ [self didChangeValueForKey:@#attr withSetMutation:NSKeyValueMinusSetMutation usingObjects:aSet]; } #define MO_REL_INT(type, attr, capattr) \ - (void)intersect##capattr:(NSSet *)aSet { \ [self willChangeValueForKey:@#attr withSetMutation:NSKeyValueIntersectSetMutation usingObjects:aSet]; \ [[self primitiveValueForKey:@#attr] intersectSet:aSet]; \ [self didChangeValueForKey:@#attr withSetMutation:NSKeyValueIntersectSetMutation usingObjects:aSet]; } #define MO_REL_ACCESSORS_H(type, attr, capattr) \ - (NSMutableSet*)attr; \ - (void)add##capattr##Object:(type)anObject; \ - (void)add##capattr:(NSSet *)aSet; \ - (void)remove##capattr##Object:(type)anObject; \ - (void)remove##capattr:(NSSet *)aSet; \ - (void)intersect##capattr:(NSSet *)aSet; #define MO_REL_ACCESSORS(type, attr, capattr) \ MO_REL_GETTER(attr) \ MO_REL_ADD(type, attr, capattr) \ MO_REL_DEL(type, attr, capattr) \ MO_REL_INT(type, attr, capattr)