]> git.saurik.com Git - apple/xnu.git/blame - libkern/libkern/c++/OSNumber.h
xnu-792.6.61.tar.gz
[apple/xnu.git] / libkern / libkern / c++ / OSNumber.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
37839358
A
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.
1c79356b 11 *
37839358
A
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
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
37839358
A
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.
1c79356b
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/* IOOffset.h created by rsulack on Wed 17-Sep-1997 */
23/* IOOffset.h converted to C++ by gvdl on Fri 1998-10-30 */
24
25#ifndef _OS_OSNUMBER_H
26#define _OS_OSNUMBER_H
27
28#include <libkern/c++/OSObject.h>
29
30/*!
31 @class OSNumber
32 @abstract A container class for numeric values.
33*/
34class OSNumber : public OSObject
35{
36 OSDeclareDefaultStructors(OSNumber)
37
38protected:
39 unsigned long long value;
40 unsigned int size;
41
42 struct ExpansionData { };
43
44 /*! @var reserved
45 Reserved for future use. (Internal use only) */
46 ExpansionData *reserved;
47
48public:
49 /*!
50 @function withNumber
51 @abstract A static constructor function to create and initialize an instance of OSNumber with a given value.
52 @param value The numeric integer value.
53 @param numberOfBits The number of bit required to represent the value.
54 @result Returns an instance of OSNumber or 0 if an error occurred.
55 */
56 static OSNumber *withNumber(unsigned long long value,
57 unsigned int numberOfBits);
58 /*!
59 @function withNumber
60 @abstract A static constructor function to create and initialize an instance of OSNumber with a given value represented as a simple c-string.
91447636 61 @discussion This function does not work on IOKit versions prior to 8.0 (prior to 10.4). For IOKit version 8.0 and later, it works but is limited to parsing unsigned 32 bit quantities The format of the c-string may be decimal, hexadecimal ("0x" prefix), binary ("0b" prefix, or octal ("0" prefix).
1c79356b
A
62 @param value A c-string representing a numeric value.
63 @param numberOfBits The number of bit required to represent the value.
64 @result Returns an instance of OSNumber or 0 if an error occurred.
65 */
66 static OSNumber *withNumber(const char *value, unsigned int numberOfBits);
67
68 /*!
69 @function init
70 @abstract A member function to initialize an instance of OSNumber.
71 @param value An integer value.
72 @param numberOfBits The number of bit required to represent the value.
73 @result Returns true if instance was successfully initialized, false otherwise.
74 */
75 virtual bool init(unsigned long long value, unsigned int numberOfBits);
76 /*!
77 @function init
78 @abstract A member function to initialize an instance of OSNumber.
79 @param value A c-string representation of a numeric value.
80 @param numberOfBits The number of bit required to represent the value.
81 @result Returns true if instance was successfully initialized, false otherwise.
82 */
83 virtual bool init(const char *value, unsigned int numberOfBits);
84 /*!
85 @function free
86 @abstract Releases and deallocates resources created by the OSNumber instances.
87 @discussion This function should not be called directly, use release() instead.
88 */
89 virtual void free();
90
91 /*!
92 @function numberOfBits
93 @abstract A member function which returns the number of bits used to represent the value.
94 @result Returns the number of bits required to represent the value.
95 */
96 virtual unsigned int numberOfBits() const;
97 /*!
98 @function numberOfBytes
99 @abstract A member function which returns the number of bytes used to represent the value.
100 @result Returns the number of bytes required to represent the value.
101 */
102 virtual unsigned int numberOfBytes() const;
103
104 /*!
105 @function unsigned8BitValue
106 @abstract A member function which returns its internal value as an 8-bit value.
107 @result Returns the internal value as an 8-bit value.
108 */
109 virtual unsigned char unsigned8BitValue() const;
110 /*!
111 @function unsigned16BitValue
112 @abstract A member function which returns its internal value as an 16-bit value.
113 @result Returns the internal value as an 16-bit value.
114 */
115 virtual unsigned short unsigned16BitValue() const;
116 /*!
117 @function unsigned32BitValue
118 @abstract A member function which returns its internal value as an 32-bit value.
119 @result Returns the internal value as an 32-bit value.
120 */
121 virtual unsigned int unsigned32BitValue() const;
122 /*!
123 @function unsigned64BitValue
124 @abstract A member function which returns its internal value as an 64-bit value.
125 @result Returns the internal value as an 64-bit value.
126 */
127 virtual unsigned long long unsigned64BitValue() const;
128
129 /*!
130 @function addValue
131 @abstract A member function which adds an integer value to the internal numeric value of the OSNumber object.
132 @param value The value to be added.
133 */
134 virtual void addValue(signed long long value);
135 /*!
136 @function setValue
137 @abstract Replaces the current internal numeric value of the OSNumber object by the value given.
138 @param value The new value for the OSNumber object.
139 */
140 virtual void setValue(unsigned long long value);
141
142 /*!
143 @function isEqualTo
144 @abstract A member function to test the equality of two OSNumber objects.
145 @param integer The OSNumber object to be compared against the receiver.
146 @result Returns true if the two objects are equivalent, false otherwise.
147 */
148 virtual bool isEqualTo(const OSNumber *integer) const;
149 /*!
150 @function isEqualTo
151 @abstract A member function to test the equality of an arbitrary OSObject derived object and an OSNumber object.
152 @param obj The OSObject derived object to be compared to the receiver.
153 @result Returns true if the two objects are equivalent, false otherwise.
154 */
155 virtual bool isEqualTo(const OSMetaClassBase *obj) const;
156
157 /*!
158 @function serialize
159 @abstract A member function which archives the receiver.
160 @param s The OSSerialize object.
161 @result Returns true if serialization was successful, false if not.
162 */
163 virtual bool serialize(OSSerialize *s) const;
164
165
166 OSMetaClassDeclareReservedUnused(OSNumber, 0);
167 OSMetaClassDeclareReservedUnused(OSNumber, 1);
168 OSMetaClassDeclareReservedUnused(OSNumber, 2);
169 OSMetaClassDeclareReservedUnused(OSNumber, 3);
170 OSMetaClassDeclareReservedUnused(OSNumber, 4);
171 OSMetaClassDeclareReservedUnused(OSNumber, 5);
172 OSMetaClassDeclareReservedUnused(OSNumber, 6);
173 OSMetaClassDeclareReservedUnused(OSNumber, 7);
174};
175
176#endif /* !_OS_OSNUMBER_H */