~ubuntu-branches/ubuntu/breezy/gnustep-base/breezy

« back to all changes in this revision

Viewing changes to Headers/Foundation/NSSet.h

  • Committer: Bazaar Package Importer
  • Author(s): Eric Heintzmann
  • Date: 2005-04-17 00:14:38 UTC
  • mfrom: (1.2.1 upstream) (4 hoary)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20050417001438-enf0y07c9tku85z1
Tags: 1.10.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** Interface for NSSet, NSMutableSet, NSCountedSet for GNUStep
 
2
   Copyright (C) 1995, 1996, 1998 Free Software Foundation, Inc.
 
3
 
 
4
   Written by:  Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
 
5
   Created: Sep 1995
 
6
   
 
7
   This file is part of the GNUstep Base Library.
 
8
 
 
9
   This library is free software; you can redistribute it and/or
 
10
   modify it under the terms of the GNU Library General Public
 
11
   License as published by the Free Software Foundation; either
 
12
   version 2 of the License, or (at your option) any later version.
 
13
   
 
14
   This library is distributed in the hope that it will be useful,
 
15
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
   Library General Public License for more details.
 
18
   
 
19
   You should have received a copy of the GNU Library General Public
 
20
   License along with this library; if not, write to the Free
 
21
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
 
22
 
 
23
   AutogsdocSource: NSSet.m
 
24
   AutogsdocSource: NSCountedSet.m
 
25
 
 
26
   */ 
 
27
 
 
28
#ifndef _NSSet_h_GNUSTEP_BASE_INCLUDE
 
29
#define _NSSet_h_GNUSTEP_BASE_INCLUDE
 
30
 
 
31
#include <Foundation/NSObject.h>
 
32
 
 
33
@class NSArray, NSString, NSEnumerator, NSDictionary;
 
34
 
 
35
@interface NSSet : NSObject <NSCoding, NSCopying, NSMutableCopying>
 
36
 
 
37
+ (id) set;
 
38
+ (id) setWithArray: (NSArray*)objects;
 
39
+ (id) setWithObject: (id)anObject;
 
40
+ (id) setWithObjects: (id)firstObject, ...;
 
41
#ifndef STRICT_OPENSTEP
 
42
+ (id) setWithObjects: (id*)objects
 
43
                count: (unsigned)count;
 
44
#endif
 
45
+ (id) setWithSet: (NSSet*)aSet;
 
46
 
 
47
- (NSArray*) allObjects;
 
48
- (id) anyObject;
 
49
- (BOOL) containsObject: (id)anObject;
 
50
- (unsigned) count;
 
51
- (NSString*) description;
 
52
- (NSString*) descriptionWithLocale: (NSDictionary*)locale;
 
53
 
 
54
- (id) init;
 
55
- (id) initWithArray: (NSArray*)other;
 
56
- (id) initWithObjects: (id)firstObject, ...;
 
57
- (id) initWithObjects: (id*)objects
 
58
                 count: (unsigned)count;
 
59
- (id) initWithSet: (NSSet*)other;
 
60
- (id) initWithSet: (NSSet*)other copyItems: (BOOL)flag;
 
61
 
 
62
- (BOOL) intersectsSet: (NSSet*)otherSet;
 
63
- (BOOL) isEqualToSet: (NSSet*)other;
 
64
- (BOOL) isSubsetOfSet: (NSSet*)otherSet;
 
65
 
 
66
- (void) makeObjectsPerform: (SEL)aSelector;
 
67
- (void) makeObjectsPerform: (SEL)aSelector withObject: (id)argument;
 
68
#ifndef STRICT_OPENSTEP
 
69
- (void) makeObjectsPerformSelector: (SEL)aSelector;
 
70
- (void) makeObjectsPerformSelector: (SEL)aSelector withObject: (id)argument;
 
71
#endif
 
72
- (id) member: (id)anObject;
 
73
- (NSEnumerator*) objectEnumerator;
 
