1 /** Interface for NSOrderedSet, NSMutableOrderedSet for GNUStep 2 Copyright (C) 2019 Free Software Foundation, Inc. 3 4 Written by: Gregory John Casamento <greg.casamento@gmail.com> 5 Created: May 17 2019 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 Lesser 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 Lesser General Public License for more details. 18 19 You should have received a copy of the GNU Lesser General Public 20 License along with this library; if not, write to the Free 21 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 Boston, MA 02110 USA. 23 24 */ 25 26 #ifndef _NSOrderedSet_h_GNUSTEP_BASE_INCLUDE 27 #define _NSOrderedSet_h_GNUSTEP_BASE_INCLUDE 28 29 #if OS_API_VERSION(MAC_OS_X_VERSION_10_7,GS_API_LATEST) 30 31 #import <GNUstepBase/GSVersionMacros.h> 32 #import <GNUstepBase/GSBlocks.h> 33 34 #import <Foundation/NSObject.h> 35 #import <Foundation/NSEnumerator.h> 36 #import <Foundation/NSIndexSet.h> 37 #import <Foundation/NSKeyedArchiver.h> 38 39 #if defined(__cplusplus) 40 extern "C" { 41 #endif 42 43 @class GS_GENERIC_CLASS(NSArray, ElementT); 44 @class GS_GENERIC_CLASS(NSEnumerator, ElementT); 45 @class GS_GENERIC_CLASS(NSSet, ElementT); 46 @class GS_GENERIC_CLASS(NSDictionary, KeyT:id<NSCopying>, ValT); 47 @class NSString; 48 @class NSPredicate; 49 50 @interface GS_GENERIC_CLASS(NSOrderedSet, __covariant ElementT) : NSObject <NSCoding, 51 NSCopying, 52 NSMutableCopying, 53 NSFastEnumeration> 54 55 // class methods 56 + (instancetype) orderedSet; 57 + (instancetype) orderedSetWithArray:(GS_GENERIC_CLASS(NSArray, ElementT)*)objects; 58 + (instancetype) orderedSetWithArray:(GS_GENERIC_CLASS(NSArray, ElementT)*)objects 59 range: (NSRange)range 60 copyItems:(BOOL)flag; 61 + (instancetype) orderedSetWithObject:(GS_GENERIC_TYPE(ElementT))anObject; 62 + (instancetype) orderedSetWithObjects:(GS_GENERIC_TYPE(ElementT))firstObject, ...; 63 + (instancetype) orderedSetWithObjects:(const GS_GENERIC_TYPE(ElementT)[])objects 64 count:(NSUInteger) count; 65 + (instancetype) orderedSetWithOrderedSet:(GS_GENERIC_CLASS(NSOrderedSet, ElementT)*)aSet; 66 + (instancetype) orderedSetWithSet:(GS_GENERIC_CLASS(NSSet, ElementT)*)aSet; 67 + (instancetype) orderedSetWithSet:(GS_GENERIC_CLASS(NSSet, ElementT)*)aSet 68 copyItems:(BOOL)flag; 69 70 // instance methods 71 - (instancetype) initWithArray:(GS_GENERIC_CLASS(NSArray, ElementT)*)array; 72 - (instancetype) initWithArray:(GS_GENERIC_CLASS(NSArray, ElementT)*)array copyItems:(BOOL)flag; 73 - (instancetype) initWithArray:(GS_GENERIC_CLASS(NSArray, ElementT)*)array 74 range:(NSRange)range 75 copyItems:(BOOL)flag; 76 - (instancetype) initWithObject:(id)object; 77 - (instancetype) initWithObjects:(GS_GENERIC_TYPE(ElementT))firstObject, ...; 78 - (instancetype) initWithObjects:(const GS_GENERIC_TYPE(ElementT)[])objects 79 count:(NSUInteger)count; 80 - (instancetype) initWithOrderedSet:(GS_GENERIC_CLASS(NSOrderedSet, ElementT)*)aSet; 81 - (instancetype) initWithOrderedSet:(GS_GENERIC_CLASS(NSOrderedSet, ElementT)*)aSet 82 copyItems:(BOOL)flag; 83 - (instancetype) initWithOrderedSet:(GS_GENERIC_CLASS(NSOrderedSet, ElementT)*)aSet 84 range: (NSRange)range 85 copyItems:(BOOL)flag; 86 - (instancetype) initWithSet:(GS_GENERIC_CLASS(NSSet, ElementT)*)aSet; 87 - (instancetype) initWithSet:(GS_GENERIC_CLASS(NSSet, ElementT)*)aSet copyItems:(BOOL)flag; 88 - (instancetype) init; 89 - (NSUInteger) count; 90 - (BOOL)containsObject:(GS_GENERIC_TYPE(ElementT))anObject; 91 - (void) enumerateObjectsAtIndexes:(NSIndexSet *)indexSet 92 options:(NSEnumerationOptions)opts 93 usingBlock:(GSEnumeratorBlock)aBlock; 94 - (void) enumerateObjectsUsingBlock: (GSEnumeratorBlock)aBlock; 95 - (void) enumerateObjectsWithOptions:(NSEnumerationOptions)opts 96 usingBlock:(GSEnumeratorBlock)aBlock; 97 - (GS_GENERIC_TYPE(ElementT)) firstObject; 98 - (GS_GENERIC_TYPE(ElementT)) lastObject; 99 - (GS_GENERIC_TYPE(ElementT)) objectAtIndex: (NSUInteger)index; 100 - (GS_GENERIC_TYPE(ElementT)) objectAtIndexedSubscript:(NSUInteger)index; 101 - (GS_GENERIC_CLASS(NSArray, ElementT)*) objectsAtIndexes:(NSIndexSet *)indexes; 102 - (NSUInteger) indexOfObject:(GS_GENERIC_TYPE(ElementT))objects; 103 - (NSUInteger) indexOfObject: (id)key 104 inSortedRange: (NSRange)range 105 options: (NSBinarySearchingOptions)options 106 usingComparator: (NSComparator)comparator; 107 108 - (NSUInteger) indexOfObjectAtIndexes:(NSIndexSet *)indexSet 109 options:(NSEnumerationOptions)opts 110 passingTest:(GSPredicateBlock)predicate; 111 - (NSUInteger) indexOfObjectPassingTest:(GSPredicateBlock)predicate; 112 - (NSUInteger) indexOfObjectWithOptions:(NSEnumerationOptions)opts 113 passingTest:(GSPredicateBlock)predicate; 114 - (NSIndexSet *) indexesOfObjectsAtIndexes:(NSIndexSet *)indexSet 115 options:(NSEnumerationOptions)opts 116 passingTest:(GSPredicateBlock)predicate; 117 118 - (NSIndexSet *)indexesOfObjectsPassingTest:(GSPredicateBlock)predicate; 119 - (NSIndexSet *) indexesOfObjectsWithOptions:(NSEnumerationOptions)opts 120 passingTest:(GSPredicateBlock)predicate; 121 - (GS_GENERIC_CLASS(NSEnumerator, ElementT)*) objectEnumerator; 122 - (GS_GENERIC_CLASS(NSEnumerator, ElementT)*) reverseObjectEnumerator; 123 - (NSOrderedSet *)reversedOrderedSet; 124 - (void) getObjects: (__unsafe_unretained GS_GENERIC_TYPE(ElementT)[])aBuffer 125 range: (NSRange)aRange; 126 127 // Key value coding support 128 - (void) setValue: (id)value forKey: (NSString*)key; 129 - (id) valueForKey: (NSString*)key; 130 131 // Comparing Sets 132 - (BOOL) isEqualToOrderedSet: (NSOrderedSet *)aSet; 133 134 // Set operations 135 - (BOOL) intersectsOrderedSet: (NSOrderedSet *)aSet; 136 - (BOOL) intersectsSet: (NSSet *)aSet; 137 - (BOOL) isSubsetOfOrderedSet: (NSOrderedSet *)aSet; 138 - (BOOL) isSubsetOfSet:(NSSet *)aSet; 139 140 // Creating a Sorted Array 141 - (GS_GENERIC_CLASS(NSArray, ElementT) *) sortedArrayUsingDescriptors:(NSArray *)sortDescriptors; 142 - (GS_GENERIC_CLASS(NSArray, ElementT) *) sortedArrayUsingComparator: 143 (NSComparator)comparator; 144 - (GS_GENERIC_CLASS(NSArray, ElementT) *) 145 sortedArrayWithOptions: (NSSortOptions)options 146 usingComparator: (NSComparator)comparator; 147 148 // Filtering Ordered Sets 149 - (NSOrderedSet *)filteredOrderedSetUsingPredicate: (NSPredicate *)predicate; 150 151 // Describing a set 152 - (NSString *) description; 153 - (NSString *) descriptionWithLocale: (NSLocale *)locale; 154 - (NSString *) descriptionWithLocale: (NSLocale *)locale indent: (BOOL)flag; 155 156 // Convert to other types 157 - (NSArray *) array; 158 - (NSSet *) set; 159 @end 160 161 // Mutable Ordered Set 162 @interface GS_GENERIC_CLASS(NSMutableOrderedSet, ElementT) : GS_GENERIC_CLASS(NSOrderedSet, ElementT) 163 // Creating a Mutable Ordered Set 164 + (instancetype)orderedSetWithCapacity: (NSUInteger)capacity; 165 - (instancetype)initWithCapacity: (NSUInteger)capacity; 166 - (instancetype) init; 167 - (void)addObject:(GS_GENERIC_TYPE(ElementT))anObject; 168 - (void)addObjects:(const GS_GENERIC_TYPE(ElementT)[])objects count:(NSUInteger)count; 169 - (void)addObjectsFromArray:(GS_GENERIC_CLASS(NSArray, ElementT)*)otherArray; 170 - (void)insertObject:(GS_GENERIC_TYPE(ElementT))object atIndex:(NSUInteger)index; 171 - (void)setObject:(GS_GENERIC_TYPE(ElementT))object atIndexedSubscript:(NSUInteger)index; 172 - (void)insertObjects:(GS_GENERIC_CLASS(NSArray, ElementT)*)array atIndexes:(NSIndexSet *)indexes; 173 - (void)removeObject:(GS_GENERIC_TYPE(ElementT))object; 174 - (void)removeObjectAtIndex:(NSUInteger)index; 175 - (void)removeObjectsAtIndexes:(NSIndexSet *)indexes; 176 - (void)removeObjectsInArray:(GS_GENERIC_CLASS(NSArray, ElementT)*)otherArray; 177 - (void)removeObjectsInRange:(NSRange)range; 178 - (void)removeAllObjects; 179 - (void)replaceObjectAtIndex:(NSUInteger)index 180 withObject:(GS_GENERIC_TYPE(ElementT))object; 181 - (void) replaceObjectsAtIndexes: (NSIndexSet *)indexes 182 withObjects: (GS_GENERIC_CLASS(NSArray, ElementT)*)objects; 183 - (void) replaceObjectsInRange:(NSRange)range 184 withObjects:(const GS_GENERIC_TYPE(ElementT)[])objects 185 count: (NSUInteger)count; 186 - (void)setObject:(GS_GENERIC_TYPE(ElementT))object atIndex:(NSUInteger)index; 187 - (void)moveObjectsAtIndexes:(NSIndexSet *)indexes toIndex:(NSUInteger)index; 188 - (void) exchangeObjectAtIndex:(NSUInteger)index withObjectAtIndex:(NSUInteger)otherIndex; 189 - (void)filterUsingPredicate:(NSPredicate *)predicate; 190 - (void) sortUsingDescriptors:(NSArray *)descriptors; 191 - (void) sortUsingComparator: (NSComparator)comparator; 192 - (void) sortWithOptions: (NSSortOptions)options 193 usingComparator: (NSComparator)comparator; 194 - (void) sortRange: (NSRange)range 195 options:(NSSortOptions)options 196 usingComparator: (NSComparator)comparator; 197 - (void) intersectOrderedSet:(GS_GENERIC_CLASS(NSOrderedSet, ElementT)*)aSet; 198 - (void) intersectSet:(GS_GENERIC_CLASS(NSSet, ElementT)*)aSet; 199 - (void) minusOrderedSet:(GS_GENERIC_CLASS(NSOrderedSet, ElementT)*)aSet; 200 - (void) minusSet:(GS_GENERIC_CLASS(NSSet, ElementT)*)aSet; 201 - (void) unionOrderedSet:(GS_GENERIC_CLASS(NSOrderedSet, ElementT)*)aSet; 202 - (void) unionSet:(GS_GENERIC_CLASS(NSSet, ElementT)*)aSet; 203 - (instancetype) initWithCoder: (NSCoder *)coder; 204 @end 205 206 #if defined(__cplusplus) 207 } 208 #endif 209 210 #endif /* OS_API_VERSION check */ 211 212 #endif /* _NSOrderedSet_h_GNUSTEP_BASE_INCLUDE */ 213