]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/c++/OSNumber.h
c54c3a3c6ce3b6805332fb5726479b368e321a2a
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* IOOffset.h created by rsulack on Wed 17-Sep-1997 */
29 /* IOOffset.h converted to C++ by gvdl on Fri 1998-10-30 */
31 #ifndef _OS_OSNUMBER_H
32 #define _OS_OSNUMBER_H
34 #include <libkern/c++/OSObject.h>
40 * This header declares the OSNumber container class.
48 * OSNumber wraps an integer value in a C++ object
49 * for use in Libkern collections.
52 * OSNumber represents an integer of 8, 16, 32, or 64 bits
53 * as a Libkern C++ object.
54 * OSNumber objects are mutable: you can add to or set their values.
56 * <b>Use Restrictions</b>
58 * With very few exceptions in the I/O Kit, all Libkern-based C++
59 * classes, functions, and macros are <b>unsafe</b>
60 * to use in a primary interrupt context.
61 * Consult the I/O Kit documentation related to primary interrupts
62 * for more information.
64 * OSNumber provides no concurrency protection;
65 * it's up to the usage context to provide any protection necessary.
66 * Some portions of the I/O Kit, such as
67 * @link //apple_ref/doc/class/IORegistryEntry IORegistryEntry@/link,
68 * handle synchronization via defined member functions for setting
71 class OSNumber
: public OSObject
73 OSDeclareDefaultStructors(OSNumber
)
74 friend class OSSerialize
;
77 unsigned long long value
;
80 struct ExpansionData
{ };
82 /* Reserved for future use. (Internal use only) */
83 ExpansionData
* reserved
;
89 * @function withNumber
92 * Creates and initializes an instance of OSNumber
93 * with an integer value.
95 * @param value The numeric integer value for the OSNumber to store.
96 * @param numberOfBits The number of bits to limit storage to.
99 * An instance of OSNumber with a reference count of 1;
100 * <code>NULL</code> on failure.
103 * <code>value</code> is masked to the provided <code>numberOfBits</code>
104 * when the OSNumber object is initialized.
106 * You can change the value of an OSNumber later
107 * using <code>@link setValue setValue@/link</code>
108 * and <code>@link addValue addValue@/link</code>,
109 * but you can't change the bit size.
111 static OSNumber
* withNumber(
112 unsigned long long value
,
113 unsigned int numberOfBits
);
117 * @function withNumber
120 * Creates and initializes an instance of OSNumber
121 * with an unsigned integer value represented as a C string.
123 * @param valueString A C string representing a numeric value
124 * for the OSNumber to store.
125 * @param numberOfBits The number of bits to limit storage to.
128 * An instance of OSNumber with a reference count of 1;
129 * <code>NULL</code> on failure.
132 * This function does not work in I/O Kit versions prior to 8.0 (Mac OS X 10.4).
133 * In I/O Kit version 8.0 and later, it works
134 * but is limited to parsing unsigned 32 bit quantities.
135 * The format of the C string may be decimal, hexadecimal ("0x" prefix),
136 * binary ("0b" prefix), or octal ("0" prefix).
138 * The parsed value is masked to the provided <code>numberOfBits</code>
139 * when the OSNumber object is initialized.
141 * You can change the value of an OSNumber later
142 * using <code>@link setValue setValue@/link</code>
143 * and <code>@link addValue addValue@/link</code>,
144 * but you can't change the bit size.
146 static OSNumber
* withNumber(
147 const char * valueString
,
148 unsigned int numberOfBits
);
155 * Initializes an instance of OSNumber with an integer value.
157 * @param value The numeric integer value for the OSNumber to store.
158 * @param numberOfBits The number of bits to limit storage to.
161 * <code>true</code> if initialization succeeds,
162 * <code>false</code> on failure.
165 * Not for general use. Use the static instance creation method
167 * //apple_ref/cpp/clm/OSNumber/withNumber/staticOSNumber*\/(constchar*,unsignedint)
168 * withNumber(unsigned long long, unsigned int)@/link</code>
172 unsigned long long value
,
173 unsigned int numberOfBits
);
180 * Initializes an instance of OSNumber
181 * with an unsigned integer value represented as a C string.
183 * @param valueString A C string representing a numeric value
184 * for the OSNumber to store.
185 * @param numberOfBits The number of bits to limit storage to.
188 * <code>true</code> if initialization succeeds,
189 * <code>false</code> on failure.
192 * Not for general use. Use the static instance creation method
194 * //apple_ref/cpp/clm/OSNumber/withNumber/staticOSNumber*\/(constchar*,unsignedint)
195 * withNumber(const char *, unsigned int)@/link</code>
199 const char * valueString
,
200 unsigned int numberOfBits
);
207 * Deallocates or releases any resources
208 * used by the OSNumber instance.
211 * This function should not be called directly;
214 * //apple_ref/cpp/instm/OSObject/release/virtualvoid/()
215 * release@/link</code>
218 virtual void free() APPLE_KEXT_OVERRIDE
;
222 * @function numberOfBits
225 * Returns the number of bits used to represent
226 * the OSNumber object's integer value.
229 * The number of bits used to represent
230 * the OSNumber object's integer value.
233 * The number of bits is used to limit the stored value of the OSNumber.
234 * Any change to its value is performed as an <code>unsigned long long</code>
235 * and then truncated to the number of bits.
237 virtual unsigned int numberOfBits() const;
241 * @function numberOfBytes
244 * Returns the number of bytes used to represent
245 * the OSNumber object's integer value.
248 * The number of bytes used to represent
249 * the OSNumber object's integer value.
250 * See <code>@link numberOfBits numberOfBits@/link</code>.
252 virtual unsigned int numberOfBytes() const;
255 // xx-review: should switch to explicitly-sized int types
256 // xx-review: but that messes up C++ mangled symbols :-(
260 * @function unsigned8BitValue
263 * Returns the OSNumber object's integer value
264 * cast as an unsigned 8-bit integer.
267 * The OSNumber object's integer value
268 * cast as an unsigned 8-bit integer.
271 * This function merely casts the internal integer value,
272 * giving no indication of truncation or other potential conversion problems.
274 virtual unsigned char unsigned8BitValue() const;
278 * @function unsigned16BitValue
281 * Returns the OSNumber object's integer value
282 * cast as an unsigned 16-bit integer.
285 * Returns the OSNumber object's integer value
286 * cast as an unsigned 16-bit integer.
289 * This function merely casts the internal integer value,
290 * giving no indication of truncation or other potential conversion problems.
292 virtual unsigned short unsigned16BitValue() const;
296 * @function unsigned32BitValue
299 * Returns the OSNumber object's integer value
300 * cast as an unsigned 32-bit integer.
303 * Returns the OSNumber object's integer value
304 * cast as an unsigned 32-bit integer.
307 * This function merely casts the internal integer value,
308 * giving no indication of truncation or other potential conversion problems.
310 virtual unsigned int unsigned32BitValue() const;
314 * @function unsigned64BitValue
317 * Returns the OSNumber object's integer value
318 * cast as an unsigned 64-bit integer.
321 * Returns the OSNumber object's integer value
322 * cast as an unsigned 64-bit integer.
325 * This function merely casts the internal integer value,
326 * giving no indication of truncation or other potential conversion problems.
328 virtual unsigned long long unsigned64BitValue() const;
330 // xx-review: wow, there's no addNumber(OSNumber *)!
336 * Adds a signed integer value to the internal integer value
337 * of the OSNumber object.
339 * @param value The value to be added.
342 * This function adds values as 64-bit integers,
343 * but masks the result by the bit size
344 * (see <code>@link numberOfBits numberOfBits@/link</code>),
345 * so addition overflows will not necessarily
346 * be the same as for plain C integers.
348 virtual void addValue(signed long long value
);
355 * Replaces the current internal integer value
356 * of the OSNumber object by the value given.
358 * @param value The new value for the OSNumber object,
359 * which is truncated by the bit size of the OSNumber object
360 * (see <code>@link numberOfBits numberOfBits@/link</code>).
362 virtual void setValue(unsigned long long value
);
366 * @function isEqualTo
369 * Tests the equality of two OSNumber objects.
371 * @param aNumber The OSNumber to be compared against the receiver.
374 * <code>true</code> if the OSNumber objects are equal,
375 * <code>false</code> if not.
378 * Two OSNumber objects are considered equal
379 * if they represent the same C integer value.
381 virtual bool isEqualTo(const OSNumber
* aNumber
) const;
385 * @function isEqualTo
388 * Tests the equality an OSNumber to an arbitrary object.
390 * @param anObject An object to be compared against the receiver.
393 * <code>true</code> if the objects are equal,
394 * <code>false</code> if not.
397 * An OSNumber is considered equal to another object if that object is
398 * derived from OSNumber and represents the same C integer value.
400 virtual bool isEqualTo(const OSMetaClassBase
* anObject
) const APPLE_KEXT_OVERRIDE
;
404 * @function serialize
407 * Archives the receiver into the provided
408 * @link //apple_ref/doc/class/OSSerialize OSSerialize@/link object.
410 * @param serializer The OSSerialize object.
413 * <code>true</code> if serialization succeeds, <code>false</code> if not.
415 virtual bool serialize(OSSerialize
* serializer
) const APPLE_KEXT_OVERRIDE
;
418 OSMetaClassDeclareReservedUnused(OSNumber
, 0);
419 OSMetaClassDeclareReservedUnused(OSNumber
, 1);
420 OSMetaClassDeclareReservedUnused(OSNumber
, 2);
421 OSMetaClassDeclareReservedUnused(OSNumber
, 3);
422 OSMetaClassDeclareReservedUnused(OSNumber
, 4);
423 OSMetaClassDeclareReservedUnused(OSNumber
, 5);
424 OSMetaClassDeclareReservedUnused(OSNumber
, 6);
425 OSMetaClassDeclareReservedUnused(OSNumber
, 7);
428 #endif /* !_OS_OSNUMBER_H */