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 /* IOArray.h created by rsulack on Thu 11-Sep-1997 */
24 #include <libkern/c++/OSCollectionIterator.h>
25 #include <libkern/c++/OSCollection.h>
26 #include <libkern/c++/OSArray.h>
27 #include <libkern/c++/OSLib.h>
29 #define super OSIterator
31 OSDefineMetaClassAndStructors(OSCollectionIterator
, OSIterator
)
35 extern int debug_container_malloc_size
;
37 #define ACCUMSIZE(s) do { debug_container_malloc_size += (s); } while(0)
42 bool OSCollectionIterator::initWithCollection(const OSCollection
*inColl
)
44 if ( !super::init() || !inColl
)
50 initialUpdateStamp
= 0;
56 OSCollectionIterator
*
57 OSCollectionIterator::withCollection(const OSCollection
*inColl
)
60 OSCollectionIterator
*me
= new OSCollectionIterator
;
62 if (me
&& !me
->initWithCollection(inColl
)) {
70 void OSCollectionIterator::free()
73 kfree(collIterator
, collection
->iteratorSize());
74 ACCUMSIZE(-(collection
->iteratorSize()));
79 collection
->release();
86 void OSCollectionIterator::reset()
91 collIterator
= (void *)kalloc(collection
->iteratorSize());
92 ACCUMSIZE(collection
->iteratorSize());
97 if (!collection
->initIterator(collIterator
))
100 initialUpdateStamp
= collection
->updateStamp
;
104 bool OSCollectionIterator::isValid()
107 collIterator
= (void *)kalloc(collection
->iteratorSize());
108 ACCUMSIZE(collection
->iteratorSize());
109 if (!collection
->initIterator(collIterator
))
111 initialUpdateStamp
= collection
->updateStamp
;
114 else if (!valid
|| collection
->updateStamp
!= initialUpdateStamp
)
120 OSObject
*OSCollectionIterator::getNextObject()
128 retVal
= collection
->getNextObjectForIterator(collIterator
, &retObj
);
129 return (retVal
)? retObj
: 0;