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