]> git.saurik.com Git - apple/xnu.git/blob - libkern/c++/OSCollection.cpp
828ebbd4b2521723a21ba2824dad1808664ed619
[apple/xnu.git] / libkern / c++ / OSCollection.cpp
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /* IOArray.h created by rsulack on Thu 11-Sep-1997 */
24
25 #include <libkern/OSDebug.h>
26
27 #include <libkern/c++/OSCollection.h>
28 #include <libkern/c++/OSDictionary.h>
29
30 #include <IOKit/IOKitDebug.h>
31
32 #define super OSObject
33
34 OSDefineMetaClassAndAbstractStructors(OSCollection, OSObject)
35
36
37 OSMetaClassDefineReservedUsed(OSCollection, 0);
38 OSMetaClassDefineReservedUsed(OSCollection, 1);
39 OSMetaClassDefineReservedUnused(OSCollection, 2);
40 OSMetaClassDefineReservedUnused(OSCollection, 3);
41 OSMetaClassDefineReservedUnused(OSCollection, 4);
42 OSMetaClassDefineReservedUnused(OSCollection, 5);
43 OSMetaClassDefineReservedUnused(OSCollection, 6);
44 OSMetaClassDefineReservedUnused(OSCollection, 7);
45
46 bool OSCollection::init()
47 {
48 if (!super::init())
49 return false;
50
51 updateStamp = 0;
52
53 return true;
54 }
55
56 void OSCollection::haveUpdated()
57 {
58 if ( (gIOKitDebug & kOSLogRegistryMods) && (fOptions & kImmutable) )
59 OSReportWithBacktrace("Trying to change a collection in the registry");
60
61 updateStamp++;
62 }
63
64 unsigned OSCollection::setOptions(unsigned options, unsigned mask, void *)
65 {
66 unsigned old = fOptions;
67
68 if (mask)
69 fOptions = (old & ~mask) | (options & mask);
70
71 return old;
72 }
73
74 OSCollection * OSCollection::copyCollection(OSDictionary *cycleDict)
75 {
76 if (cycleDict) {
77 OSObject *obj = cycleDict->getObject((const OSSymbol *) this);
78 if (obj)
79 obj->retain();
80
81 return reinterpret_cast<OSCollection *>(obj);
82 }
83 else {
84 // If we are here it means that there is a collection subclass that
85 // hasn't overridden the copyCollection method. In which case just
86 // return a reference to ourselves.
87 // Hopefully this collection will not be inserted into the registry
88 retain();
89 return this;
90 }
91 }