]> git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/c++/OSNumber.h
5eb6fa7ed554af25b239ef67cdb5d04ade02b127
[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 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /* IOOffset.h created by rsulack on Wed 17-Sep-1997 */
26 /* IOOffset.h converted to C++ by gvdl on Fri 1998-10-30 */
27
28 #ifndef _OS_OSNUMBER_H
29 #define _OS_OSNUMBER_H
30
31 #include <libkern/c++/OSObject.h>
32
33 /*!
34 @class OSNumber
35 @abstract A container class for numeric values.
36 */
37 class OSNumber : public OSObject
38 {
39 OSDeclareDefaultStructors(OSNumber)
40
41 protected:
42 unsigned long long value;
43 unsigned int size;
44
45 struct ExpansionData { };
46
47 /*! @var reserved
48 Reserved for future use. (Internal use only) */
49 ExpansionData *reserved;
50
51 public:
52 /*!
53 @function withNumber
54 @abstract A static constructor function to create and initialize an instance of OSNumber with a given value.
55 @param value The numeric integer value.
56 @param numberOfBits The number of bit required to represent the value.
57 @result Returns an instance of OSNumber or 0 if an error occurred.
58 */
59 static OSNumber *withNumber(unsigned long long value,
60 unsigned int numberOfBits);
61 /*!
62 @function withNumber
63 @abstract A static constructor function to create and initialize an instance of OSNumber with a given value represented as a simple c-string.
64 @param value A c-string representing a numeric value.
65 @param numberOfBits The number of bit required to represent the value.
66 @result Returns an instance of OSNumber or 0 if an error occurred.
67 */
68 static OSNumber *withNumber(const char *value, unsigned int numberOfBits);
69
70 /*!
71 @function init
72 @abstract A member function to initialize an instance of OSNumber.
73 @param value An integer value.
74 @param numberOfBits The number of bit required to represent the value.
75 @result Returns true if instance was successfully initialized, false otherwise.
76 */
77 virtual bool init(unsigned long long value, unsigned int numberOfBits);
78 /*!
79 @function init
80 @abstract A member function to initialize an instance of OSNumber.
81 @param value A c-string representation of a numeric value.
82 @param numberOfBits The number of bit required to represent the value.
83 @result Returns true if instance was successfully initialized, false otherwise.
84 */
85 virtual bool init(const char *value, unsigned int numberOfBits);
86 /*!
87 @function free
88 @abstract Releases and deallocates resources created by the OSNumber instances.
89 @discussion This function should not be called directly, use release() instead.
90 */
91 virtual void free();
92
93 /*!
94 @function numberOfBits
95 @abstract A member function which returns the number of bits used to represent the value.
96 @result Returns the number of bits required to represent the value.
97 */
98 virtual unsigned int numberOfBits() const;
99 /*!
100 @function numberOfBytes
101 @abstract A member function which returns the number of bytes used to represent the value.
102 @result Returns the number of bytes required to represent the value.
103 */
104 virtual unsigned int numberOfBytes() const;
105
106 /*!
107 @function unsigned8BitValue
108 @abstract A member function which returns its internal value as an 8-bit value.
109 @result Returns the internal value as an 8-bit value.
110 */
111 virtual unsigned char unsigned8BitValue() const;
112 /*!
113 @function unsigned16BitValue
114 @abstract A member function which returns its internal value as an 16-bit value.
115 @result Returns the internal value as an 16-bit value.
116 */
117 virtual unsigned short unsigned16BitValue() const;
118 /*!
119 @function unsigned32BitValue
120 @abstract A member function which returns its internal value as an 32-bit value.
121 @result Returns the internal value as an 32-bit value.
122 */
123 virtual unsigned int unsigned32BitValue() const;
124 /*!
125 @function unsigned64BitValue
126 @abstract A member function which returns its internal value as an 64-bit value.
127 @result Returns the internal value as an 64-bit value.
128 */
129 virtual unsigned long long unsigned64BitValue() const;
130
131 /*!
132 @function addValue
133 @abstract A member function which adds an integer value to the internal numeric value of the OSNumber object.
134 @param value The value to be added.
135 */
136 virtual void addValue(signed long long value);
137 /*!
138 @function setValue
139 @abstract Replaces the current internal numeric value of the OSNumber object by the value given.
140 @param value The new value for the OSNumber object.
141 */
142 virtual void setValue(unsigned long long value);
143
144 /*!
145 @function isEqualTo
146 @abstract A member function to test the equality of two OSNumber objects.
147 @param integer The OSNumber object to be compared against the receiver.
148 @result Returns true if the two objects are equivalent, false otherwise.
149 */
150 virtual bool isEqualTo(const OSNumber *integer) const;
151 /*!
152 @function isEqualTo
153 @abstract A member function to test the equality of an arbitrary OSObject derived object and an OSNumber object.
154 @param obj The OSObject derived object to be compared to the receiver.
155 @result Returns true if the two objects are equivalent, false otherwise.
156 */
157 virtual bool isEqualTo(const OSMetaClassBase *obj) const;
158
159 /*!
160 @function serialize
161 @abstract A member function which archives the receiver.
162 @param s The OSSerialize object.
163 @result Returns true if serialization was successful, false if not.
164 */
165 virtual bool serialize(OSSerialize *s) const;
166
167
168 OSMetaClassDeclareReservedUnused(OSNumber, 0);
169 OSMetaClassDeclareReservedUnused(OSNumber, 1);
170 OSMetaClassDeclareReservedUnused(OSNumber, 2);
171 OSMetaClassDeclareReservedUnused(OSNumber, 3);
172 OSMetaClassDeclareReservedUnused(OSNumber, 4);
173 OSMetaClassDeclareReservedUnused(OSNumber, 5);
174 OSMetaClassDeclareReservedUnused(OSNumber, 6);
175 OSMetaClassDeclareReservedUnused(OSNumber, 7);
176 };
177
178 #endif /* !_OS_OSNUMBER_H */