Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 | /* * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. The rights granted to you under the License * may not be used to create, or enable the creation or redistribution of, * unlawful or unlicensed copies of an Apple operating system, or to * circumvent, violate, or enable the circumvention or violation of, any * terms of an Apple operating system software license agreement. * * Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /* IOCollection.h created by gvdl on Thu 1998-10-22 */ #ifndef _OS_OSCOLLECTION_H #define _OS_OSCOLLECTION_H #include <libkern/c++/OSObject.h> class OSDictionary; /*! * @header * * @abstract * This header declares the OSDictionary collection class. */ /*! * @class OSCollection * * @abstract * The abstract superclass for Libkern collections. * * @discussion * OSCollection is the abstract superclass * for all Libkern C++ object collections. * It defines the necessary interfaces for managing storage space * and iterating through an arbitrary collection * (see the * @link //apple_ref/cpp/class/OSIterator OSIterator@/link * and * @link //apple_ref/cpp/class/OSCollectionIterator OSCollectionIterator@/link * classes). * It is up to concrete subclasses * to define their specific content management functions. * * <b>Use Restrictions</b> * * With very few exceptions in the I/O Kit, all Libkern-based C++ * classes, functions, and macros are <b>unsafe</b> * to use in a primary interrupt context. * Consult the I/O Kit documentation related to primary interrupts * for more information. * * OSCollection provides no concurrency protection; * it's up to the usage context to provide any protection necessary. * Some portions of the I/O Kit, such as * @link //apple_ref/doc/class/IORegistryEntry IORegistryEntry@/link, * handle synchronization via defined member functions for setting * properties. */ class OSCollection : public OSObject { friend class OSCollectionIterator; OSDeclareAbstractStructors(OSCollection); struct ExpansionData { }; protected: /* Not to be included in headerdoc. * * @var updateStamp * * @abstract * A counter for changes to the collection object. * * @discussion * The update stamp is used primarily to track validity * of iteration contexts. * See @link //apple_ref/cpp/class/OSIterator OSIterator@/link and * @link //apple_ref/cpp/class/OSCollectionIterator OSCollectionIterator@/link * for more information. */ unsigned int updateStamp; private: /* Reserved for future use. (Internal use only) */ // ExpansionData * reserved; unsigned int fOptions; protected: // Member functions used by the OSCollectionIterator class. /*! * @function iteratorSize * * @abstract * Returns the size in bytes of a subclass's iteration context. * * @result * The size in bytes of the iteration context * needed by the subclass of OSCollection. * * @discussion * This pure virtual member function, which subclasses must implement, * is called by an * @link //apple_ref/doc/class/OSCollectionIterator OSCollectionIterator@/link * object so that it can allocate the storage needed * for the iteration context. * An iteration context contains the data necessary * to iterate through the collection. */ virtual unsigned int iteratorSize() const = 0; /*! * @function initIterator * * @abstract * Initializes the iteration context for a collection subclass. * * @param iterationContext The iteration context to initialize. * * @result * <code>true</code> if initialization was successful, * <code>false</code> otherwise. * * @discussion * This pure virtual member function, which subclasses must implement, * is called by an * @link //apple_ref/doc/class/OSCollectionIterator OSCollectionIterator@/link * object to initialize an iteration context for a collection. * The collection object should interpret <code>iterationContext</code> appropriately * and initialize its contents to begin an iteration. * * This function can be called repeatedly for a given context, * whenever the iterator is reset via the * @link //apple_ref/cpp/instm/OSCollectionIterator/reset/virtualvoid/() * OSCollectionIterator::reset@/link * function. */ virtual bool initIterator(void * iterationContext) const = 0; /*! * @function getNextObjectForIterator * * @abstract * Returns the next member of a collection. * * @param iterationContext The iteration context. * @param nextObject The object returned by reference to the caller. * * @result * <code>true</code> if an object was found, <code>false</code> otherwise. * * @discussion * This pure virtual member function, which subclasses must implement, * is called by an * @link //apple_ref/doc/class/OSCollectionIterator OSCollectionIterator@/link * to get the next object for a given iteration context. * The collection object should interpret * <code>iterationContext</code> appropriately, * advance the context from its current object * to the next object (if it exists), * return that object by reference in <code>nextObject</code>, * and return <code>true</code> for the function call. * If there is no next object, the collection object must return <code>false</code>. * * For associative collections, the object returned should be the key * used to access its associated value, and not the value itself. */ virtual bool getNextObjectForIterator( void * iterationContext, OSObject ** nextObject) const = 0; /*! * @function init * * @abstract * Initializes the OSCollection object. * * @result * <code>true</code> on success, <code>false</code> otherwise. * * @discussion * This function is used to initialize state * within a newly created OSCollection object. */ virtual bool init(); public: /*! * @typedef _OSCollectionFlags * * @const kImmutable * @discussion * Used with <code>@link setOptions setOptions@/link</code> * to indicate the collection's contents should * or should not change. * * An @link //apple_ref/doc/class/IORegistryEntry IORegistryEntry@/link * object marks collections immutable when set * as properties of a registry entry that's attached to a plane. * This is generally an advisory flag, used for debugging; * setting it does not mean a collection will in fact * disallow modifications. */ typedef enum { kImmutable = 0x00000001, kMASK = (unsigned) -1 } _OSCollectionFlags; // xx-review: should be protected, not public /*! * @function haveUpdated * * @abstract * Tracks updates to the collection. * * @discussion * Subclasses call this function <i>before</i> * making any change to their contents (not after, as the name implies). * Update tracking is used for collection iterators, * and to enforce certain protections in the IORegistry. */ void haveUpdated(); /*! * @function getCount * * @abstract * Returns the number of objects in the collection. * * @result * The number of objects in the collection. * * @discussion * Subclasses must implement this pure virtual member function. */ virtual unsigned int getCount() const = 0; /*! * @function getCapacity * * @abstract * Returns the number of objects the collection * can store without reallocating. * * @result * The number objects the collection * can store without reallocating. * * @discussion * Subclasses must implement this pure virtual member function. */ virtual unsigned int getCapacity() const = 0; /*! * @function getCapacityIncrement * * @abstract * Returns the storage increment of the collection. * * @result * The storage increment of the collection. * * @discussion * Subclasses must implement this pure virtual member function. * Most collection subclasses allocate their storage * in multiples of the capacity increment. * * See * <code>@link * //apple_ref/cpp/instm/OSCollection/ensureCapacity/virtualunsignedint/(unsignedint) * ensureCapacity@/link</code> * for how the capacity increment is used. */ virtual unsigned int getCapacityIncrement() const = 0; /*! * @function setCapacityIncrement * * @abstract * Sets the storage increment of the collection. * * @result * The new storage increment of the collection, * which may be different from the number requested. * * @discussion * Subclasses must implement this pure virtual member function. * Most collection subclasses allocate their storage * in multiples of the capacity increment. * * Collection subclasses should gracefully handle * an <code>increment</code> of zero * by applying (and returning) a positive minimum capacity. * * Setting the capacity increment does not trigger an immediate adjustment * of a collection's storage. * * See * @link * //apple_ref/cpp/instm/OSCollection/ensureCapacity/virtualunsignedint/(unsignedint) * ensureCapacity@/link * for how the capacity increment is used. */ virtual unsigned int setCapacityIncrement(unsigned increment) = 0; /*! * @function ensureCapacity * * @abstract * Ensures the collection has enough space to store * the requested number of objects. * * @param newCapacity The total number of objects the collection * should be able to store. * * @result * The new capacity of the collection, * which may be different from the number requested * (if smaller, reallocation of storage failed). * * @discussion * Subclasses implement this pure virtual member function * to adjust their storage so that they can hold * at least <code>newCapacity</code> objects. * Libkern collections generally allocate storage * in multiples of their capacity increment. * * Subclass methods that add objects to the collection * should call this function before adding any object, * and should check the return value for success. * * Collection subclasses may reduce their storage * when the number of contained objects falls below some threshold, * but no Libkern collections currently do. */ virtual unsigned int ensureCapacity(unsigned int newCapacity) = 0; /*! * @function flushCollection * * @abstract * Empties the collection, releasing any objects retained. * * @discussion * Subclasses implement this pure virtual member function * to remove their entire contents. * This must not release the collection itself. */ virtual void flushCollection() = 0; /*! * @function setOptions * * @abstract * Recursively sets option bits in this collection * and all child collections. * * @param options A bitfield whose values turn the options on (1) or off (0). * @param mask A mask indicating which bits * in <code>options</code> to change. * Pass 0 to get the whole current options bitfield * without changing any settings. * @param context Unused. * * @result * The options bitfield as it was before the set operation. * * @discussion * Kernel extensions should not call this function. * * The only option currently in use is * <code>@link //apple_ref/doc/title:econst/OSCollectionFlags/kImmutable * kImmutable@/link</code>. * * Subclasses should override this function to recursively apply * the options to their contents if the options actually change. */ virtual unsigned setOptions( unsigned options, unsigned mask, void * context = 0); OSMetaClassDeclareReservedUsed(OSCollection, 0); /*! * @function copyCollection * * @abstract * Creates a deep copy of a collection. * * @param cycleDict A dictionary of all of the collections * that have been copied so far, * to start the copy at the top level * pass <code>NULL</code> for <code>cycleDict</code>. * * @result * The newly copied collecton, * <code>NULL</code> on failure. * * @discussion * This function copies the collection * and all of the contained collections recursively. * Objects that are not derived from OSCollection are retained * rather than copied. * * Subclasses of OSCollection must override this function * to properly support deep copies. */ virtual OSCollection *copyCollection(OSDictionary * cycleDict = 0); OSMetaClassDeclareReservedUsed(OSCollection, 1); OSMetaClassDeclareReservedUnused(OSCollection, 2); OSMetaClassDeclareReservedUnused(OSCollection, 3); OSMetaClassDeclareReservedUnused(OSCollection, 4); OSMetaClassDeclareReservedUnused(OSCollection, 5); OSMetaClassDeclareReservedUnused(OSCollection, 6); OSMetaClassDeclareReservedUnused(OSCollection, 7); }; #endif /* !_OS_OSCOLLECTION_H */ |