]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/c++/OSCollection.h
7145889704182b88ab392eca9efbdb033e49357c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 /* IOCollection.h created by gvdl on Thu 1998-10-22 */
25 #ifndef _OS_OSCOLLECTION_H
26 #define _OS_OSCOLLECTION_H
28 #include <libkern/c++/OSObject.h>
34 @abstract Abstract super class for all collections.
36 OSCollection is the abstract super class for all OSObject derived collections and provides the necessary interfaces for managing storage space and iteration through a collection.
38 class OSCollection
: public OSObject
40 friend class OSCollectionIterator
;
42 OSDeclareAbstractStructors ( OSCollection
);
44 struct ExpansionData
{ };
47 unsigned int updateStamp
;
50 /* Reserved for future use. (Internal use only) */
51 // ExpansionData *reserved;
52 unsigned int fOptions
;
55 // Member functions used by the OSCollectionIterator class.
57 @function iteratorSize
58 @abstract A pure virtual member function to return the size of the iterator context.
59 @result Returns an integer size for the storage space required to contain context necessary for iterating through a collection.
61 This member function is called by an OSCollectionIterator object to allow it to allocate enough storage space for the iterator context. This context contains the data necessary to iterate through the collection when getNextObjectForIterator() is called.
63 virtual unsigned int iteratorSize () const = 0 ;
65 @function initIterator
66 @abstract Pure virtual member function to allocate and initialize the iterator context data.
67 @param iterator The iterator context.
68 @result Returns true if initialization was successful, false otherwise.
70 virtual bool initIterator ( void * iterator
) const = 0 ;
72 @function getNextObjectForIterator
73 @abstract A pure virtual member function which returns the next member of a collection.
74 @param iterator The iterator context.
75 @param ret The object returned to the caller.
76 @result Returns true if an object was found, false otherwise.
78 This is the entry point used by an OSCollectionIterator object to advance to next object in the collection. The iterator context is passed to the receiver to allow it to find the location of the current object and then advance the iterator context to the next object.
80 virtual bool getNextObjectForIterator ( void * iterator
, OSObject
** ret
) const = 0 ;
84 @abstract A member function to initialize the OSCollection object.
85 @result Returns true if an object was initialized successfully, false otherwise.
87 This function is used to initialize state within a newly created OSCollection object.
93 kImmutable
= 0x00000001 ,
99 @abstract A member function to track of all updates to the collection.
105 @abstract A pure virtual member function which returns the number of objects in the collection subclass.
106 @results Returns the number objects in a collection.
108 virtual unsigned int getCount () const = 0 ;
110 @function getCapacity
111 @abstract A pure virtual member function which returns the storage space in the collection subclass.
112 @results Returns the number objects in a collection.
114 virtual unsigned int getCapacity () const = 0 ;
116 @function getCapacityIncrement
117 @abstract A pure virtual member function which returns the growth factor of the collection subclass.
118 @results Returns the size by which the collection subclass should grow.
120 virtual unsigned int getCapacityIncrement () const = 0 ;
122 @function setCapacityIncrement
123 @abstract A pure virtual member function which sets the growth factor of the collection subclass.
124 @param increment The new size by which the capacity of the collection should grow.
125 @results Returns the new capacity increment.
127 virtual unsigned int setCapacityIncrement ( unsigned increment
) = 0 ;
130 @function ensureCapacity
131 @abstract A pure virtual member function which
135 virtual unsigned int ensureCapacity ( unsigned int newCapacity
) = 0 ;
138 @function flushCollection
139 @abstract A pure virtual member function which
141 virtual void flushCollection () = 0 ;
145 @abstract This function is used to recursively set option bits in this collection and all child collections.
146 @discussion setOptions is a recursive function but the OSCollection class itself does not know the structure of the particular collection. This means that all derived classes are expected to override this method and recurse if the old value of the option was NOT set, which is why the old value is returned. As this function is a reserved function override it is very multi purpose. It can be used to get & set the options,
147 @param options Set the (options & mask) bits.
148 @param mask The mask of bits which need to be set, 0 to get the current value.
149 @result The options before the set operation, NB setOptions(?,0) returns the current value of this collection.
151 OSMetaClassDeclareReservedUsed ( OSCollection
, 0 );
152 virtual unsigned setOptions ( unsigned options
, unsigned mask
, void * = 0 );
155 @function copyCollection
156 @abstract Do a deep copy of a collection tree.
157 @discussion This function copies this collection and all of the contained collections recursively. Objects that don't derive from OSContainter are NOT copied, that is objects like OSString and OSData. To a derive from OSConnection::copyCollection some code is required to be implemented in the derived class, below is the skeleton pseudo code to copy a collection.
159 OSCollection * <MyCollection>::copyCollection(OSDictionary *inCycleDict)
161 bool allocDict = !cycleDict;
162 OSCollection *ret = 0;
163 <MyCollection> *newMyColl = 0;
166 cycleDict = OSDictionary::withCapacity(16);
171 // Check to see if we already have a copy of the new dictionary
172 ret = super::copyCollection(cycleDict);
176 // Your code goes here to copy your collection,
177 // see OSArray & OSDictionary for examples.
178 newMyColl = <MyCollection>::with<MyCollection>(this);
182 // Insert object into cycle Dictionary
183 cycleDict->setObject((const OSSymbol *) this, newMyColl);
185 // Duplicate any collections in us
186 for (unsigned int i = 0; i < count; i++) {
187 OSObject *obj = getObject(i);
188 OSCollection *coll = OSDynamicCast(OSCollection, obj);
191 OSCollection *newColl = coll->copyCollection(cycleDict);
195 newMyColl->replaceObject(i, newColl);
207 newMyColl->release();
210 cycleDict->release();
215 @param cycleDict Is a dictionary of all of the collections that have been, to start the copy at the top level just leave this field 0.
216 @result The newly copied collecton or 0 if insufficient memory
218 virtual OSCollection
* copyCollection ( OSDictionary
* cycleDict
= 0 );
219 OSMetaClassDeclareReservedUsed ( OSCollection
, 1 );
221 OSMetaClassDeclareReservedUnused ( OSCollection
, 2 );
222 OSMetaClassDeclareReservedUnused ( OSCollection
, 3 );
223 OSMetaClassDeclareReservedUnused ( OSCollection
, 4 );
224 OSMetaClassDeclareReservedUnused ( OSCollection
, 5 );
225 OSMetaClassDeclareReservedUnused ( OSCollection
, 6 );
226 OSMetaClassDeclareReservedUnused ( OSCollection
, 7 );
229 #endif /* !_OS_OSCOLLECTION_H */