HexFiend
Instance Methods | List of all members
HFByteArray Class Reference

The principal Model class for HexFiend's MVC architecture. More...

Inheritance diagram for HFByteArray:
HFAttributedByteArray HFBTreeByteArray HFFullMemoryByteArray

Instance Methods

(HFByteRangeAttributeArray *) - attributesForBytesInRange:
 
(HFByteRangeAttributeArray *) - byteRangeAttributeArray
 
(BOOL) - writeToFile:trackingProgress:error:
 
(NSArray *) - rangesOfFileModifiedIfSavedToFile:
 
(BOOL) - clearDependenciesOnRanges:inFile:hint:
 
Initialization
(instancetype) - initWithByteSlice:
 
(instancetype) - initWithByteArray:
 
Accessing raw data
(unsigned long long) - length
 
(void) - copyBytes:range:
 
Accessing byte slices

Methods to access the byte slices underlying the HFByteArray.

(NSArray *) - byteSlices
 
(NSEnumerator *) - byteSliceEnumerator
 
(HFByteSlice *) - sliceContainingByteAtIndex:beginningOffset:
 
Modifying the byte array

Methods to modify the given byte array.

(void) - insertByteSlice:inRange:
 
(void) - insertByteArray:inRange:
 
(void) - deleteBytesInRange:
 
(HFByteArray *) - subarrayWithRange:
 
Write locking and generation count

Methods to lock and query the lock that prevents writes.

(void) - incrementChangeLockCounter
 
(void) - decrementChangeLockCounter
 
(BOOL) - changesAreLocked
 
(void) - incrementGenerationOrRaiseIfLockedForSelector:
 
(NSUInteger) - changeGenerationCount
 
Searching
(unsigned long long) - indexOfBytesEqualToBytes:inRange:searchingForwards:trackingProgress:
 

Detailed Description

HFByteArray implements the Model portion of HexFiend.framework. It is logically a mutable, resizable array of bytes, with a 64 bit length. It is somewhat analagous to a 64 bit version of NSMutableData, except that it is designed to enable efficient (faster than O(n)) implementations of insertion and deletion.

HFByteArray, being an abstract class, will raise an exception if you attempt to instantiate it directly. For most uses, instantiate HFBTreeByteArray instead, with the usual [[class alloc] init].

HFByteArray also exposes itself as an array of HFByteSlices, which are logically immutable arrays of bytes. which is useful for operations such as file saving that need to access the underlying byte slices.

HFByteArray contains a generation count, which is incremented whenever the HFByteArray changes (to allow caches to be implemented on top of it). It also includes the notion of locking: a locked HFByteArray will raise an exception if written to, but it may still be read.

ByteArrays have the usual threading restrictions for non-concurrent data structures. It is safe to read an HFByteArray concurrently from multiple threads. It is not safe to read an HFByteArray while it is being modified from another thread, nor is it safe to modify one simultaneously from two threads.

HFByteArray is an abstract class. It will raise an exception if you attempt to instantiate it directly. The principal concrete subclass is HFBTreeByteArray.

Method Documentation

§ initWithByteSlice:()

- (instancetype) initWithByteSlice: (HFByteSlice *)  slice

Initialize to a byte array containing only the given slice.

§ initWithByteArray:()

- (instancetype) initWithByteArray: (HFByteArray *)  array

Initialize to a byte array containing the slices of the given array.

§ length()

- (unsigned long long) length

Returns the length of the HFByteArray as a 64 bit unsigned long long. This is an abstract method that concrete subclasses must override.

§ copyBytes:range:()

