]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/c++/OSData.h
2406be7c0d98656d0bb9e6820984f259f3295240
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 initWithBytes
96 @abstract A member function to initialize an instance of OSData with the provided data.
97 @param bytes A pointer to a block of data to be copied.
98 @param inLength The length of the block of data.
99 @result Returns true if initialization was successful, false otherwise.
101 virtual bool initWithCapacity(unsigned int inCapacity
);
103 @function initWithBytes
104 @abstract A member function to initialize an instance of OSData which references a block of data.
105 @param bytes A reference to a block of data
106 @param inLength The length of the block of data.
107 @result Returns true if initialization was successful, false otherwise.
109 virtual bool initWithBytes(const void *bytes
, unsigned int inLength
);
111 @function initWithBytes
112 @abstract A member function to initialize an instance of OSData which references a block of data.
113 @param bytes A reference to a block of data
114 @param inLength The length of the block of data.
115 @result Returns true if initialization was successful, false otherwise.
117 virtual bool initWithBytesNoCopy(void *bytes
, unsigned int inLength
);
119 @function initWithData
120 @abstract A member function to initialize an instance of OSData with the data provided.
121 @param inData An OSData object which provides the data to be copied.
122 @result Returns true if initialization was successful, false otherwise.
124 virtual bool initWithData(const OSData
*inData
);
126 @function initWithData
127 @abstract A member function to initialize an instance of OSData with a specific range of the data provided
128 @param inData An OSData object.
129 @param start The starting range of data to be copied.
130 @param inLength The length in bytes of the data to be copied.
131 @result Returns true if initialization was successful, false otherwise.
133 virtual bool initWithData(const OSData
*inData
,
134 unsigned int start
, unsigned int inLength
);
137 @abstract A member function which releases all resources created or used by the OSData object.
138 @discussion Do not call this function directly, use release() instead.
144 @abstract A member function which returns the length of the internal data buffer.
145 @result Returns an integer value for the length of data in the object's internal data buffer.
147 virtual unsigned int getLength() const;
149 @function getCapacity
150 @abstract A member function which returns the capacity of the internal data buffer.
151 @result Returns an integer value for the size of the object's internal data buffer.
153 virtual unsigned int getCapacity() const;
155 @function getCapacityIncrement
156 @abstract A member function which returns the size by which the data buffer will grow.
157 @result Returns the size by which the data buffer will grow.
159 virtual unsigned int getCapacityIncrement() const;
161 @function setCapacityIncrement
162 @abstract A member function which sets the growth size of the data buffer.
163 @result Returns the new growth size.
165 virtual unsigned int setCapacityIncrement(unsigned increment
);
167 @function ensureCapacity
168 @abstract A member function which will expand the size of the collection to a given storage capacity.
169 @param newCapacity The new capacity for the data buffer.
170 @result Returns the new capacity of the data buffer or the previous capacity upon error.
172 virtual unsigned int ensureCapacity(unsigned int newCapacity
);
174 @function appendBytes
175 @abstract A member function which appends a buffer of data onto the end of the object's internal data buffer.
176 @param bytes A pointer to the block of data.
177 @param inLength The length of the data block.
178 @result Returns true if the object was able to append the new data, false otherwise.
180 virtual bool appendBytes(const void *bytes
, unsigned int inLength
);
182 @function appendBytes
183 @abstract A member function which appends the data contained in an OSData object to the receiver.
184 @param other An OSData object.
185 @result Returns true if appending the new data was successful, false otherwise.
187 virtual bool appendBytes(const OSData
*other
);
190 @function getBytesNoCopy
191 @abstract A member function to return a pointer to the OSData object's internal data buffer.
192 @result Returns a reference to the OSData object's internal data buffer.
194 virtual const void *getBytesNoCopy() const;
196 @function getBytesNoCopy
197 @abstract Returns a reference into the OSData object's internal data buffer at particular offset and with a particular length.
198 @param start The offset from the base of the internal data buffer.
199 @param inLength The length of window.
200 @result Returns a pointer at a particular offset into the data buffer, or 0 if the starting offset or length are not valid.
202 virtual const void *getBytesNoCopy(unsigned int start
,
203 unsigned int inLength
) const;
207 @abstract A member function to test the equality of two OSData objects.
208 @param aData The OSData object to be compared to the receiver.
209 @result Returns true if the two objects are equivalent, false otherwise.
211 virtual bool isEqualTo(const OSData
*aData
) const;
214 @abstract A member function to test the equality of an arbitrary block of data with the OSData object's internal data buffer.
215 @param someData A pointer to a block of data.
216 @param inLength The length of the block of data.
217 @result Returns true if the two blocks of data are equivalent, false otherwise.
219 virtual bool isEqualTo(const void *someData
, unsigned int inLength
) const;
222 @abstract A member function to test the equality between an OSData object and an arbitrary OSObject derived object.
223 @param obj An OSObject derived object.
224 @result Returns true if the two objects are equivalent.
226 virtual bool isEqualTo(const OSMetaClassBase
*obj
) const;
229 @abstract A member function to test the equality between an OSData object and an OSString object.
230 @param obj An OSString object
231 @result Returns true if the two objects are equivalent.
233 virtual bool isEqualTo(const OSString
*obj
) const;
236 @abstract A member function which archives the receiver.
237 @param s The OSSerialize object.
238 @result Returns true if serialization was successful, false if not.
240 virtual bool serialize(OSSerialize
*s
) const;
244 @abstract A member function which appends a buffer of constant data onto the end of the object's internal data buffer.
245 @param byte A byte value to replicate as the added data.
246 @param inCount The length of the data to add.
247 @result Returns true if the object was able to append the new data, false otherwise.
249 virtual bool appendByte(unsigned char byte
, unsigned int inCount
);
252 OSMetaClassDeclareReservedUnused(OSData
, 0);
253 OSMetaClassDeclareReservedUnused(OSData
, 1);
254 OSMetaClassDeclareReservedUnused(OSData
, 2);
255 OSMetaClassDeclareReservedUnused(OSData
, 3);
256 OSMetaClassDeclareReservedUnused(OSData
, 4);
257 OSMetaClassDeclareReservedUnused(OSData
, 5);
258 OSMetaClassDeclareReservedUnused(OSData
, 6);
259 OSMetaClassDeclareReservedUnused(OSData
, 7);
262 #endif /* !_OS_OSDATA_H */