2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 /* IOArray.h created by rsulack on Thu 11-Sep-1997 */
27 #include <libkern/c++/OSCollectionIterator.h>
28 #include <libkern/c++/OSCollection.h>
29 #include <libkern/c++/OSArray.h>
30 #include <libkern/c++/OSLib.h>
32 #define super OSIterator
34 OSDefineMetaClassAndStructors(OSCollectionIterator
, OSIterator
)
38 extern int debug_container_malloc_size
;
40 #define ACCUMSIZE(s) do { debug_container_malloc_size += (s); } while(0)
45 bool OSCollectionIterator::initWithCollection(const OSCollection
*inColl
)
47 if ( !super::init() || !inColl
)
53 initialUpdateStamp
= 0;
59 OSCollectionIterator
*
60 OSCollectionIterator::withCollection(const OSCollection
*inColl
)
63 OSCollectionIterator
*me
= new OSCollectionIterator
;
65 if (me
&& !me
->initWithCollection(inColl
)) {
73 void OSCollectionIterator::free()
76 kfree((vm_offset_t
)collIterator
, collection
->iteratorSize());
77 ACCUMSIZE(-(collection
->iteratorSize()));
82 collection
->release();
89 void OSCollectionIterator::reset()
94 collIterator
= (void *)kalloc(collection
->iteratorSize());
95 ACCUMSIZE(collection
->iteratorSize());
100 if (!collection
->initIterator(collIterator
))
103 initialUpdateStamp
= collection
->updateStamp
;
107 bool OSCollectionIterator::isValid()
110 collIterator
= (void *)kalloc(collection
->iteratorSize());
111 ACCUMSIZE(collection
->iteratorSize());
112 if (!collection
->initIterator(collIterator
))
114 initialUpdateStamp
= collection
->updateStamp
;
117 else if (!valid
|| collection
->updateStamp
!= initialUpdateStamp
)
123 OSObject
*OSCollectionIterator::getNextObject()
131 retVal
= collection
->getNextObjectForIterator(collIterator
, &retObj
);
132 return (retVal
)? retObj
: 0;