]> git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/c++/OSNumber.h
aa32d0fcb76b25c3020f9594eab7170ebd6fbcb3
[apple/xnu.git] / libkern / libkern / c++ / OSNumber.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 /* 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 */
34 class OSNumber : public OSObject
35 {
36 OSDeclareDefaultStructors(OSNumber)
37
38 protected:
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
48 public:
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.
61 @param value A c-string representing a numeric value.
62 @param numberOfBits The number of bit required to represent the value.
63 @result Returns an instance of OSNumber or 0 if an error occurred.
64 */
65 static OSNumber *withNumber(const char *value, unsigned int numberOfBits);
66
67 /*!
68 @function init
69 @abstract A member function to initialize an instance of OSNumber.
70 @param value An integer value.
71 @param numberOfBits The number of bit required to represent the value.
72 @result Returns true if instance was successfully initialized, false otherwise.
73 */
74 virtual bool init(unsigned long long value, unsigned int numberOfBits);
75 /*!
76 @function init
77 @abstract A member function to initialize an instance of OSNumber.
78 @param value A c-string representation of a numeric value.
79 @param numberOfBits The number of bit required to represent the value.
80 @result Returns true if instance was successfully initialized, false otherwise.
81 */
82 virtual bool init(const char *value, unsigned int numberOfBits);
83 /*!
84 @function free
85 @abstract Releases and deallocates resources created by the OSNumber instances.
86 @discussion This function should not be called directly, use release() instead.
87 */
88 virtual void free();
89
90 /*!
91 @function numberOfBits
92 @abstract A member function which returns the number of bits used to represent the value.
93 @result Returns the number of bits required to represent the value.
94 */
95 virtual unsigned int numberOfBits() const;
96 /*!
97 @function numberOfBytes
98 @abstract A member function which returns the number of bytes used to represent the value.
99 @result Returns the number of bytes required to represent the value.
100 */
101 virtual unsigned int numberOfBytes() const;
102
103 /*!
104 @function unsigned8BitValue
105 @abstract A member function which returns its internal value as an 8-bit value.
106 @result Returns the internal value as an 8-bit value.
107 */
108 virtual unsigned char unsigned8BitValue() const;
109 /*!
110 @function unsigned16BitValue
111 @abstract A member function which returns its internal value as an 16-bit value.
112 @result Returns the internal value as an 16-bit value.
113 */
114 virtual unsigned short unsigned16BitValue() const;
115 /*!
116 @function unsigned32BitValue
117 @abstract A member function which returns its internal value as an 32-bit value.
118 @result Returns the internal value as an 32-bit value.
119 */
120 virtual unsigned int unsigned32BitValue() const;
121 /*!
122 @function unsigned64BitValue
123 @abstract A member function which returns its internal value as an 64-bit value.
124 @result Returns the internal value as an 64-bit value.
125 */
126 virtual unsigned long long unsigned64BitValue() const;
127
128 /*!
129 @function addValue
130 @abstract A member function which adds an integer value to the internal numeric value of the OSNumber object.
131 @param value The value to be added.
132 */
133 virtual void addValue(signed long long value);
134 /*!
135 @function setValue
136 @abstract Replaces the current internal numeric value of the OSNumber object by the value given.
137 @param value The new value for the OSNumber object.
138 */
139 virtual void setValue(unsigned long long value);
140
141 /*!
142 @function isEqualTo
143 @abstract A member function to test the equality of two OSNumber objects.
144 @param integer The OSNumber object to be compared against the receiver.
145 @result Returns true if the two objects are equivalent, false otherwise.
146 */
147 virtual bool isEqualTo(const OSNumber *integer) const;
148 /*!
149 @function isEqualTo
150 @abstract A member function to test the equality of an arbitrary OSObject derived object and an OSNumber object.
151 @param obj The OSObject derived object to be compared to the receiver.
152 @result Returns true if the two objects are equivalent, false otherwise.
153 */
154 virtual bool isEqualTo(const OSMetaClassBase *obj) const;
155
156 /*!
157 @function serialize
158 @abstract A member function which archives the receiver.
159 @param s The OSSerialize object.
160 @result Returns true if serialization was successful, false if not.
161 */
162 virtual bool serialize(OSSerialize *s) const;
163
164
165 OSMetaClassDeclareReservedUnused(OSNumber, 0);
166 OSMetaClassDeclareReservedUnused(OSNumber, 1);
167 OSMetaClassDeclareReservedUnused(OSNumber, 2);
168 OSMetaClassDeclareReservedUnused(OSNumber, 3);
169 OSMetaClassDeclareReservedUnused(OSNumber, 4);
170 OSMetaClassDeclareReservedUnused(OSNumber, 5);
171 OSMetaClassDeclareReservedUnused(OSNumber, 6);
172 OSMetaClassDeclareReservedUnused(OSNumber, 7);
173 };
174
175 #endif /* !_OS_OSNUMBER_H */