]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/c++/OSData.h
33b8259af02e712437bb1f5c7464a3195b9b2a51
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
22 /* IOData.h created by rsulack on Wed 17-Sep-1997 */
23 /* IOData.h converted to C++ by gvdl on Fri 1998-10-30 */
28 #include <libkern/c++/OSObject.h>
34 @abstract A container class to manage an array of bytes.
36 class OSData
: public OSObject
38 OSDeclareDefaultStructors ( OSData
)
43 unsigned int capacity
;
44 unsigned int capacityIncrement
;
46 struct ExpansionData
{ };
49 Reserved for future use. (Internal use only) */
50 ExpansionData
* reserved
;
54 @function withCapacity
55 @abstract A static constructor function to create and initialize an empty instance of OSData with a given capacity.
56 @param inCapacity The initial capacity of the OSData object in bytes.
57 @result Returns an instance of OSData or 0 if a failure occurs.
59 static OSData
* withCapacity ( unsigned int inCapacity
);
62 @abstract A static constructor function to create and initialize an instance of OSData and copies in the provided data.
63 @param bytes A buffer of data.
64 @param inLength The size of the given buffer.
65 @result Returns an instance of OSData or 0 if a failure occurs.
67 static OSData
* withBytes ( const void * bytes
, unsigned int inLength
);
69 @function withBytesNoCopy
70 @abstract A static constructor function to create and initialize an instance of OSData which references a buffer of data.
71 @param bytes A reference to a block of data.
72 @param inLength The size of the data block.
73 @result Returns an instance of OSData or 0 if a failure occurs.
75 static OSData
* withBytesNoCopy ( void * bytes
, unsigned int inLength
);
78 @abstract A static constructor function to create and initialize an instance of OSData with the data provided.
79 @param inData An OSData object which provides the initial data.
80 @result Returns an instance of OSData or 0 if a failure occurs.
82 static OSData
* withData ( const OSData
* inData
);
85 @abstract A static constructor function to create and initialize an instance of OSData with a specific range of the data provided.
86 @param inData An OSData object which provides the initial data.
87 @param start The starting index at which the data will be copied.
88 @param inLength The number of bytes to be copied starting at index 'start'.
89 @result Returns an instance of OSData or 0 if a failure occurs.
91 static OSData
* withData ( const OSData
* inData
,
92 unsigned int start
, unsigned int inLength
);
95 @function initWithCapacity
96 @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.
97 @param capacity The length of the allocated block of data.
98 @result Returns true if initialization was successful, false otherwise.
100 virtual bool initWithCapacity ( unsigned int capacity
);
102 @function initWithBytes
103 @abstract A member function to initialize an instance of OSData which references a block of data.
104 @param bytes A reference to a block of data
105 @param inLength The length of the block of data.
106 @result Returns true if initialization was successful, false otherwise.
108 virtual bool initWithBytes ( const void * bytes
, unsigned int inLength
);
110 @function initWithBytes
111 @abstract A member function to initialize an instance of OSData which references a block of data.
112 @param bytes A reference to a block of data
113 @param inLength The length of the block of data.
114 @result Returns true if initialization was successful, false otherwise.
116 virtual bool initWithBytesNoCopy ( void * bytes
, unsigned int inLength
);
118 @function initWithData
119 @abstract A member function to initialize an instance of OSData with the data provided.
120 @param inData An OSData object which provides the data to be copied.
121 @result Returns true if initialization was successful, false otherwise.
123 virtual bool initWithData ( const OSData
* inData
);
125 @function initWithData
126 @abstract A member function to initialize an instance of OSData with a specific range of the data provided
127 @param inData An OSData object.
128 @param start The starting range of data to be copied.
129 @param inLength The length in bytes of the data to be copied.
130 @result Returns true if initialization was successful, false otherwise.
132 virtual bool initWithData ( const OSData
* inData
,
133 unsigned int start
, unsigned int inLength
);
136 @abstract A member function which releases all resources created or used by the OSData object.
137 @discussion Do not call this function directly, use release() instead.
143 @abstract A member function which returns the length of the internal data buffer.
144 @result Returns an integer value for the length of data in the object's internal data buffer.
146 virtual unsigned int getLength () const ;
148 @function getCapacity
149 @abstract A member function which returns the capacity of the internal data buffer.
150 @result Returns an integer value for the size of the object's internal data buffer.
152 virtual unsigned int getCapacity () const ;
154 @function getCapacityIncrement
155 @abstract A member function which returns the size by which the data buffer will grow.
156 @result Returns the size by which the data buffer will grow.
158 virtual unsigned int getCapacityIncrement () const ;
160 @function setCapacityIncrement
161 @abstract A member function which sets the growth size of the data buffer.
162 @result Returns the new growth size.
164 virtual unsigned int setCapacityIncrement ( unsigned increment
);
166 @function ensureCapacity
167 @abstract A member function which will expand the size of the collection to a given storage capacity.
168 @param newCapacity The new capacity for the data buffer.
169 @result Returns the new capacity of the data buffer or the previous capacity upon error.
171 virtual unsigned int ensureCapacity ( unsigned int newCapacity
);
173 @function appendBytes
174 @abstract A member function which appends a buffer of data onto the end of the object's internal data buffer.
175 @param bytes A pointer to the block of data. If the value is 0 then append zero-ed memory to the data object.
176 @param inLength The length of the data block.
177 @result Returns true if the object was able to append the new data, false otherwise.
179 virtual bool appendBytes ( const void * bytes
, unsigned int inLength
);
181 @function appendBytes
182 @abstract A member function which appends the data contained in an OSData object to the receiver.
183 @param other An OSData object.
184 @result Returns true if appending the new data was successful, false otherwise.
186 virtual bool appendBytes ( const OSData
* other
);
189 @function getBytesNoCopy
190 @abstract A member function to return a pointer to the OSData object's internal data buffer.
191 @result Returns a reference to the OSData object's internal data buffer.
193 virtual const void * getBytesNoCopy () const ;
195 @function getBytesNoCopy
196 @abstract Returns a reference into the OSData object's internal data buffer at particular offset and with a particular length.
197 @param start The offset from the base of the internal data buffer.
198 @param inLength The length of window.
199 @result Returns a pointer at a particular offset into the data buffer, or 0 if the starting offset or length are not valid.
201 virtual const void * getBytesNoCopy ( unsigned int start
,
202 unsigned int inLength
) const ;
206 @abstract A member function to test the equality of two OSData objects.
207 @param aData The OSData object to be compared to the receiver.
208 @result Returns true if the two objects are equivalent, false otherwise.
210 virtual bool isEqualTo ( const OSData
* aData
) const ;
213 @abstract A member function to test the equality of an arbitrary block of data with the OSData object's internal data buffer.
214 @param someData A pointer to a block of data.
215 @param inLength The length of the block of data.
216 @result Returns true if the two blocks of data are equivalent, false otherwise.
218 virtual bool isEqualTo ( const void * someData
, unsigned int inLength
) const ;
221 @abstract A member function to test the equality between an OSData object and an arbitrary OSObject derived object.
222 @param obj An OSObject derived object.
223 @result Returns true if the two objects are equivalent.
225 virtual bool isEqualTo ( const OSMetaClassBase
* obj
) const ;
228 @abstract A member function to test the equality between an OSData object and an OSString object.
229 @param obj An OSString object
230 @result Returns true if the two objects are equivalent.
232 virtual bool isEqualTo ( const OSString
* obj
) const ;
235 @abstract A member function which archives the receiver.
236 @param s The OSSerialize object.
237 @result Returns true if serialization was successful, false if not.
239 virtual bool serialize ( OSSerialize
* s
) const ;
243 @abstract A member function which appends a buffer of constant data onto the end of the object's internal data buffer.
244 @param byte A byte value to replicate as the added data.
245 @param inCount The length of the data to add.
246 @result Returns true if the object was able to append the new data, false otherwise.
248 virtual bool appendByte ( unsigned char byte
, unsigned int inCount
);
253 OSMetaClassDeclareReservedUnused ( OSData
, 0 );
254 OSMetaClassDeclareReservedUnused ( OSData
, 1 );
255 OSMetaClassDeclareReservedUnused ( OSData
, 2 );
256 OSMetaClassDeclareReservedUnused ( OSData
, 3 );
257 OSMetaClassDeclareReservedUnused ( OSData
, 4 );
258 OSMetaClassDeclareReservedUnused ( OSData
, 5 );
259 OSMetaClassDeclareReservedUnused ( OSData
, 6 );
260 OSMetaClassDeclareReservedUnused ( OSData
, 7 );
263 #endif /* !_OS_OSDATA_H */