HexFiend
|
The principal Model class for HexFiend's MVC architecture. More...
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.
- (instancetype) initWithByteSlice: | (HFByteSlice *) | slice |
Initialize to a byte array containing only the given slice.
- (instancetype) initWithByteArray: | (HFByteArray *) | array |
Initialize to a byte array containing the slices of the given array.
- (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.
- (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.
- (NSArray *) byteSlices |
Returns the contents of the receiver as an array of byte slices. This is an abstract method that concrete subclasses must override.
- (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.
- (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.
- (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.
- (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.
- (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:
.
- (HFByteArray *) subarrayWithRange: | (HFRange) | range |
Returns a new HFByteArray containing the given range. This is an abstract method that concrete subclasses must override.
- (void) incrementChangeLockCounter |
Increment the change lock. Until the change lock reaches 0, all modifications to the receiver will raise an exception.
- (void) decrementChangeLockCounter |
Decrement the change lock. If the change lock reaches 0, modifications will be allowed again.
- (BOOL) changesAreLocked |
Query if the changes are locked. This method is KVO compliant.
- (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.
sel | The selector that would modify the receiver (e.g. deleteBytesInRange: ). This is usually _cmd . |
- (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.
- (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.
findBytes | The HFByteArray containing the data to be found (the needle to the receiver's haystack). |
range | The range of the receiver in which to search. The end of the range must not exceed the receiver's length. |
forwards | If this is YES, then the first match within the range is returned. Otherwise the last is returned. |
progressTracker | An HFProgressTracker to allow progress reporting and cancelleation for the search operation. |
findBytes
, or ULLONG_MAX if the byte array was not found (or the operation was cancelled) - (HFByteRangeAttributeArray *) attributesForBytesInRange: | (HFRange) | range |
Returns a byte range attribute array for the bytes in the given range.
Provided by category HFByteArray(HFAttributes).
- (HFByteRangeAttributeArray *) byteRangeAttributeArray |
Returns the HFByteArray level byte range attribute array. Default is to return nil.
Provided by category HFByteArray(HFAttributes).
- (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.
targetURL | A 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. |
progressTracker | An HFProgressTracker to allow progress reporting and cancelleation for the write operation. |
error | An out NSError parameter. |
Provided by category HFByteArray(HFFileWriting).
- (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.
reference | An HFFileReference to the file to be modified |
Provided by category HFByteArray(HFFileWriting).
- (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.
ranges | An array of HFRangeWrappers, representing ranges in the given file that the receiver should no longer depend on. |
reference | The HFFileReference that the receiver should no longer depend on. |
hint | A 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. |
Provided by category HFByteArray(HFFileWriting).