package nxm.sys.lib;

import nxm.sys.inc.Constants;
import nxm.sys.inc.DataTypes;

/**
  Base class for primitives.  This is a container for methods that are
  specific to primitives.  These include data generators, data processors,
  data sinks and graphical primitives which normally execute in a sub-thread
  of the current shell.

  @author Jeff Schoen
*/
public class Primitive extends Command implements DataTypes, Constants {

  /** The default buffer size. */
  public int bufSize = 32768;

  /** The default transfer length. */
  public int xfer = 1024;

  /** The data generator length. */
  public double todo = -1;

  /** default constructor */
  public Primitive () {}

  /** Returns the number of elements to process this pass.

      @return The number of elements to process.
   */
  public int todo() {
    int ndo;
    if (todo < 0.0) ndo = xfer;
    else if (todo > (double)xfer) ndo = xfer;
    else ndo = (int)todo;
    todo -= (double)ndo;
    return (ndo);
  }

  /** Sets the total number of elements to process.

      @param elements The total number of elements to process.
   */
  public void todo( double elements) {
    todo = elements;
  }

  @Override
  public boolean isPipable() { return true; }

}
