]> git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/c++/OSSymbol.h
xnu-517.3.15.tar.gz
[apple/xnu.git] / libkern / libkern / c++ / OSSymbol.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
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
13 * file.
14 *
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.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /* IOSymbol.h created by gvdl on Fri 1998-10-30 */
26 /* IOSymbol must be created through the factory methods and thus is not subclassable. */
27
28 #ifndef _OS_OSSYMBOL_H
29 #define _OS_OSSYMBOL_H
30
31 #include <libkern/c++/OSString.h>
32
33 /*!
34 @class OSSymbol
35 @abstract A container class whose instances represent unique string values.
36 @discussion
37 An OSSymbol object represents a unique string value. When creating an OSSymbol, a string is given and an OSSymbol representing this string is created if none exist for this string. If a symbol for this string already exists, then a reference to an existing symbol is returned.
38 */
39 class OSSymbol : public OSString
40 {
41 friend class OSSymbolPool;
42
43 OSDeclareAbstractStructors(OSSymbol)
44
45 private:
46 struct ExpansionData { };
47
48 /*! @var reserved
49 Reserved for future use. (Internal use only) */
50 ExpansionData *reserved;
51
52 static void initialize();
53
54 friend void checkModuleForSymbols(void); /* in catalogue? */
55
56 // The string init methods have to be removed from the inheritance.
57 virtual bool initWithString(const OSString *aString);
58 virtual bool initWithCString(const char *cString);
59 virtual bool initWithCStringNoCopy(const char *cString);
60
61 protected:
62 /*!
63 @function taggedRelease
64 @abstract Overriden super class release method so we can synchronise with the symbol pool.
65 @discussion When we release an symbol we need to synchronise the destruction of the object with any potential searches that may be occuring through the family factor methods. See OSObject::taggedRelease
66 */
67 virtual void taggedRelease(const void *tag, const int when) const;
68
69 /*!
70 @function free
71 @abstract Overriden super class release method so we can synchronise with the symbol pool.
72 @discussion When we release an symbol we need to synchronise the destruction of the object with any potential searches that may be occuring through the family factor methods. See OSObject::free
73 */
74 virtual void free();
75
76 public:
77 /*!
78 @function taggedRelease
79 @abstract Release a tag.
80 @discussion The C++ language has forced me to override this method even though I have implemented it as { super::taggedRelease(tag) }. It seems that C++ is confused about the appearance of the protected taggedRelease with 2 args and refuses to only inherit one function. See OSObject::taggedRelease
81 */
82 virtual void taggedRelease(const void *tag) const;
83
84
85 /*!
86 @function withString
87 @abstract A static constructor function to create an OSSymbol instance from an OSString object or returns an existing OSSymbol object based on the OSString object given.
88 @param aString An OSString object.
89 @result Returns a unique OSSymbol object for the string given.
90 */
91 static const OSSymbol *withString(const OSString *aString);
92 /*!
93 @function withCString
94 @abstract A static constructor function to create an OSSymbol instance from a simple c-string returns an existing OSSymbol object based on the string object given.
95 @param cString A c-string.
96 @result Returns a unique OSSymbol object for the string given.
97 */
98 static const OSSymbol *withCString(const char *cString);
99 /*!
100 @function withCStringNoCopy
101 @abstract A static constructor function to create an OSSymbol instance from a simple c-string, but does not copy the string to the container.
102 @param cString A c-string.
103 @result Returns a unique OSSymbol object for the string given.
104 */
105 static const OSSymbol *withCStringNoCopy(const char *cString);
106
107 /*!
108 @function isEqualTo
109 @abstract A member function which tests the equality between two OSSymbol objects. Two OSSymbol objects are only equivalent when their references are identical
110 @param aSymbol The OSSymbol object to be compared against the receiver.
111 @result Returns true if the two objects are equivalent, false otherwise.
112 */
113 virtual bool isEqualTo(const OSSymbol *aSymbol) const;
114 /*!
115 @function isEqualTo
116 @abstract A member function which tests the equality between an OSSymbol object and a simple c-string.
117 @param aCString The c-string to be compared against the receiver.
118 @result Returns true if the OSSymbol's internal string representation is equivalent to the c-string it is being compared against, false otherwise.
119 */
120 virtual bool isEqualTo(const char *aCString) const;
121 /*!
122 @function isEqualTo
123 @abstract A member function which tests the equality between an OSSymbol object and and arbitrary OSObject derived object.
124 @param obj The OSObject derived object to be compared against the receiver.
125 @result Returns true if the OSSymbol and the OSObject objects are equivalent.
126 */
127 virtual bool isEqualTo(const OSMetaClassBase *obj) const;
128
129 /* OSRuntime only INTERNAL API - DO NOT USE */
130 static void checkForPageUnload(void *startAddr, void *endAddr);
131
132
133 OSMetaClassDeclareReservedUnused(OSSymbol, 0);
134 OSMetaClassDeclareReservedUnused(OSSymbol, 1);
135 OSMetaClassDeclareReservedUnused(OSSymbol, 2);
136 OSMetaClassDeclareReservedUnused(OSSymbol, 3);
137 OSMetaClassDeclareReservedUnused(OSSymbol, 4);
138 OSMetaClassDeclareReservedUnused(OSSymbol, 5);
139 OSMetaClassDeclareReservedUnused(OSSymbol, 6);
140 OSMetaClassDeclareReservedUnused(OSSymbol, 7);
141 };
142
143 #endif /* !_OS_OSSYMBOL_H */