]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/c++/OSData.h
e699dff1d53ea5a9a91096640eb4cef1048d53d1
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 /* IOData.h created by rsulack on Wed 17-Sep-1997 */
29 /* IOData.h converted to C++ by gvdl on Fri 1998-10-30 */
34 #include <libkern/c++/OSObject.h>
40 @abstract A container class to manage an array of bytes.
42 class OSData
: public OSObject
44 OSDeclareDefaultStructors ( OSData
)
49 unsigned int capacity
;
50 unsigned int capacityIncrement
;
52 struct ExpansionData
{ };
55 Reserved for future use. (Internal use only) */
56 ExpansionData
* reserved
;
60 @function withCapacity
61 @abstract A static constructor function to create and initialize an empty instance of OSData with a given capacity.
62 @param inCapacity The initial capacity of the OSData object in bytes.
63 @result Returns an instance of OSData or 0 if a failure occurs.
65 static OSData
* withCapacity ( unsigned int inCapacity
);
68 @abstract A static constructor function to create and initialize an instance of OSData and copies in the provided data.
69 @param bytes A buffer of data.
70 @param inLength The size of the given buffer.
71 @result Returns an instance of OSData or 0 if a failure occurs.
73 static OSData
* withBytes ( const void * bytes
, unsigned int inLength
);
75 @function withBytesNoCopy
76 @abstract A static constructor function to create and initialize an instance of OSData which references a buffer of data.
77 @param bytes A reference to a block of data.
78 @param inLength The size of the data block.
79 @result Returns an instance of OSData or 0 if a failure occurs.
81 static OSData
* withBytesNoCopy ( void * bytes
, unsigned int inLength
);
84 @abstract A static constructor function to create and initialize an instance of OSData with the data provided.
85 @param inData An OSData object which provides the initial data.
86 @result Returns an instance of OSData or 0 if a failure occurs.
88 static OSData
* withData ( const OSData
* inData
);
91 @abstract A static constructor function to create and initialize an instance of OSData with a specific range of the data provided.
92 @param inData An OSData object which provides the initial data.
93 @param start The starting index at which the data will be copied.
94 @param inLength The number of bytes to be copied starting at index 'start'.
95 @result Returns an instance of OSData or 0 if a failure occurs.
97 static OSData
* withData ( const OSData
* inData
,
98 unsigned int start
, unsigned int inLength
);
101 @function initWithCapacity
102 @abstract A member function to initialize an instance of OSData with a minimum capacity of at least the given size. If this function is called an an object that has been previously used then the length is set down to 0 and a new block of data is allocated if necessary to ensure the given capacity.
103 @param capacity The length of the allocated block of data.
104 @result Returns true if initialization was successful, false otherwise.
106 virtual bool initWithCapacity ( unsigned int capacity
);
108 @function initWithBytes
109 @abstract A member function to initialize an instance of OSData which references a block of data.
110 @param bytes A reference to a block of data
111 @param inLength The length of the block of data.
112 @result Returns true if initialization was successful, false otherwise.
114 virtual bool initWithBytes ( const void * bytes
, unsigned int inLength
);
116 @function initWithBytes
117 @abstract A member function to initialize an instance of OSData which references a block of data.
118 @param bytes A reference to a block of data
119 @param inLength The length of the block of data.
120 @result Returns true if initialization was successful, false otherwise.
122 virtual bool initWithBytesNoCopy ( void * bytes
, unsigned int inLength
);
124 @function initWithData
125 @abstract A member function to initialize an instance of OSData with the data provided.
126 @param inData An OSData object which provides the data to be copied.
127 @result Returns true if initialization was successful, false otherwise.
129 virtual bool initWithData ( const OSData
* inData
);
131 @function initWithData
132 @abstract A member function to initialize an instance of OSData with a specific range of the data provided
133 @param inData An OSData object.
134 @param start The starting range of data to be copied.
135 @param inLength The length in bytes of the data to be copied.
136 @result Returns true if initialization was successful, false otherwise.
138 virtual bool initWithData ( const OSData
* inData
,
139 unsigned int start
, unsigned int inLength
);
142 @abstract A member function which releases all resources created or used by the OSData object.
143 @discussion Do not call this function directly, use release() instead.
149 @abstract A member function which returns the length of the internal data buffer.
150 @result Returns an integer value for the length of data in the object's internal data buffer.
152 virtual unsigned int getLength () const ;
154 @function getCapacity
155 @abstract A member function which returns the capacity of the internal data buffer.
156 @result Returns an integer value for the size of the object's internal data buffer.
158 virtual unsigned int getCapacity () const ;
160 @function getCapacityIncrement
161 @abstract A member function which returns the size by which the data buffer will grow.
162 @result Returns the size by which the data buffer will grow.
164 virtual unsigned int getCapacityIncrement () const ;
166 @function setCapacityIncrement
167 @abstract A member function which sets the growth size of the data buffer.
168 @result Returns the new growth size.
170 virtual unsigned int setCapacityIncrement ( unsigned increment
);
172 @function ensureCapacity
173 @abstract A member function which will expand the size of the collection to a given storage capacity.
174 @param newCapacity The new capacity for the data buffer.
175 @result Returns the new capacity of the data buffer or the previous capacity upon error.
177 virtual unsigned int ensureCapacity ( unsigned int newCapacity
);
179 @function appendBytes
180 @abstract A member function which appends a buffer of data onto the end of the object's internal data buffer.
181 @param bytes A pointer to the block of data. If the value is 0 then append zero-ed memory to the data object.
182 @param inLength The length of the data block.
183 @result Returns true if the object was able to append the new data, false otherwise.
185 virtual bool appendBytes ( const void * bytes
, unsigned int inLength
);
187 @function appendBytes
188 @abstract A member function which appends the data contained in an OSData object to the receiver.
189 @param other An OSData object.
190 @result Returns true if appending the new data was successful, false otherwise.
192 virtual bool appendBytes ( const OSData
* other
);
195 @function getBytesNoCopy
196 @abstract A member function to return a pointer to the OSData object's internal data buffer.
197 @result Returns a reference to the OSData object's internal data buffer.
199 virtual const void * getBytesNoCopy () const ;
201 @function getBytesNoCopy
202 @abstract Returns a reference into the OSData object's internal data buffer at particular offset and with a particular length.
203 @param start The offset from the base of the internal data buffer.
204 @param inLength The length of window.
205 @result Returns a pointer at a particular offset into the data buffer, or 0 if the starting offset or length are not valid.
207 virtual const void * getBytesNoCopy ( unsigned int start
,
208 unsigned int inLength
) const ;
212 @abstract A member function to test the equality of two OSData objects.
213 @param aData The OSData object to be compared to the receiver.
214 @result Returns true if the two objects are equivalent, false otherwise.
216 virtual bool isEqualTo ( const OSData
* aData
) const ;
219 @abstract A member function to test the equality of an arbitrary block of data with the OSData object's internal data buffer.
220 @param someData A pointer to a block of data.
221 @param inLength The length of the block of data.
222 @result Returns true if the two blocks of data are equivalent, false otherwise.
224 virtual bool isEqualTo ( const void * someData
, unsigned int inLength
) const ;
227 @abstract A member function to test the equality between an OSData object and an arbitrary OSObject derived object.
228 @param obj An OSObject derived object.
229 @result Returns true if the two objects are equivalent.
231 virtual bool isEqualTo ( const OSMetaClassBase
* obj
) const ;
234 @abstract A member function to test the equality between an OSData object and an OSString object.
235 @param obj An OSString object
236 @result Returns true if the two objects are equivalent.
238 virtual bool isEqualTo ( const OSString
* obj
) const ;
241 @abstract A member function which archives the receiver.
242 @param s The OSSerialize object.
243 @result Returns true if serialization was successful, false if not.
245 virtual bool serialize ( OSSerialize
* s
) const ;
249 @abstract A member function which appends a buffer of constant data onto the end of the object's internal data buffer.
250 @param byte A byte value to replicate as the added data.
251 @param inCount The length of the data to add.
252 @result Returns true if the object was able to append the new data, false otherwise.
254 virtual bool appendByte ( unsigned char byte
, unsigned int inCount
);
259 OSMetaClassDeclareReservedUnused ( OSData
, 0 );
260 OSMetaClassDeclareReservedUnused ( OSData
, 1 );
261 OSMetaClassDeclareReservedUnused ( OSData
, 2 );
262 OSMetaClassDeclareReservedUnused ( OSData
, 3 );
263 OSMetaClassDeclareReservedUnused ( OSData
, 4 );
264 OSMetaClassDeclareReservedUnused ( OSData
, 5 );
265 OSMetaClassDeclareReservedUnused ( OSData
, 6 );
266 OSMetaClassDeclareReservedUnused ( OSData
, 7 );
269 #endif /* !_OS_OSDATA_H */