2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include <EOControl/EOArrayDataSource.h>
24 #include <EOControl/EOFetchSpecification.h>
25 #include <EOControl/EOSortOrdering.h>
26 #include <EOControl/EOQualifier.h>
29 @interface EODataSource(PostChange)
30 - (void)postDataSourceChangedNotification;
33 @implementation EOArrayDataSource
36 if ((self = [super init])) {
37 self->objects = [[NSMutableArray alloc] init];
42 [self->fetchSpecification release];
43 [self->objects release];
49 - (void)setFetchSpecification:(EOFetchSpecification *)_fspec {
50 if ([self->fetchSpecification isEqual:_fspec])
53 [self->fetchSpecification autorelease];
54 self->fetchSpecification = [_fspec copy];
56 [self postDataSourceChangedNotification];
58 - (EOFetchSpecification *)fetchSpecification {
59 return self->fetchSpecification;
62 - (void)setArray:(NSArray *)_array {
63 [self->objects removeAllObjects];
64 [self->objects addObjectsFromArray:_array];
69 - (NSArray *)fetchObjects {
72 if (self->fetchSpecification == nil) {
73 result = [[self->objects copy] autorelease];
79 q = [self->fetchSpecification qualifier];
80 sort = [self->fetchSpecification sortOrderings];
84 result = [self->objects sortedArrayUsingKeyOrderArray:sort];
86 result = [[self->objects copy] autorelease];
89 result = [self->objects filteredArrayUsingQualifier:q];
90 if (sort) result = [result sortedArrayUsingKeyOrderArray:sort];
98 - (void)deleteObject:(id)_object {
99 [self->objects removeObjectIdenticalTo:_object];
100 [self postDataSourceChangedNotification];
103 - (void)insertObject:(id)_object {
104 [self->objects addObject:_object];
105 [self postDataSourceChangedNotification];
109 return [NSMutableDictionary dictionaryWithCapacity:16];
112 @end /* EOArrayDataSource */