frysk.value
Class Location

java.lang.Object
  extended by frysk.value.Location
Direct Known Subclasses:
ByteBufferLocation, PieceLocation

public abstract class Location
extends Object

Location of a variable. An sequence of bytes accessable using get/put methods. The underlying buffer does NOT have an implict byte-ordering (technically this makes the buffer big-endian). Instead, code needing to interpret a sequence of bytes as having a particular ordering (little, big, et.al.) must specify that ordering explicitly.


Constructor Summary
protected Location()
          Permit extension by anyone.
 
Method Summary
 byte[] get(ByteOrder order)
          Get the entire contents of the location as a big-endian array of bytes.
abstract  long getAddress()
           
protected abstract  byte getByte(long idx)
          Return the byte at IDX.
abstract  long length()
          The length of the location, in bytes.
 void put(ByteOrder order, byte[] bytes, int fill)
          Put the big-endian BYTES into the least-significant end of Location; if there insufficient bytes, pad the most sigificant end with FILL (treated as a byte); if there are too may bytes truncate the most significant end.
protected abstract  void putByte(long idx, byte value)
          Poke the byte at IDX.
protected abstract  Location slice(long offset, long length)
          Return a slice of this Location starting at byte OFFSET, and going for LENGTH bytes.
 byte[] toByteArray()
          Return the entire contents of the location as a sequence of raw bytes.
abstract  void toPrint(PrintWriter writer)
          Print this Location.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Location

protected Location()
Permit extension by anyone.

Method Detail

toString

public String toString()
Overrides:
toString in class Object

get

public byte[] get(ByteOrder order)
Get the entire contents of the location as a big-endian array of bytes. If ORDER is little-endian, the byte array will first be converted to big-endian (i.e., its order will be reversed) before returning. Useful for code trying to extract byte-order dependent data such as that needed by BigInteger and BigDecimal. Could re-implement this by decorating byte-order with a location specific get/put method.


toByteArray

public byte[] toByteArray()
Return the entire contents of the location as a sequence of raw bytes.


put

public void put(ByteOrder order,
                byte[] bytes,
                int fill)
Put the big-endian BYTES into the least-significant end of Location; if there insufficient bytes, pad the most sigificant end with FILL (treated as a byte); if there are too may bytes truncate the most significant end. If ORDER is little-endian, first convert the big-endian byte array into litte-endian (i.e., , reverse the byte order). Useful for code trying to store byte-order dependent data such as that returned by BigInteger and BigDecimal. Can re-implement this by decorating byte-order with a location specific get/put method.


slice

protected abstract Location slice(long offset,
                                  long length)
Return a slice of this Location starting at byte OFFSET, and going for LENGTH bytes.


getByte

protected abstract byte getByte(long idx)
Return the byte at IDX.


putByte

protected abstract void putByte(long idx,
                                byte value)
Poke the byte at IDX.


length

public abstract long length()
The length of the location, in bytes. This MUST be a long (or BigInteger) as a value's size could be bigger than 32-bits.


toPrint

public abstract void toPrint(PrintWriter writer)
Print this Location.


getAddress

public abstract long getAddress()