]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/c++/OSCollection.h
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* IOCollection.h created by gvdl on Thu 1998-10-22 */
24 #ifndef _OS_OSCOLLECTION_H
25 #define _OS_OSCOLLECTION_H
27 #include <libkern/c++/OSObject.h>
33 @abstract Abstract super class for all collections.
35 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.
37 class OSCollection
: public OSObject
39 friend class OSCollectionIterator
;
41 OSDeclareAbstractStructors ( OSCollection
);
43 struct ExpansionData
{ };
46 unsigned int updateStamp
;
49 /* Reserved for future use. (Internal use only) */
50 // ExpansionData *reserved;
51 unsigned int fOptions
;
54 // Member functions used by the OSCollectionIterator class.
56 @function iteratorSize
57 @abstract A pure virtual member function to return the size of the iterator context.
58 @result Returns an integer size for the storage space required to contain context necessary for iterating through a collection.
60 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.
62 virtual unsigned int iteratorSize () const = 0 ;
64 @function initIterator
65 @abstract Pure virtual member function to allocate and initialize the iterator context data.
66 @param iterator The iterator context.
67 @result Returns true if initialization was successful, false otherwise.
69 virtual bool initIterator ( void * iterator
) const = 0 ;
71 @function getNextObjectForIterator
72 @abstract A pure virtual member function which returns the next member of a collection.
73 @param iterator The iterator context.
74 @param ret The object returned to the caller.
75 @result Returns true if an object was found, false otherwise.
77 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.
79 virtual bool getNextObjectForIterator ( void * iterator
, OSObject
** ret
) const = 0 ;
83 @abstract A member function to initialize the OSCollection object.
84 @result Returns true if an object was initialized successfully, false otherwise.
86 This function is used to initialize state within a newly created OSCollection object.
92 kImmutable
= 0x00000001 ,
98 @abstract A member function to track of all updates to the collection.
104 @abstract A pure virtual member function which returns the number of objects in the collection subclass.
105 @results Returns the number objects in a collection.
107 virtual unsigned int getCount () const = 0 ;
109 @function getCapacity
110 @abstract A pure virtual member function which returns the storage space in the collection subclass.
111 @results Returns the number objects in a collection.
113 virtual unsigned int getCapacity () const = 0 ;
115 @function getCapacityIncrement
116 @abstract A pure virtual member function which returns the growth factor of the collection subclass.
117 @results Returns the size by which the collection subclass should grow.
119 virtual unsigned int getCapacityIncrement () const = 0 ;
121 @function setCapacityIncrement
122 @abstract A pure virtual member function which sets the growth factor of the collection subclass.
123 @param increment The new size by which the capacity of the collection should grow.
124 @results Returns the new capacity increment.
126 virtual unsigned int setCapacityIncrement ( unsigned increment
) = 0 ;
129 @function ensureCapacity
130 @abstract A pure virtual member function which
134 virtual unsigned int ensureCapacity ( unsigned int newCapacity
) = 0 ;
137 @function flushCollection
138 @abstract A pure virtual member function which
140 virtual void flushCollection () = 0 ;
144 @abstract This function is used to recursively set option bits in this collection and all child collections.
145 @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,
146 @param options Set the (options & mask) bits.
147 @param mask The mask of bits which need to be set, 0 to get the current value.
148 @result The options before the set operation, NB setOptions(?,0) returns the current value of this collection.
150 OSMetaClassDeclareReservedUsed ( OSCollection
, 0 );
151 virtual unsigned setOptions ( unsigned options
, unsigned mask
, void * = 0 );
154 @function copyCollection
155 @abstract Do a deep copy of a collection tree.
156 @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.
158 OSCollection * <MyCollection>::copyCollection(OSDictionary *inCycleDict)
160 bool allocDict = !cycleDict;
161 OSCollection *ret = 0;
162 <MyCollection> *newMyColl = 0;
165 cycleDict = OSDictionary::withCapacity(16);
170 // Check to see if we already have a copy of the new dictionary
171 ret = super::copyCollection(cycleDict);
175 // Your code goes here to copy your collection,
176 // see OSArray & OSDictionary for examples.
177 newMyColl = <MyCollection>::with<MyCollection>(this);
181 // Insert object into cycle Dictionary
182 cycleDict->setObject((const OSSymbol *) this, newMyColl);
184 // Duplicate any collections in us
185 for (unsigned int i = 0; i < count; i++) {
186 OSObject *obj = getObject(i);
187 OSCollection *coll = OSDynamicCast(OSCollection, obj);
190 OSCollection *newColl = coll->copyCollection(cycleDict);
194 newMyColl->replaceObject(i, newColl);
206 newMyColl->release();
209 cycleDict->release();
214 @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.
215 @result The newly copied collecton or 0 if insufficient memory
217 virtual OSCollection
* copyCollection ( OSDictionary
* cycleDict
= 0 );
218 OSMetaClassDeclareReservedUsed ( OSCollection
, 1 );
220 OSMetaClassDeclareReservedUnused ( OSCollection
, 2 );
221 OSMetaClassDeclareReservedUnused ( OSCollection
, 3 );
222 OSMetaClassDeclareReservedUnused ( OSCollection
, 4 );
223 OSMetaClassDeclareReservedUnused ( OSCollection
, 5 );
224 OSMetaClassDeclareReservedUnused ( OSCollection
, 6 );
225 OSMetaClassDeclareReservedUnused ( OSCollection
, 7 );
228 #endif /* !_OS_OSCOLLECTION_H */