xref: /xnu-11215/libkern/c++/OSCollection.cpp (revision 14e3d835)
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/OSDebug.h>
25 
26 #include <libkern/c++/OSCollection.h>
27 #include <libkern/c++/OSDictionary.h>
28 
29 #include <IOKit/IOKitDebug.h>
30 
31 #define super OSObject
32 
33 OSDefineMetaClassAndAbstractStructors(OSCollection, OSObject)
34 
35 
36 OSMetaClassDefineReservedUsed(OSCollection, 0);
37 OSMetaClassDefineReservedUsed(OSCollection, 1);
38 OSMetaClassDefineReservedUnused(OSCollection, 2);
39 OSMetaClassDefineReservedUnused(OSCollection, 3);
40 OSMetaClassDefineReservedUnused(OSCollection, 4);
41 OSMetaClassDefineReservedUnused(OSCollection, 5);
42 OSMetaClassDefineReservedUnused(OSCollection, 6);
43 OSMetaClassDefineReservedUnused(OSCollection, 7);
44 
45 bool OSCollection::init()
46 {
47     if (!super::init())
48         return false;
49 
50     updateStamp = 0;
51 
52     return true;
53 }
54 
55 void OSCollection::haveUpdated()
56 {
57     if ( (gIOKitDebug & kOSLogRegistryMods) && (fOptions & kImmutable) )
58 	OSReportWithBacktrace("Trying to change a collection in the registry");
59 
60     updateStamp++;
61 }
62 
63 unsigned OSCollection::setOptions(unsigned options, unsigned mask, void *)
64 {
65     unsigned old = fOptions;
66 
67     if (mask)
68 	fOptions = (old & ~mask) | (options & mask);
69 
70     return old;
71 }
72 
73 OSCollection *  OSCollection::copyCollection(OSDictionary *cycleDict)
74 {
75     if (cycleDict) {
76 	OSObject *obj = cycleDict->getObject((const OSSymbol *) this);
77 	if (obj)
78 	    obj->retain();
79 
80 	return reinterpret_cast<OSCollection *>(obj);
81     }
82     else {
83 	// If we are here it means that there is a collection subclass that
84 	// hasn't overridden the copyCollection method.  In which case just
85 	// return a reference to ourselves.
86 	// Hopefully this collection will not be inserted into the registry
87 	retain();
88 	return this;
89     }
90 }
91