ObjFW
Public Member Functions | Static Public Member Functions
OFDataArray Class Reference

A class for storing arbitrary data in an array. More...

#import <OFDataArray.h>

Inheritance diagram for OFDataArray:
OFObject <OFCopying> <OFComparing> <OFSerialization> <OFObject> <OFObject> OFBigDataArray

List of all members.

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.

Detailed Description

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.


Member Function Documentation

- (void) addItem: (const void*)  item

Adds an item to the OFDataArray.

Parameters:
itemA pointer to an arbitrary item
- (void) addItem: (const void*)  item
atIndex: (size_t)  index 

Adds an item to the OFDataArray at the specified index.

Parameters:
itemA pointer to an arbitrary item
indexThe 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.

Parameters:
nItemsThe number of items to add
cArrayA 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.

Parameters:
nItemsThe number of items to add
cArrayA C array containing the items to add
indexThe index where the items should be added
- (void *) cArray

Returns all elements of the OFDataArray as a C array.

Warning:
The pointer is only valid until the OFDataArray is changed!

Modifying the returned array directly is allowed and will change the contents of the data array.

Returns:
All elements of the OFDataArray as a C array
- (size_t) count

Returns the number of items in the OFDataArray.

Returns:
The number of items in the OFDataArray
+ (id) dataArray

Creates a new OFDataArray with an item size of 1.

Returns:
A new autoreleased OFDataArray
+ (id) dataArrayWithBase64EncodedString: (OFString*)  string

Creates a new OFDataArray with an item size of 1, containing the data of the Base64-encoded string.

Parameters:
stringThe string with the Base64-encoded data
Returns:
A new autoreleased OFDataArray
+ (id) dataArrayWithContentsOfFile: (OFString*)  path

Creates a new OFDataArary with an item size of 1, containing the data of the specified file.

Parameters:
pathThe path of the file
Returns:
A new autoreleased OFDataArray
+ (id) dataArrayWithContentsOfURL: (OFURL*)  URL

Creates a new OFDataArray with an item size of 1, containing the data of the specified URL.

Parameters:
URLThe URL to the contents for the OFDataArray
Returns:
A new autoreleased OFDataArray
+ (id) dataArrayWithItemSize: (size_t)  itemSize

Creates a new OFDataArray whose items all have the same size.

Parameters:
itemSizeThe size of each element in the OFDataArray
Returns:
A new autoreleased OFDataArray
- (void *) firstItem

Returns the first item of the OFDataArray.

Returns:
The first item of the OFDataArray or NULL
- (id) init

Initializes an already allocated OFDataArray with an item size of 1.

Returns:
A initialized OFDataArray

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.

Parameters:
stringThe string with the Base64-encoded data
Returns:
A initialized OFDataArray
- (id) initWithContentsOfFile: (OFString*)  path

Initializes an already allocated OFDataArray with an item size of 1, containing the data of the specified file.

Parameters:
pathThe path of the file
Returns:
An initialized OFDataArray
- (id) initWithContentsOfURL: (OFURL*)  URL

Initializes an already allocated OFDataArray with an item size of 1, containing the data of the specified URL.

Parameters:
URLThe URL to the contents for the OFDataArray
Returns:
A new autoreleased OFDataArray
- (id) initWithItemSize: (size_t)  itemSize

Initializes an already allocated OFDataArray whose items all have the same size.

Parameters:
itemSizeThe size of each element in the OFDataArray
Returns:
An initialized OFDataArray
- (void *) itemAtIndex: (size_t)  index

Returns a specific item of the OFDataArray.

Parameters:
indexThe number of the item to return
Returns:
The specified item of the OFDataArray
- (size_t) itemSize

Returns the size of each item in the OFDataArray in bytes.

Returns:
The size of each item in the OFDataArray in bytes
- (void *) lastItem

Returns the last item of the OFDataArray.

Returns:
The last item of the OFDataArray or NULL
- (OFString*) MD5Hash

Returns the MD5 hash of the data array as an autoreleased OFString.

Returns:
The MD5 hash of the data array as an autoreleased OFString
- (void) removeItemAtIndex: (size_t)  index

Removes the item at the specified index.

Parameters:
indexThe index of the item to remove
- (void) removeNItems: (size_t)  nItems

Removes the specified amount of items from the end of the OFDataArray.

Parameters:
nItemsThe number of items to remove
- (void) removeNItems: (size_t)  nItems
atIndex: (size_t)  index 

Removes the specified amount of items at the specified index.

Parameters:
nItemsThe number of items to remove
indexThe index at which the items are removed
- (OFString*) SHA1Hash

Returns the SHA-1 hash of the data array as an autoreleased OFString.

Returns:
The SHA-1 hash of the data array as an autoreleased OFString
- (OFString *) stringByBase64Encoding

Returns a string containing the data in Base64 encoding.

Returns:
A string containing the data in Base64 encoding
- (void) writeToFile: (OFString*)  path

Writes the OFDataArray into the specified file.

Parameters:
pathThe path of the file to write to

The documentation for this class was generated from the following files:
 All Classes Functions Variables Properties