package nxm.sys.libm;

import nxm.sys.inc.Constants;

/**
   Performs the Demux operation on arrays. <br>
   See {@link Operator} for a description of the available I/O Modes.
   @author  Auto-Generated
   @see     Operator
*/
@SuppressWarnings("cast")
public final class Demux extends Operator implements Constants {

  /** Create a new instance. */
  public Demux() {
    super();
  }

  /** Create a new instance.
      @param flags The processing flags to use.
   */
  public Demux (int flags) {
    super(flags);
  }

  /** Create a new instance.
      @param scale The scale factor to use.
   */
  public Demux (double scale) {
    super(scale);
  }

  /** Create a new instance.
      @param flags The processing flags to use.
      @param scale The scale factor to use.
   */
  public Demux (int flags, double scale) {
    super(flags,scale);
  }

  public final int validate (char type, int n, int mode) {
    switch (mode) {
      case CSS: return n;
      default: return NOSUPPORT;
    }
  }

  public final int process (double[][] v, int n, int mode) {
    switch (mode) {
      case CSS: CSS(v[0],v[1],v[2],n); return n;
      default:  return NOSUPPORT;
    }
  }

  public final int process (double[][] v, int n, int mode, double scale) {
    switch (mode) {
      case CSS: CSS(v[0],v[1],v[2],n); return n;
      default:  return NOSUPPORT;
    }
  }

  /** Apply this operator to mode {@link Operator#CSS} data.
      @param a     The first  operand.
      @param b     The second  operand.
      @param c     The third  operand.
      @param n     The number of elements to operate on.
      @see #process(double[][],int,int)
   */
  public static final void CSS (double[] a, double[] b, double[] c, int n) {
      for (int i=0,j=0; i<n; i++,j+=2) {
        b[i]=a[j]; c[i]=a[j+1];
      }
  }

  public final int process (float[][] v, int n, int mode) {
    switch (mode) {
      case CSS: CSS(v[0],v[1],v[2],n); return n;
      default:  return NOSUPPORT;
    }
  }

  public final int process (float[][] v, int n, int mode, double scale) {
    switch (mode) {
      case CSS: CSS(v[0],v[1],v[2],n); return n;
      default:  return NOSUPPORT;
    }
  }

  /** Apply this operator to mode {@link Operator#CSS} data.
      @param a     The first  operand.
      @param b     The second  operand.
      @param c     The third  operand.
      @param n     The number of elements to operate on.
      @see #process(float[][],int,int)
   */
  public static final void CSS (float[] a, float[] b, float[] c, int n) {
      for (int i=0,j=0; i<n; i++,j+=2) {
        b[i]=a[j]; c[i]=a[j+1];
      }
  }

  public final int process (int[][] v, int n, int mode) {
    switch (mode) {
      case CSS: CSS(v[0],v[1],v[2],n); return n;
      default:  return NOSUPPORT;
    }
  }

  public final int process (int[][] v, int n, int mode, double scale) {
    switch (mode) {
      case CSS: CSS(v[0],v[1],v[2],n); return n;
      default:  return NOSUPPORT;
    }
  }

  /** Apply this operator to mode {@link Operator#CSS} data.
      @param a     The first  operand.
      @param b     The second  operand.
      @param c     The third  operand.
      @param n     The number of elements to operate on.
      @see #process(int[][],int,int)
   */
  public static final void CSS (int[] a, int[] b, int[] c, int n) {
      for (int i=0,j=0; i<n; i++,j+=2) {
        b[i]=a[j]; c[i]=a[j+1];
      }
  }

  public int getInputs() { return 1; }
  public int getOutputs() { return 2; }
}
