2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 /* IOArray.h created by rsulack on Thu 11-Sep-1997 */
32 #include <libkern/c++/OSCollectionIterator.h>
33 #include <libkern/c++/OSCollection.h>
34 #include <libkern/c++/OSArray.h>
35 #include <libkern/c++/OSLib.h>
37 #define super OSIterator
39 OSDefineMetaClassAndStructors(OSCollectionIterator
, OSIterator
)
43 extern int debug_container_malloc_size
;
45 #define ACCUMSIZE(s) do { debug_container_malloc_size += (s); } while(0)
50 bool OSCollectionIterator::initWithCollection(const OSCollection
*inColl
)
52 if ( !super::init() || !inColl
)
58 initialUpdateStamp
= 0;
64 OSCollectionIterator
*
65 OSCollectionIterator::withCollection(const OSCollection
*inColl
)
68 OSCollectionIterator
*me
= new OSCollectionIterator
;
70 if (me
&& !me
->initWithCollection(inColl
)) {
78 void OSCollectionIterator::free()
81 kfree((vm_offset_t
)collIterator
, collection
->iteratorSize());
82 ACCUMSIZE(-(collection
->iteratorSize()));
87 collection
->release();
94 void OSCollectionIterator::reset()
99 collIterator
= (void *)kalloc(collection
->iteratorSize());
100 ACCUMSIZE(collection
->iteratorSize());
105 if (!collection
->initIterator(collIterator
))
108 initialUpdateStamp
= collection
->updateStamp
;
112 bool OSCollectionIterator::isValid()
115 collIterator
= (void *)kalloc(collection
->iteratorSize());
116 ACCUMSIZE(collection
->iteratorSize());
117 if (!collection
->initIterator(collIterator
))
119 initialUpdateStamp
= collection
->updateStamp
;
122 else if (!valid
|| collection
->updateStamp
!= initialUpdateStamp
)
128 OSObject
*OSCollectionIterator::getNextObject()
136 retVal
= collection
->getNextObjectForIterator(collIterator
, &retObj
);
137 return (retVal
)? retObj
: 0;