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 /* IOArray.h created by rsulack on Thu 11-Sep-1997 */
25 #include <libkern/c++/OSCollectionIterator.h>
26 #include <libkern/c++/OSCollection.h>
27 #include <libkern/c++/OSArray.h>
28 #include <libkern/c++/OSLib.h>
30 #define super OSIterator
32 OSDefineMetaClassAndStructors(OSCollectionIterator
, OSIterator
)
36 extern int debug_container_malloc_size
;
38 #define ACCUMSIZE(s) do { debug_container_malloc_size += (s); } while(0)
43 bool OSCollectionIterator::initWithCollection(const OSCollection
*inColl
)
45 if ( !super::init() || !inColl
)
51 initialUpdateStamp
= 0;
57 OSCollectionIterator
*
58 OSCollectionIterator::withCollection(const OSCollection
*inColl
)
61 OSCollectionIterator
*me
= new OSCollectionIterator
;
63 if (me
&& !me
->initWithCollection(inColl
)) {
71 void OSCollectionIterator::free()
74 kfree((vm_offset_t
)collIterator
, collection
->iteratorSize());
75 ACCUMSIZE(-(collection
->iteratorSize()));
80 collection
->release();
87 void OSCollectionIterator::reset()
92 collIterator
= (void *)kalloc(collection
->iteratorSize());
93 ACCUMSIZE(collection
->iteratorSize());
98 if (!collection
->initIterator(collIterator
))
101 initialUpdateStamp
= collection
->updateStamp
;
105 bool OSCollectionIterator::isValid()
108 collIterator
= (void *)kalloc(collection
->iteratorSize());
109 ACCUMSIZE(collection
->iteratorSize());
110 if (!collection
->initIterator(collIterator
))
112 initialUpdateStamp
= collection
->updateStamp
;
115 else if (!valid
|| collection
->updateStamp
!= initialUpdateStamp
)
121 OSObject
*OSCollectionIterator::getNextObject()
129 retVal
= collection
->getNextObjectForIterator(collIterator
, &retObj
);
130 return (retVal
)? retObj
: 0;