Ejemplo n.º 1
0
  /**
   * Meant for creating another view of a buffer
   *
   * @param underlyingBuffer the underlying buffer to create a view from
   * @param length the length of the view
   * @param offset the offset for the view
   */
  protected BaseDataBuffer(DataBuffer underlyingBuffer, long length, long offset) {
    if (length < 1) throw new IllegalArgumentException("Length must be >= 1");
    initTypeAndSize();
    this.length = length;
    this.offset = offset;
    this.allocationMode = underlyingBuffer.allocationMode();
    this.elementSize = underlyingBuffer.getElementSize();
    this.underlyingLength = underlyingBuffer.underlyingLength();
    this.wrappedDataBuffer = underlyingBuffer;

    // Adding link to original databuffer
    if (underlyingBuffer.originalDataBuffer() == null) {
      this.originalBuffer = underlyingBuffer;
      this.originalOffset = offset;
    } else {

      this.originalBuffer = underlyingBuffer.originalDataBuffer();

      // FIXME: please don't remove this comment, since there's probably a bug in current offset()
      // impl,
      // and this line will change originalOffset accroding to proper offset() impl
      // FIXME: [email protected]
      this.originalOffset = offset; // + underlyingBuffer.originalOffset();
    }

    if (underlyingBuffer.dataType() == Type.DOUBLE) {
      pointer = underlyingBuffer.pointer();
      indexer = underlyingBuffer.indexer();
    } else if (underlyingBuffer.dataType() == Type.FLOAT) {
      pointer = underlyingBuffer.pointer();
      indexer = underlyingBuffer.indexer();
    } else if (underlyingBuffer.dataType() == Type.INT) {
      pointer = underlyingBuffer.pointer();
      indexer = underlyingBuffer.indexer();
    }
  }