|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 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. ! 11: * ! 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 ! 18: * under the License. ! 19: * ! 20: * @APPLE_LICENSE_HEADER_END@ ! 21: */ ! 22: /* IOArray.h created by rsulack on Thu 11-Sep-1997 */ ! 23: ! 24: #include <libkern/c++/OSCollectionIterator.h> ! 25: #include <libkern/c++/OSCollection.h> ! 26: #include <libkern/c++/OSArray.h> ! 27: #include <libkern/c++/OSLib.h> ! 28: ! 29: #define super OSIterator ! 30: ! 31: OSDefineMetaClassAndStructors(OSCollectionIterator, OSIterator) ! 32: ! 33: #ifdef DEBUG ! 34: extern "C" { ! 35: extern int debug_container_malloc_size; ! 36: }; ! 37: #define ACCUMSIZE(s) do { debug_container_malloc_size += (s); } while(0) ! 38: #else ! 39: #define ACCUMSIZE(s) ! 40: #endif ! 41: ! 42: bool OSCollectionIterator::initWithCollection(OSCollection *inColl) ! 43: { ! 44: if ( !super::init() || !inColl) ! 45: return false; ! 46: ! 47: inColl->retain(); ! 48: collection = inColl; ! 49: collIterator = 0; ! 50: arrayReturn = 0; ! 51: initialUpdateStamp = 0; ! 52: valid = false; ! 53: ! 54: return this; ! 55: } ! 56: ! 57: OSCollectionIterator * ! 58: OSCollectionIterator::withCollection(OSCollection *inColl) ! 59: { ! 60: ! 61: OSCollectionIterator *me = new OSCollectionIterator; ! 62: ! 63: if (me && !me->initWithCollection(inColl)) { ! 64: me->free(); ! 65: return 0; ! 66: } ! 67: ! 68: return me; ! 69: } ! 70: ! 71: void OSCollectionIterator::free() ! 72: { ! 73: if (arrayReturn) { ! 74: arrayReturn->release(); ! 75: arrayReturn = 0; ! 76: } ! 77: ! 78: if (collIterator) { ! 79: kfree((vm_offset_t)collIterator, collection->iteratorSize()); ! 80: ACCUMSIZE(-(collection->iteratorSize())); ! 81: collIterator = 0; ! 82: } ! 83: ! 84: if (collection) { ! 85: collection->release(); ! 86: collection = 0; ! 87: } ! 88: ! 89: super::free(); ! 90: } ! 91: ! 92: void OSCollectionIterator::reset() ! 93: { ! 94: valid = false; ! 95: ! 96: if (!collIterator) { ! 97: collIterator = (void *)kalloc(collection->iteratorSize()); ! 98: ACCUMSIZE(collection->iteratorSize()); ! 99: if (!collIterator) ! 100: return; ! 101: } ! 102: ! 103: if (!collection->initIterator(collIterator)) ! 104: return; ! 105: ! 106: initialUpdateStamp = collection->updateStamp; ! 107: valid = true; ! 108: } ! 109: ! 110: bool OSCollectionIterator::isValid() ! 111: { ! 112: if (!collIterator) { ! 113: collIterator = (void *)kalloc(collection->iteratorSize()); ! 114: ACCUMSIZE(collection->iteratorSize()); ! 115: if (!collection->initIterator(collIterator)) ! 116: return false; ! 117: initialUpdateStamp = collection->updateStamp; ! 118: valid = true; ! 119: } ! 120: else if (!valid || collection->updateStamp != initialUpdateStamp) ! 121: return false; ! 122: ! 123: return true; ! 124: } ! 125: ! 126: OSObject *OSCollectionIterator::getNextObject() ! 127: { ! 128: OSObject *retObj; ! 129: bool retVal; ! 130: ! 131: if (!isValid()) ! 132: return 0; ! 133: ! 134: retVal = collection->getNextObjectForIterator(collIterator, &retObj); ! 135: return (retVal)? retObj : 0; ! 136: } ! 137:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.