ObjFW
|
A class for storing arbitrary data in an array. More...
#import <OFDataArray.h>
Public Member Functions | |
(id) | - init |
Initializes an already allocated OFDataArray with an item size of 1. | |
(id) | - initWithItemSize: |
Initializes an already allocated OFDataArray whose items all have the same size. | |
(id) | - initWithContentsOfFile: |
Initializes an already allocated OFDataArray with an item size of 1, containing the data of the specified file. | |
(id) | - initWithContentsOfURL: |
Initializes an already allocated OFDataArray with an item size of 1, containing the data of the specified URL. | |
(id) | - initWithBase64EncodedString: |
Initializes an already allocated OFDataArray with an item size of 1, containing the data of the Base64-encoded string. | |
(size_t) | - count |
Returns the number of items in the OFDataArray. | |
(size_t) | - itemSize |
Returns the size of each item in the OFDataArray in bytes. | |
(void *) | - cArray |
Returns all elements of the OFDataArray as a C array. | |
(void *) | - itemAtIndex: |
Returns a specific item of the OFDataArray. | |
(void *) | - firstItem |
Returns the first item of the OFDataArray. | |
(void *) | - lastItem |
Returns the last item of the OFDataArray. | |
(void) | - addItem: |
Adds an item to the OFDataArray. | |
(void) | - addItem:atIndex: |
Adds an item to the OFDataArray at the specified index. | |
(void) | - addNItems:fromCArray: |
Adds items from a C array to the OFDataArray. | |
(void) | - addNItems:fromCArray:atIndex: |
Adds items from a C array to the OFDataArray at the specified index. | |
(void) | - removeItemAtIndex: |
Removes the item at the specified index. | |
(void) | - removeNItems: |
Removes the specified amount of items from the end of the OFDataArray. | |
(void) | - removeNItems:atIndex: |
Removes the specified amount of items at the specified index. | |
(void) | - removeLastItem |
Removes the last item. | |
(void) | - removeAllItems |
Removes all items. | |
(OFString *) | - stringByBase64Encoding |
Returns a string containing the data in Base64 encoding. | |
(void) | - writeToFile: |
Writes the OFDataArray into the specified file. | |
(OFString *) | - MD5Hash |
Returns the MD5 hash of the data array as an autoreleased OFString. | |
(OFString *) | - SHA1Hash |
Returns the SHA-1 hash of the data array as an autoreleased OFString. | |
Static Public Member Functions | |
(id) | + dataArray |
Creates a new OFDataArray with an item size of 1. | |
(id) | + dataArrayWithItemSize: |
Creates a new OFDataArray whose items all have the same size. | |
(id) | + dataArrayWithContentsOfFile: |
Creates a new OFDataArary with an item size of 1, containing the data of the specified file. | |
(id) | + dataArrayWithContentsOfURL: |
Creates a new OFDataArray with an item size of 1, containing the data of the specified URL. | |
(id) | + dataArrayWithBase64EncodedString: |
Creates a new OFDataArray with an item size of 1, containing the data of the Base64-encoded string. |
A class for storing arbitrary data in an array.
If you plan to store large hunks of data, you should consider using OFBigDataArray, which allocates the memory in pages rather than in bytes.
For security reasons, serialization and deserialization is only implemented for OFDataArrays with item size 1.
- (void) addItem: | (const void*) | item |
Adds an item to the OFDataArray.
item | A pointer to an arbitrary item |
- (void) addItem: | (const void*) | item | |
atIndex: | (size_t) | index | |
Adds an item to the OFDataArray at the specified index.
item | A pointer to an arbitrary item |
index | The index where the item should be added |
- (void) addNItems: | (size_t) | nItems | |
fromCArray: | (const void*) | cArray | |
Adds items from a C array to the OFDataArray.
nItems | The number of items to add |
cArray | A C array containing the items to add |
- (void) addNItems: | (size_t) | nItems | |
fromCArray: | (const void*) | cArray | |
atIndex: | (size_t) | index | |
Adds items from a C array to the OFDataArray at the specified index.
nItems | The number of items to add |
cArray | A C array containing the items to add |
index | The index where the items should be added |
- (void *) cArray |
Returns all elements of the OFDataArray as a C array.
Modifying the returned array directly is allowed and will change the contents of the data array.
- (size_t) count |
Returns the number of items in the OFDataArray.
+ (id) dataArray |
Creates a new OFDataArray with an item size of 1.
+ (id) dataArrayWithBase64EncodedString: | (OFString*) | string |
Creates a new OFDataArray with an item size of 1, containing the data of the Base64-encoded string.
string | The string with the Base64-encoded data |
+ (id) dataArrayWithContentsOfFile: | (OFString*) | path |
Creates a new OFDataArary with an item size of 1, containing the data of the specified file.
path | The path of the file |
+ (id) dataArrayWithContentsOfURL: | (OFURL*) | URL |
Creates a new OFDataArray with an item size of 1, containing the data of the specified URL.
URL | The URL to the contents for the OFDataArray |
+ (id) dataArrayWithItemSize: | (size_t) | itemSize |
Creates a new OFDataArray whose items all have the same size.
itemSize | The size of each element in the OFDataArray |
- (void *) firstItem |
Returns the first item of the OFDataArray.
- (id) init |
Initializes an already allocated OFDataArray with an item size of 1.
Reimplemented from OFObject.
- (id) initWithBase64EncodedString: | (OFString*) | string |
Initializes an already allocated OFDataArray with an item size of 1, containing the data of the Base64-encoded string.
string | The string with the Base64-encoded data |
- (id) initWithContentsOfFile: | (OFString*) | path |
Initializes an already allocated OFDataArray with an item size of 1, containing the data of the specified file.
path | The path of the file |
- (id) initWithContentsOfURL: | (OFURL*) | URL |
Initializes an already allocated OFDataArray with an item size of 1, containing the data of the specified URL.
URL | The URL to the contents for the OFDataArray |
- (id) initWithItemSize: | (size_t) | itemSize |
Initializes an already allocated OFDataArray whose items all have the same size.
itemSize | The size of each element in the OFDataArray |
- (void *) itemAtIndex: | (size_t) | index |
Returns a specific item of the OFDataArray.
index | The number of the item to return |
- (size_t) itemSize |
Returns the size of each item in the OFDataArray in bytes.
- (void *) lastItem |
Returns the last item of the OFDataArray.
- (OFString*) MD5Hash |
- (void) removeItemAtIndex: | (size_t) | index |
Removes the item at the specified index.
index | The index of the item to remove |
- (void) removeNItems: | (size_t) | nItems |
Removes the specified amount of items from the end of the OFDataArray.
nItems | The number of items to remove |
- (void) removeNItems: | (size_t) | nItems | |
atIndex: | (size_t) | index | |
Removes the specified amount of items at the specified index.
nItems | The number of items to remove |
index | The index at which the items are removed |
- (OFString*) SHA1Hash |
- (OFString *) stringByBase64Encoding |
Returns a string containing the data in Base64 encoding.
- (void) writeToFile: | (OFString*) | path |
Writes the OFDataArray into the specified file.
path | The path of the file to write to |