74
 
 
75
@end
 
76
 
 
77
@interface NSMutableSet: NSSet
 
78
 
 
79
+ (id) setWithCapacity: (unsigned)numItems;
 
80
 
 
81
- (void) addObject: (id)anObject;
 
82
- (void) addObjectsFromArray: (NSArray*)array;
 
83
- (id) initWithCapacity: (unsigned)numItems;
 
84
- (void) intersectSet: (NSSet*)other;
 
85
- (void) minusSet: (NSSet*)other;
 
86
- (void) removeAllObjects;
 
87
- (void) removeObject: (id)anObject;
 
88
#ifndef STRICT_OPENSTEP
 
89
- (void) setSet: (NSSet*)other;
 
90
#endif
 
91
- (void) unionSet: (NSSet*)other;
 
92
@end
 
93
 
 
94
@interface NSCountedSet : NSMutableSet
 
95
 
 
96
- (unsigned int) countForObject: (id)anObject;
 
97
 
 
98
@end
 
99
 
 
100
#ifndef NO_GNUSTEP
 
101
 
 
102
/**
 
103
 * Utility methods for using a counted set to handle uniquing of objects.
 
104
 */
 
105
@interface NSCountedSet (GNU_Uniquing)
 
106
/**
 
107
 * <p>
 
108
 *   This method removes from the set all objects whose count is
 
109
 *   less than or equal to the specified value.
 
110
 * </p>
 
111
 * <p>
 
112
 *   This is useful where a counted set is used for uniquing objects.
 
113
 *   The set can be periodically purged of objects that have only
 
114
 *   been added once - and are therefore simply wasting space.
 
115
 * </p>
 
116
 */
 
117
- (void) purge: (int)level;
 
118
 
 
119
/**
 
120
 * <p>
 
121
 *   If the supplied object (or one equal to it as determined by
 
122
 *   the [NSObject-isEqual:] method) is already present in the set, the
 
123
 *   count for that object is incremented, the supplied object
 
124
 *   is released, and the object in the set is retained and returned.
 
125
 *   Otherwise, the supplied object is added to the set and returned.
 
126
 * </p>
 
127
 * <p> 
 
128
 *   This method is useful for uniquing objects - the init method of
 
129
 *   a class need simply end with -
 
130
 *   <code>
 
131
 *     return [myUniquingSet unique: self];
 
132
 *   </code>
 
133
 * </p>
 
134
 */
 
135
- (id) unique: (id)anObject;
 
136
@end
 
137
 
 
138
/*
 
139
 * Functions for managing a global uniquing set.
 
140
 */
 
141
 
 
142
/*
 
143
 * GSUniquing() turns on/off the action of the GSUnique() function.
 
144
 * if uniquing is turned off, GSUnique() simply returns its argument.
 
145
 *
 
146
 */
 
147
void    GSUniquing(BOOL flag);  
 
148
 
 
149
/*
 
150
 * GSUnique() returns an object that is equal to the one passed to it.
 
151
 * If the returned object is not the same object as the object passed in,
 
152
 * the original object is released and the returned object is retained.
 
153
 * Thus, an -init method that wants to implement uniquing simply needs
 
154
 * to end with 'return GSUnique(self);'
 
155
 */
 
156
id      GSUnique(id anObject);
 
157
 
 
158
/*
 
159
 * Management functions -
 
160
 */
 
161
 
 
162
/*
 
163
 * GSUPurge() can be used to purge infrequently referenced objects from the
 
164
 * set by removing any objec whose count is less than or equal to that given.
 
165
 *
 
166
 */
 
167
void    GSUPurge(unsigned count);
 
168
 
 
169
/*
 
170
 * GSUSet() can be used to artificially set the count for a particular object
 
171
 * Setting the count to zero will remove the object from the global set.
 
172
 */
 
173
id      GSUSet(id anObject, unsigned count);
 
174
 
 
175
#endif /* NO_GNUSTEP */
 
176
 
 
177
#endif