]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/c++/OSNumber.h
0b206784e03e20c6fd4d75ff6d5900dec278e555
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
)
76 unsigned long long value
;
79 struct ExpansionData
{ };
81 /* Reserved for future use. (Internal use only) */
82 ExpansionData
* reserved
;
88 * @function withNumber
91 * Creates and initializes an instance of OSNumber
92 * with an integer value.
94 * @param value The numeric integer value for the OSNumber to store.
95 * @param numberOfBits The number of bits to limit storage to.
98 * An instance of OSNumber with a reference count of 1;
99 * <code>NULL</code> on failure.
102 * <code>value</code> is masked to the provided <code>numberOfBits</code>
103 * when the OSNumber object is initialized.
105 * You can change the value of an OSNumber later
106 * using <code>@link setValue setValue@/link</code>
107 * and <code>@link addValue addValue@/link</code>,
108 * but you can't change the bit size.
110 static OSNumber
* withNumber(
111 unsigned long long value
,
112 unsigned int numberOfBits
);
116 * @function withNumber
119 * Creates and initializes an instance of OSNumber
120 * with an unsigned integer value represented as a C string.
122 * @param valueString A C string representing a numeric value
123 * for the OSNumber to store.
124 * @param numberOfBits The number of bits to limit storage to.
127 * An instance of OSNumber with a reference count of 1;
128 * <code>NULL</code> on failure.
131 * This function does not work in I/O Kit versions prior to 8.0 (Mac OS X 10.4).
132 * In I/O Kit version 8.0 and later, it works
133 * but is limited to parsing unsigned 32 bit quantities.
134 * The format of the C string may be decimal, hexadecimal ("0x" prefix),
135 * binary ("0b" prefix), or octal ("0" prefix).
137 * The parsed value is masked to the provided <code>numberOfBits</code>
138 * when the OSNumber object is initialized.
140 * You can change the value of an OSNumber later
141 * using <code>@link setValue setValue@/link</code>
142 * and <code>@link addValue addValue@/link</code>,
143 * but you can't change the bit size.
145 static OSNumber
* withNumber(
146 const char * valueString
,
147 unsigned int numberOfBits
);
154 * Initializes an instance of OSNumber with an integer value.
156 * @param value The numeric integer value for the OSNumber to store.
157 * @param numberOfBits The number of bits to limit storage to.
160 * <code>true</code> if initialization succeeds,
161 * <code>false</code> on failure.
164 * Not for general use. Use the static instance creation method
166 * //apple_ref/cpp/clm/OSNumber/withNumber/staticOSNumber*\/(constchar*,unsignedint)
167 * withNumber(unsigned long long, unsigned int)@/link</code>
171 unsigned long long value
,
172 unsigned int numberOfBits
);
179 * Initializes an instance of OSNumber
180 * with an unsigned integer value represented as a C string.
182 * @param valueString A C string representing a numeric value
183 * for the OSNumber to store.
184 * @param numberOfBits The number of bits to limit storage to.
187 * <code>true</code> if initialization succeeds,
188 * <code>false</code> on failure.
191 * Not for general use. Use the static instance creation method
193 * //apple_ref/cpp/clm/OSNumber/withNumber/staticOSNumber*\/(constchar*,unsignedint)
194 * withNumber(const char *, unsigned int)@/link</code>
198 const char * valueString
,
199 unsigned int numberOfBits
);
206 * Deallocates or releases any resources
207 * used by the OSNumber instance.
210 * This function should not be called directly;
213 * //apple_ref/cpp/instm/OSObject/release/virtualvoid/()
214 * release@/link</code>
221 * @function numberOfBits
224 * Returns the number of bits used to represent
225 * the OSNumber object's integer value.
228 * The number of bits used to represent
229 * the OSNumber object's integer value.
232 * The number of bits is used to limit the stored value of the OSNumber.
233 * Any change to its value is performed as an <code>unsigned long long</code>
234 * and then truncated to the number of bits.
236 virtual unsigned int numberOfBits() const;
240 * @function numberOfBytes
243 * Returns the number of bytes used to represent
244 * the OSNumber object's integer value.
247 * The number of bytes used to represent
248 * the OSNumber object's integer value.
249 * See <code>@link numberOfBits numberOfBits@/link</code>.
251 virtual unsigned int numberOfBytes() const;
254 // xx-review: should switch to explicitly-sized int types
255 // xx-review: but that messes up C++ mangled symbols :-(
259 * @function unsigned8BitValue
262 * Returns the OSNumber object's integer value
263 * cast as an unsigned 8-bit integer.
266 * The OSNumber object's integer value
267 * cast as an unsigned 8-bit integer.
270 * This function merely casts the internal integer value,
271 * giving no indication of truncation or other potential conversion problems.
273 virtual unsigned char unsigned8BitValue() const;
277 * @function unsigned16BitValue
280 * Returns the OSNumber object's integer value
281 * cast as an unsigned 16-bit integer.
284 * Returns the OSNumber object's integer value
285 * cast as an unsigned 16-bit integer.
288 * This function merely casts the internal integer value,
289 * giving no indication of truncation or other potential conversion problems.
291 virtual unsigned short unsigned16BitValue() const;
295 * @function unsigned32BitValue
298 * Returns the OSNumber object's integer value
299 * cast as an unsigned 32-bit integer.
302 * Returns the OSNumber object's integer value
303 * cast as an unsigned 32-bit integer.
306 * This function merely casts the internal integer value,
307 * giving no indication of truncation or other potential conversion problems.
309 virtual unsigned int unsigned32BitValue() const;
313 * @function unsigned64BitValue
316 * Returns the OSNumber object's integer value
317 * cast as an unsigned 64-bit integer.
320 * Returns the OSNumber object's integer value
321 * cast as an unsigned 64-bit integer.
324 * This function merely casts the internal integer value,
325 * giving no indication of truncation or other potential conversion problems.
327 virtual unsigned long long unsigned64BitValue() const;
329 // xx-review: wow, there's no addNumber(OSNumber *)!
335 * Adds a signed integer value to the internal integer value
336 * of the OSNumber object.
338 * @param value The value to be added.
341 * This function adds values as 64-bit integers,
342 * but masks the result by the bit size
343 * (see <code>@link numberOfBits numberOfBits@/link</code>),
344 * so addition overflows will not necessarily
345 * be the same as for plain C integers.
347 virtual void addValue(signed long long value
);
354 * Replaces the current internal integer value
355 * of the OSNumber object by the value given.
357 * @param value The new value for the OSNumber object,
358 * which is truncated by the bit size of the OSNumber object
359 * (see <code>@link numberOfBits numberOfBits@/link</code>).
361 virtual void setValue(unsigned long long value
);
365 * @function isEqualTo
368 * Tests the equality of two OSNumber objects.
370 * @param aNumber The OSNumber to be compared against the receiver.
373 * <code>true</code> if the OSNumber objects are equal,
374 * <code>false</code> if not.
377 * Two OSNumber objects are considered equal
378 * if they represent the same C integer value.
380 virtual bool isEqualTo(const OSNumber
* aNumber
) const;
384 * @function isEqualTo
387 * Tests the equality an OSNumber to an arbitrary object.
389 * @param anObject An object to be compared against the receiver.
392 * <code>true</code> if the objects are equal,
393 * <code>false</code> if not.
396 * An OSNumber is considered equal to another object if that object is
397 * derived from OSNumber and represents the same C integer value.
399 virtual bool isEqualTo(const OSMetaClassBase
* anObject
) const;
403 * @function serialize
406 * Archives the receiver into the provided
407 * @link //apple_ref/doc/class/OSSerialize OSSerialize@/link object.
409 * @param serializer The OSSerialize object.
412 * <code>true</code> if serialization succeeds, <code>false</code> if not.
414 virtual bool serialize(OSSerialize
* serializer
) const;
417 OSMetaClassDeclareReservedUnused(OSNumber
, 0);
418 OSMetaClassDeclareReservedUnused(OSNumber
, 1);
419 OSMetaClassDeclareReservedUnused(OSNumber
, 2);
420 OSMetaClassDeclareReservedUnused(OSNumber
, 3);
421 OSMetaClassDeclareReservedUnused(OSNumber
, 4);
422 OSMetaClassDeclareReservedUnused(OSNumber
, 5);
423 OSMetaClassDeclareReservedUnused(OSNumber
, 6);
424 OSMetaClassDeclareReservedUnused(OSNumber
, 7);
427 #endif /* !_OS_OSNUMBER_H */