- (void) copyBytes: (unsigned char *)  dst
range: (HFRange range 

Copies a range of bytes into a buffer. This is an abstract method that concrete subclasses must override.

§ byteSlices()

- (NSArray *) byteSlices

Returns the contents of the receiver as an array of byte slices. This is an abstract method that concrete subclasses must override.

§ byteSliceEnumerator()

- (NSEnumerator *) byteSliceEnumerator

Returns an NSEnumerator representing the byte slices of the receiver. This is implemented as enumerating over the result of -byteSlices, but subclasses can override this to be more efficient.

§ sliceContainingByteAtIndex:beginningOffset:()

- (HFByteSlice *) sliceContainingByteAtIndex: (unsigned long long)  offset
beginningOffset: (unsigned long long *)  actualOffset 

Returns the byte slice containing the byte at the given index, and the actual offset of this slice.

§ insertByteSlice:inRange:()

- (void) insertByteSlice: (HFByteSlice *)  slice
inRange: (HFRange lrange 

Insert an HFByteSlice in the given range. The maximum value of the range must not exceed the length of the subarray. The length of the given slice is not required to be equal to length of the range - in other words, this method may change the length of the receiver. This is an abstract method that concrete subclasses must override.

§ insertByteArray:inRange:()

- (void) insertByteArray: (HFByteArray *)  array
inRange: (HFRange lrange 

Insert an HFByteArray in the given range. This is implemented via calling insertByteSlice:inRange: with the byte slices from the given byte array.

§ deleteBytesInRange:()

- (void) deleteBytesInRange: (HFRange range

Delete bytes in the given range. This is implemented on the base class by creating an empty byte array and inserting it in the range to be deleted, via insertByteSlice:inRange:.

§ subarrayWithRange:()

- (HFByteArray *) subarrayWithRange: (HFRange range

Returns a new HFByteArray containing the given range. This is an abstract method that concrete subclasses must override.

§ incrementChangeLockCounter()

- (void) incrementChangeLockCounter

Increment the change lock. Until the change lock reaches 0, all modifications to the receiver will raise an exception.

§ decrementChangeLockCounter()

- (void) decrementChangeLockCounter

Decrement the change lock. If the change lock reaches 0, modifications will be allowed again.

§ changesAreLocked()

- (BOOL) changesAreLocked

Query if the changes are locked. This method is KVO compliant.

§ incrementGenerationOrRaiseIfLockedForSelector:()

- (void) incrementGenerationOrRaiseIfLockedForSelector: (SEL)  sel

Increments the generation count, unless the receiver is locked, in which case it raises an exception. All subclasses of HFByteArray should call this method at the beginning of any overridden method that may modify the receiver.

Parameters
selThe selector that would modify the receiver (e.g. deleteBytesInRange:). This is usually _cmd.

§ changeGenerationCount()

- (NSUInteger) changeGenerationCount

Return the change generation count. Every change to the ByteArray increments this by one or more. This can be used for caching layers on top of HFByteArray, to known when to expire their cache.

§ indexOfBytesEqualToBytes:inRange:searchingForwards:trackingProgress:()

- (unsigned long long) indexOfBytesEqualToBytes: (HFByteArray *)  findBytes
inRange: (HFRange range
searchingForwards: (BOOL)  forwards
trackingProgress: (HFProgressTracker *)  progressTracker 

Searches the receiver for a byte array matching findBytes within the given range, and returns the index that it was found. This is a concrete method on HFByteArray.

Parameters
findBytesThe HFByteArray containing the data to be found (the needle to the receiver's haystack).
rangeThe range of the receiver in which to search. The end of the range must not exceed the receiver's length.
forwardsIf this is YES, then the first match within the range is returned. Otherwise the last is returned.
progressTrackerAn HFProgressTracker to allow progress reporting and cancelleation for the search operation.
Returns
The index in the receiver of bytes equal to findBytes, or ULLONG_MAX if the byte array was not found (or the operation was cancelled)

§ attributesForBytesInRange:()

- (HFByteRangeAttributeArray *) attributesForBytesInRange: (HFRange range

Returns a byte range attribute array for the bytes in the given range.

Provided by category HFByteArray(HFAttributes).

§ byteRangeAttributeArray()

- (HFByteRangeAttributeArray *) byteRangeAttributeArray

Returns the HFByteArray level byte range attribute array. Default is to return nil.

Provided by category HFByteArray(HFAttributes).

§ writeToFile:trackingProgress:error:()

- (BOOL) writeToFile: (NSURL *)  targetURL
trackingProgress: (HFProgressTracker *)  progressTracker
error: (NSError **)  error 

Attempts to write the receiver to a file. This is a concrete method on HFByteArray.

Parameters
targetURLA URL to the file to be written to. It is OK for the receiver to contain one or more instances of HFByteSlice that are sourced from the file.
progressTrackerAn HFProgressTracker to allow progress reporting and cancelleation for the write operation.
errorAn out NSError parameter.
Returns
YES if the write succeeded, NO if it failed.

Provided by category HFByteArray(HFFileWriting).

§ rangesOfFileModifiedIfSavedToFile:()

- (NSArray *) rangesOfFileModifiedIfSavedToFile: (HFFileReference *)  reference

Returns the ranges of the file that would be modified, if the receiver were written to it. This is useful (for example) in determining if the clipboard can be preserved after a save operation. This is a concrete method on HFByteArray.

Parameters
referenceAn HFFileReference to the file to be modified
Returns
An array of HFRangeWrappers, representing the ranges of the file that would be affected. If no range would be affected, the result is an empty array.

Provided by category HFByteArray(HFFileWriting).

§ clearDependenciesOnRanges:inFile:hint:()

- (BOOL) clearDependenciesOnRanges: (NSArray *)  ranges
inFile: (HFFileReference *)  reference
hint: (NSMutableDictionary *)  hint 

Attempts to modify the receiver so that it no longer depends on any of the HFRanges in the array within the given file. It is not necessary to perform this operation on the byte array that is being written to the file.

Parameters
rangesAn array of HFRangeWrappers, representing ranges in the given file that the receiver should no longer depend on.
referenceThe HFFileReference that the receiver should no longer depend on.
hintA dictionary that can be used to improve the efficiency of the operation, by allowing multiple byte arrays to share the same state. If you plan to call this method on multiple byte arrays, pass the first one an empty NSMutableDictionary, and pass the same dictionary to subsequent calls.
Returns
A YES return indicates the operation was successful, and the receiver no longer contains byte slices that source data from any of the ranges of the given file (or never did). A NO return indicates that breaking the dependencies would require too much memory, and so the receiver still depends on some of those ranges.

Provided by category HFByteArray(HFFileWriting).


The documentation for this class was generated from the following file: