]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/c++/OSData.h
b306a247ab8ddac770b0160e530b7504dc69ca8a
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
25 /* IOData.h created by rsulack on Wed 17-Sep-1997 */
26 /* IOData.h converted to C++ by gvdl on Fri 1998-10-30 */
31 #include <libkern/c++/OSObject.h>
37 @abstract A container class to manage an array of bytes.
39 class OSData
: public OSObject
41 OSDeclareDefaultStructors(OSData
)
46 unsigned int capacity
;
47 unsigned int capacityIncrement
;
49 struct ExpansionData
{ };
52 Reserved for future use. (Internal use only) */
53 ExpansionData
*reserved
;
57 @function withCapacity
58 @abstract A static constructor function to create and initialize an empty instance of OSData with a given capacity.
59 @param inCapacity The initial capacity of the OSData object in bytes.
60 @result Returns an instance of OSData or 0 if a failure occurs.
62 static OSData
*withCapacity(unsigned int inCapacity
);
65 @abstract A static constructor function to create and initialize an instance of OSData and copies in the provided data.
66 @param bytes A buffer of data.
67 @param inLength The size of the given buffer.
68 @result Returns an instance of OSData or 0 if a failure occurs.
70 static OSData
*withBytes(const void *bytes
, unsigned int inLength
);
72 @function withBytesNoCopy
73 @abstract A static constructor function to create and initialize an instance of OSData which references a buffer of data.
74 @param bytes A reference to a block of data.
75 @param inLength The size of the data block.
76 @result Returns an instance of OSData or 0 if a failure occurs.
78 static OSData
*withBytesNoCopy(void *bytes
, unsigned int inLength
);
81 @abstract A static constructor function to create and initialize an instance of OSData with the data provided.
82 @param inData An OSData object which provides the initial data.
83 @result Returns an instance of OSData or 0 if a failure occurs.
85 static OSData
*withData(const OSData
*inData
);
88 @abstract A static constructor function to create and initialize an instance of OSData with a specific range of the data provided.
89 @param inData An OSData object which provides the initial data.
90 @param start The starting index at which the data will be copied.
91 @param inLength The number of bytes to be copied starting at index 'start'.
92 @result Returns an instance of OSData or 0 if a failure occurs.
94 static OSData
*withData(const OSData
*inData
,
95 unsigned int start
, unsigned int inLength
);
98 @function initWithBytes
99 @abstract A member function to initialize an instance of OSData with the provided data.
100 @param bytes A pointer to a block of data to be copied.
101 @param inLength The length of the block of data.
102 @result Returns true if initialization was successful, false otherwise.
104 virtual bool initWithCapacity(unsigned int inCapacity
);
106 @function initWithBytes
107 @abstract A member function to initialize an instance of OSData which references a block of data.
108 @param bytes A reference to a block of data
109 @param inLength The length of the block of data.
110 @result Returns true if initialization was successful, false otherwise.
112 virtual bool initWithBytes(const void *bytes
, unsigned int inLength
);
114 @function initWithBytes
115 @abstract A member function to initialize an instance of OSData which references a block of data.
116 @param bytes A reference to a block of data
117 @param inLength The length of the block of data.
118 @result Returns true if initialization was successful, false otherwise.
120 virtual bool initWithBytesNoCopy(void *bytes
, unsigned int inLength
);
122 @function initWithData
123 @abstract A member function to initialize an instance of OSData with the data provided.
124 @param inData An OSData object which provides the data to be copied.
125 @result Returns true if initialization was successful, false otherwise.
127 virtual bool initWithData(const OSData
*inData
);
129 @function initWithData
130 @abstract A member function to initialize an instance of OSData with a specific range of the data provided
131 @param inData An OSData object.
132 @param start The starting range of data to be copied.
133 @param inLength The length in bytes of the data to be copied.
134 @result Returns true if initialization was successful, false otherwise.
136 virtual bool initWithData(const OSData
*inData
,
137 unsigned int start
, unsigned int inLength
);
140 @abstract A member function which releases all resources created or used by the OSData object.
141 @discussion Do not call this function directly, use release() instead.
147 @abstract A member function which returns the length of the internal data buffer.
148 @result Returns an integer value for the length of data in the object's internal data buffer.
150 virtual unsigned int getLength() const;
152 @function getCapacity
153 @abstract A member function which returns the capacity of the internal data buffer.
154 @result Returns an integer value for the size of the object's internal data buffer.
156 virtual unsigned int getCapacity() const;
158 @function getCapacityIncrement
159 @abstract A member function which returns the size by which the data buffer will grow.
160 @result Returns the size by which the data buffer will grow.
162 virtual unsigned int getCapacityIncrement() const;
164 @function setCapacityIncrement
165 @abstract A member function which sets the growth size of the data buffer.
166 @result Returns the new growth size.
168 virtual unsigned int setCapacityIncrement(unsigned increment
);
170 @function ensureCapacity
171 @abstract A member function which will expand the size of the collection to a given storage capacity.
172 @param newCapacity The new capacity for the data buffer.
173 @result Returns the new capacity of the data buffer or the previous capacity upon error.
175 virtual unsigned int ensureCapacity(unsigned int newCapacity
);
177 @function appendBytes
178 @abstract A member function which appends a buffer of data onto the end of the object's internal data buffer.
179 @param bytes A pointer to the block of data.
180 @param inLength The length of the data block.
181 @result Returns true if the object was able to append the new data, false otherwise.
183 virtual bool appendBytes(const void *bytes
, unsigned int inLength
);
185 @function appendBytes
186 @abstract A member function which appends the data contained in an OSData object to the receiver.
187 @param other An OSData object.
188 @result Returns true if appending the new data was successful, false otherwise.
190 virtual bool appendBytes(const OSData
*other
);
193 @function getBytesNoCopy
194 @abstract A member function to return a pointer to the OSData object's internal data buffer.
195 @result Returns a reference to the OSData object's internal data buffer.
197 virtual const void *getBytesNoCopy() const;
199 @function getBytesNoCopy
200 @abstract Returns a reference into the OSData object's internal data buffer at particular offset and with a particular length.
201 @param start The offset from the base of the internal data buffer.
202 @param inLength The length of window.
203 @result Returns a pointer at a particular offset into the data buffer, or 0 if the starting offset or length are not valid.
205 virtual const void *getBytesNoCopy(unsigned int start
,
206 unsigned int inLength
) const;
210 @abstract A member function to test the equality of two OSData objects.
211 @param aData The OSData object to be compared to the receiver.
212 @result Returns true if the two objects are equivalent, false otherwise.
214 virtual bool isEqualTo(const OSData
*aData
) const;
217 @abstract A member function to test the equality of an arbitrary block of data with the OSData object's internal data buffer.
218 @param someData A pointer to a block of data.
219 @param inLength The length of the block of data.
220 @result Returns true if the two blocks of data are equivalent, false otherwise.
222 virtual bool isEqualTo(const void *someData
, unsigned int inLength
) const;
225 @abstract A member function to test the equality between an OSData object and an arbitrary OSObject derived object.
226 @param obj An OSObject derived object.
227 @result Returns true if the two objects are equivalent.
229 virtual bool isEqualTo(const OSMetaClassBase
*obj
) const;
232 @abstract A member function to test the equality between an OSData object and an OSString object.
233 @param obj An OSString object
234 @result Returns true if the two objects are equivalent.
236 virtual bool isEqualTo(const OSString
*obj
) const;
239 @abstract A member function which archives the receiver.
240 @param s The OSSerialize object.
241 @result Returns true if serialization was successful, false if not.
243 virtual bool serialize(OSSerialize
*s
) const;
247 @abstract A member function which appends a buffer of constant data onto the end of the object's internal data buffer.
248 @param byte A byte value to replicate as the added data.
249 @param inCount The length of the data to add.
250 @result Returns true if the object was able to append the new data, false otherwise.
252 virtual bool appendByte(unsigned char byte
, unsigned int inCount
);
255 OSMetaClassDeclareReservedUnused(OSData
, 0);
256 OSMetaClassDeclareReservedUnused(OSData
, 1);
257 OSMetaClassDeclareReservedUnused(OSData
, 2);
258 OSMetaClassDeclareReservedUnused(OSData
, 3);
259 OSMetaClassDeclareReservedUnused(OSData
, 4);
260 OSMetaClassDeclareReservedUnused(OSData
, 5);
261 OSMetaClassDeclareReservedUnused(OSData
, 6);
262 OSMetaClassDeclareReservedUnused(OSData
, 7);
265 #endif /* !_OS_OSDATA_H */