/* ----------------------------------------------------------------------------
 * This file was automatically generated by SWIG (http://www.swig.org).
 * Version 4.0.2
 *
 * Do not make changes to this file unless you know what you are doing--modify
 * the SWIG interface file instead.
 * ----------------------------------------------------------------------------- */

package com.robotraconteur;

public class MessageElementDataUtil {
  private transient long swigCPtr;
  protected transient boolean swigCMemOwn;

  protected MessageElementDataUtil(long cPtr, boolean cMemoryOwn) {
    swigCMemOwn = cMemoryOwn;
    swigCPtr = cPtr;
  }

  protected static long getCPtr(MessageElementDataUtil obj) {
    return (obj == null) ? 0 : obj.swigCPtr;
  }

  @SuppressWarnings("deprecation")
  protected void finalize() {
    delete();
  }

  public synchronized void delete() {
    if (swigCPtr != 0) {
      if (swigCMemOwn) {
        swigCMemOwn = false;
        RobotRaconteurJavaJNI.delete_MessageElementDataUtil(swigCPtr);
      }
      swigCPtr = 0;
    }
  }

public static Object rRBaseArrayToArray(RRBaseArray a)
  {
	if (a==null) return null;
	switch (a.getTypeID())
	{
		case DataTypes_double_t:
		{
	        double[] r=new double[(int)a.size()];
	        rRBaseArrayToDoubles(a,r,r.length);
	        return r;
		}
	    case DataTypes_single_t:
	    {
	        float[] r=new float[(int)a.size()];
	        rRBaseArrayToFloats(a,r,r.length);
	        return r;
		}
	    case DataTypes_int8_t:
	    {
	        byte[] r=new byte[(int)a.size()];
	        rRBaseArrayToBytes(a,r,r.length);
	        return r;
		}
	    case DataTypes_uint8_t:

	    {
	        byte[] r=new byte[(int)a.size()];
	        rRBaseArrayToBytes(a,r,r.length);
	        return new UnsignedBytes(r);
		}
	    case DataTypes_int16_t:
	    {
	    	short[] r=new short[(int)a.size()];
	        rRBaseArrayToShorts(a,r,r.length);
	        return r;
	    }
	    case DataTypes_uint16_t:
	    {
	    	short[] r=new short[(int)a.size()];
	        rRBaseArrayToShorts(a,r,r.length);
	        return new UnsignedShorts(r);
	    }
	    case DataTypes_int32_t:
	    {
	    	int[] r=new int[(int)a.size()];
	        rRBaseArrayToInts(a,r,r.length);
	        return r;
	    }
	    case DataTypes_uint32_t:
	    {
	    	int[] r=new int[(int)a.size()];
	        rRBaseArrayToInts(a,r,r.length);
	        return new UnsignedInts(r);
	    }
	    case DataTypes_int64_t:
	    {
	    	long[] r=new long[(int)a.size()];
	        rRBaseArrayToLongs(a,r,r.length);
	        return r;
	    }
	    case DataTypes_uint64_t:
	    {
	    	long[] r=new long[(int)a.size()];
	        rRBaseArrayToLongs(a,r,r.length);
	        return new UnsignedLongs(r);
	    }
	    case DataTypes_cdouble_t:
	    {
	    	double[] o2=new double[(int)a.size()*2];
	    	rRBaseArrayComplexToDoubles(a,o2,o2.length);
	    	CDouble[] o3=new CDouble[(int)a.size()];
	    	for (int j=0; j<o3.length; j++)
	    	{
	    		o3[j] = new CDouble(o2[j *2], o2[j*2+1]);
	    	}
	    	return o3;
	    }
	    case DataTypes_csingle_t:
	    {
	    	float[] o2=new float[(int)a.size()*2];
	    	rRBaseArrayComplexToFloats(a,o2,o2.length);
	    	CSingle[] o3=new CSingle[(int)a.size()];
	    	for (int j=0; j<o3.length; j++)
	    	{
	    		o3[j] = new CSingle(o2[j *2], o2[j*2+1]);
	    	}
	    	return o3;
	    }
	    case DataTypes_bool_t:
	    {
	    	byte[] o2=new byte[(int)a.size()];
	    	rRBaseArrayBoolToBytes(a,o2,o2.length);
	    	boolean[] o3=new boolean[(int)a.size()];
	    	for (int j=0; j<o3.length; j++)
	    	{
	    		o3[j] = o2[j] != 0;
	    	}
	    	return o3;
	    }
	    default:
	    	break;

	}

	throw new RuntimeException(new DataTypeException("Unknown RRArray type"));

  }

  public static RRBaseArray arrayToRRBaseArray(Object a)
  {
	  if (a==null) return null;
	  if (a instanceof double[]) return doublesToRRBaseArray((double[])a,((double[])a).length);
	  if (a instanceof float[]) return floatsToRRBaseArray((float[])a,((float[])a).length);
	  if (a instanceof byte[]) return bytesToRRBaseArray((byte[])a,((byte[])a).length,DataTypes.DataTypes_int8_t);
	  if (a instanceof UnsignedBytes) return bytesToRRBaseArray(((UnsignedBytes)a).value,((UnsignedBytes)a).value.length,DataTypes.DataTypes_uint8_t);
	  if (a instanceof short[]) return shortsToRRBaseArray((short[])a,((short[])a).length,DataTypes.DataTypes_int16_t);
	  if (a instanceof UnsignedShorts) return shortsToRRBaseArray(((UnsignedShorts)a).value,((UnsignedShorts)a).value.length,DataTypes.DataTypes_uint16_t);
	  if (a instanceof int[]) return intsToRRBaseArray((int[])a,((int[])a).length,DataTypes.DataTypes_int32_t);
	  if (a instanceof UnsignedInts) return intsToRRBaseArray(((UnsignedInts)a).value,((UnsignedInts)a).value.length,DataTypes.DataTypes_uint32_t);
	  if (a instanceof long[]) return longsToRRBaseArray((long[])a,((long[])a).length,DataTypes.DataTypes_int64_t);
	  if (a instanceof UnsignedLongs) return longsToRRBaseArray(((UnsignedLongs)a).value,((UnsignedLongs)a).value.length,DataTypes.DataTypes_uint64_t);
	  if (a instanceof CDouble[])
	  {
		  CDouble[] a1=(CDouble[])a;
		  double[] b1=new double[a1.length * 2];
		  for (int j = 0; j<a1.length; j++)
          {
              b1[j * 2] = a1[j].real;
              b1[j * 2 + 1] = a1[j].imag;
          }
		  return doublesToComplexRRBaseArray(b1,b1.length);
	  }
	  if (a instanceof CSingle[])
	  {
		  CSingle[] a1=(CSingle[])a;
		  float[] b1=new float[a1.length * 2];
		  for (int j = 0; j<a1.length; j++)
          {
              b1[j * 2] = a1[j].real;
              b1[j * 2 + 1] = a1[j].imag;
          }
		  return floatsToComplexRRBaseArray(b1,b1.length);
	  }
	  if (a instanceof boolean[])
	  {
		  boolean[] a1=(boolean[])a;
		  byte[] b1=new byte[a1.length];
		  for (int j = 0; j<a1.length; j++)
          {
              b1[j] = (byte) (a1[j] ? 1 : 0);
          }
		  return bytesToBoolRRBaseArray(b1,b1.length);
	  }

	  throw new RuntimeException(new DataTypeException("Unknown Array type"));

  }

  public static void arrayToRRBaseArray(Object a, RRBaseArray rra)
  {
	  if (a instanceof double[]) {doublesToRRBaseArray((double[])a,((double[])a).length,rra); return; }
	  if (a instanceof float[]) {floatsToRRBaseArray((float[])a,((float[])a).length,rra); return;}
	  if (a instanceof byte[]) { bytesToRRBaseArray((byte[])a,((byte[])a).length,rra); return; }
	  if (a instanceof UnsignedBytes) {bytesToRRBaseArray(((UnsignedBytes)a).value,((UnsignedBytes)a).value.length,rra); return; }
	  if (a instanceof short[]) {shortsToRRBaseArray((short[])a,((short[])a).length,rra); return; }
	  if (a instanceof UnsignedShorts) {shortsToRRBaseArray(((UnsignedShorts)a).value,((UnsignedShorts)a).value.length,rra); return; }
	  if (a instanceof int[]) {intsToRRBaseArray((int[])a,((int[])a).length,rra); return; }
	  if (a instanceof UnsignedInts) { intsToRRBaseArray(((UnsignedInts)a).value,((UnsignedInts)a).value.length,rra); return; }
	  if (a instanceof long[]) { longsToRRBaseArray((long[])a,((long[])a).length,rra); return; }
	  if (a instanceof UnsignedLongs) { longsToRRBaseArray(((UnsignedLongs)a).value,((UnsignedLongs)a).value.length,rra); return; }
	  if (a instanceof CDouble[])
	  {
		  CDouble[] a1=(CDouble[])a;
		  double[] b1=new double[a1.length * 2];
		  for (int j = 0; j<a1.length; j++)
          {
              b1[j * 2] = a1[j].real;
              b1[j * 2 + 1] = a1[j].imag;
          }
		  doublesToComplexRRBaseArray(b1,b1.length,rra);
		  return;
	  }
	  if (a instanceof CSingle[])
	  {
		  CSingle[] a1=(CSingle[])a;
		  float[] b1=new float[a1.length * 2];
		  for (int j = 0; j<a1.length; j++)
          {
              b1[j * 2] = a1[j].real;
              b1[j * 2 + 1] = a1[j].imag;
          }
		  floatsToComplexRRBaseArray(b1,b1.length,rra);
		  return;
	  }
	  if (a instanceof boolean[])
	  {
		  boolean[] a1=(boolean[])a;
		  byte[] b1=new byte[a1.length];
		  for (int j = 0; j<a1.length; j++)
          {
              b1[j] = (byte) (a1[j] ? 1 : 0);
          }
		  bytesToBoolRRBaseArray(b1,b1.length,rra);
		  return;
	  }
	  throw new RuntimeException(new DataTypeException("Unknown Array type"));
  }



  public static RRBaseArray toRRBaseArray(MessageElementData m) {
    long cPtr = RobotRaconteurJavaJNI.MessageElementDataUtil_toRRBaseArray(MessageElementData.getCPtr(m), m);
    return (cPtr == 0) ? null : new RRBaseArray(cPtr, true);
  }

  public static MessageElementNestedElementList toMessageElementNestedElementList(MessageElementData m) {
    long cPtr = RobotRaconteurJavaJNI.MessageElementDataUtil_toMessageElementNestedElementList(MessageElementData.getCPtr(m), m);
    return (cPtr == 0) ? null : new MessageElementNestedElementList(cPtr, true);
  }

  public static String rRBaseArrayToString(RRBaseArray rrarray) {
    return RobotRaconteurJavaJNI.MessageElementDataUtil_rRBaseArrayToString(RRBaseArray.getCPtr(rrarray), rrarray);
  }

  public static void rRBaseArrayToDoubles(RRBaseArray rrarray, double[] array_out, int len) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_rRBaseArrayToDoubles(RRBaseArray.getCPtr(rrarray), rrarray, array_out, len);
  }

  public static void rRBaseArrayToFloats(RRBaseArray rrarray, float[] array_out, int len) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_rRBaseArrayToFloats(RRBaseArray.getCPtr(rrarray), rrarray, array_out, len);
  }

  public static void rRBaseArrayToBytes(RRBaseArray rrarray, byte[] array_out, int len) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_rRBaseArrayToBytes__SWIG_0(RRBaseArray.getCPtr(rrarray), rrarray, array_out, len);
  }

  public static void rRBaseArrayToBytes(RRBaseArray rrarray, short[] array_out, int len) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_rRBaseArrayToBytes__SWIG_1(RRBaseArray.getCPtr(rrarray), rrarray, array_out, len);
  }

  public static void rRBaseArrayToShorts(RRBaseArray rrarray, short[] array_out, int len) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_rRBaseArrayToShorts__SWIG_0(RRBaseArray.getCPtr(rrarray), rrarray, array_out, len);
  }

  public static void rRBaseArrayToShorts(RRBaseArray rrarray, int[] array_out, int len) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_rRBaseArrayToShorts__SWIG_1(RRBaseArray.getCPtr(rrarray), rrarray, array_out, len);
  }

  public static void rRBaseArrayToInts(RRBaseArray rrarray, int[] array_out, int len) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_rRBaseArrayToInts__SWIG_0(RRBaseArray.getCPtr(rrarray), rrarray, array_out, len);
  }

  public static void rRBaseArrayToInts(RRBaseArray rrarray, long[] array_out, int len) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_rRBaseArrayToInts__SWIG_1(RRBaseArray.getCPtr(rrarray), rrarray, array_out, len);
  }

  public static void rRBaseArrayToLongs(RRBaseArray rrarray, long[] array_out, int len) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_rRBaseArrayToLongs(RRBaseArray.getCPtr(rrarray), rrarray, array_out, len);
  }

  public static void rRBaseArrayComplexToDoubles(RRBaseArray rrarray, double[] array_out, int len) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_rRBaseArrayComplexToDoubles(RRBaseArray.getCPtr(rrarray), rrarray, array_out, len);
  }

  public static void rRBaseArrayComplexToFloats(RRBaseArray rrarray, float[] array_out, int len) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_rRBaseArrayComplexToFloats(RRBaseArray.getCPtr(rrarray), rrarray, array_out, len);
  }

  public static void rRBaseArrayBoolToBytes(RRBaseArray rrarray, short[] array_out, int len) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_rRBaseArrayBoolToBytes__SWIG_0(RRBaseArray.getCPtr(rrarray), rrarray, array_out, len);
  }

  public static void rRBaseArrayBoolToBytes(RRBaseArray rrarray, byte[] array_out, int len) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_rRBaseArrayBoolToBytes__SWIG_1(RRBaseArray.getCPtr(rrarray), rrarray, array_out, len);
  }

  public static RRBaseArray stringToRRBaseArray(String str) {
    long cPtr = RobotRaconteurJavaJNI.MessageElementDataUtil_stringToRRBaseArray(str);
    return (cPtr == 0) ? null : new RRBaseArray(cPtr, true);
  }

  public static RRBaseArray doublesToRRBaseArray(double[] array_in, int len) {
    long cPtr = RobotRaconteurJavaJNI.MessageElementDataUtil_doublesToRRBaseArray__SWIG_0(array_in, len);
    return (cPtr == 0) ? null : new RRBaseArray(cPtr, true);
  }

  public static RRBaseArray floatsToRRBaseArray(float[] array_in, int len) {
    long cPtr = RobotRaconteurJavaJNI.MessageElementDataUtil_floatsToRRBaseArray__SWIG_0(array_in, len);
    return (cPtr == 0) ? null : new RRBaseArray(cPtr, true);
  }

  public static RRBaseArray bytesToRRBaseArray(byte[] array_in, int len, DataTypes type) {
    long cPtr = RobotRaconteurJavaJNI.MessageElementDataUtil_bytesToRRBaseArray__SWIG_0(array_in, len, type.swigValue());
    return (cPtr == 0) ? null : new RRBaseArray(cPtr, true);
  }

  public static RRBaseArray bytesToRRBaseArray(short[] array_in, int len) {
    long cPtr = RobotRaconteurJavaJNI.MessageElementDataUtil_bytesToRRBaseArray__SWIG_1(array_in, len);
    return (cPtr == 0) ? null : new RRBaseArray(cPtr, true);
  }

  public static RRBaseArray shortsToRRBaseArray(short[] array_in, int len, DataTypes type) {
    long cPtr = RobotRaconteurJavaJNI.MessageElementDataUtil_shortsToRRBaseArray__SWIG_0(array_in, len, type.swigValue());
    return (cPtr == 0) ? null : new RRBaseArray(cPtr, true);
  }

  public static RRBaseArray shortsToRRBaseArray(int[] array_in, int len) {
    long cPtr = RobotRaconteurJavaJNI.MessageElementDataUtil_shortsToRRBaseArray__SWIG_1(array_in, len);
    return (cPtr == 0) ? null : new RRBaseArray(cPtr, true);
  }

  public static RRBaseArray intsToRRBaseArray(int[] array_in, int len, DataTypes type) {
    long cPtr = RobotRaconteurJavaJNI.MessageElementDataUtil_intsToRRBaseArray__SWIG_0(array_in, len, type.swigValue());
    return (cPtr == 0) ? null : new RRBaseArray(cPtr, true);
  }

  public static RRBaseArray intsToRRBaseArray(long[] array_in, int len) {
    long cPtr = RobotRaconteurJavaJNI.MessageElementDataUtil_intsToRRBaseArray__SWIG_1(array_in, len);
    return (cPtr == 0) ? null : new RRBaseArray(cPtr, true);
  }

  public static RRBaseArray longsToRRBaseArray(long[] array_in, int len, DataTypes type) {
    long cPtr = RobotRaconteurJavaJNI.MessageElementDataUtil_longsToRRBaseArray__SWIG_0(array_in, len, type.swigValue());
    return (cPtr == 0) ? null : new RRBaseArray(cPtr, true);
  }

  public static RRBaseArray doublesToComplexRRBaseArray(double[] array_in, int len) {
    long cPtr = RobotRaconteurJavaJNI.MessageElementDataUtil_doublesToComplexRRBaseArray__SWIG_0(array_in, len);
    return (cPtr == 0) ? null : new RRBaseArray(cPtr, true);
  }

  public static RRBaseArray floatsToComplexRRBaseArray(float[] array_in, int len) {
    long cPtr = RobotRaconteurJavaJNI.MessageElementDataUtil_floatsToComplexRRBaseArray__SWIG_0(array_in, len);
    return (cPtr == 0) ? null : new RRBaseArray(cPtr, true);
  }

  public static RRBaseArray bytesToBoolRRBaseArray(short[] array_in, int len) {
    long cPtr = RobotRaconteurJavaJNI.MessageElementDataUtil_bytesToBoolRRBaseArray__SWIG_0(array_in, len);
    return (cPtr == 0) ? null : new RRBaseArray(cPtr, true);
  }

  public static RRBaseArray bytesToBoolRRBaseArray(byte[] array_in, int len) {
    long cPtr = RobotRaconteurJavaJNI.MessageElementDataUtil_bytesToBoolRRBaseArray__SWIG_1(array_in, len);
    return (cPtr == 0) ? null : new RRBaseArray(cPtr, true);
  }

  public static void doublesToRRBaseArray(double[] array_in, int len, RRBaseArray rrarray) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_doublesToRRBaseArray__SWIG_1(array_in, len, RRBaseArray.getCPtr(rrarray), rrarray);
  }

  public static void floatsToRRBaseArray(float[] array_in, int len, RRBaseArray rrarray) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_floatsToRRBaseArray__SWIG_1(array_in, len, RRBaseArray.getCPtr(rrarray), rrarray);
  }

  public static void bytesToRRBaseArray(byte[] array_in, int len, RRBaseArray rrarray) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_bytesToRRBaseArray__SWIG_2(array_in, len, RRBaseArray.getCPtr(rrarray), rrarray);
  }

  public static void bytesToRRBaseArray(short[] array_in, int len, RRBaseArray rrarray) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_bytesToRRBaseArray__SWIG_3(array_in, len, RRBaseArray.getCPtr(rrarray), rrarray);
  }

  public static void shortsToRRBaseArray(short[] array_in, int len, RRBaseArray rrarray) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_shortsToRRBaseArray__SWIG_2(array_in, len, RRBaseArray.getCPtr(rrarray), rrarray);
  }

  public static void shortsToRRBaseArray(int[] array_in, int len, RRBaseArray rrarray) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_shortsToRRBaseArray__SWIG_3(array_in, len, RRBaseArray.getCPtr(rrarray), rrarray);
  }

  public static void intsToRRBaseArray(int[] array_in, int len, RRBaseArray rrarray) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_intsToRRBaseArray__SWIG_2(array_in, len, RRBaseArray.getCPtr(rrarray), rrarray);
  }

  public static void intsToRRBaseArray(long[] array_in, int len, RRBaseArray rrarray) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_intsToRRBaseArray__SWIG_3(array_in, len, RRBaseArray.getCPtr(rrarray), rrarray);
  }

  public static void longsToRRBaseArray(long[] array_in, int len, RRBaseArray rrarray) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_longsToRRBaseArray__SWIG_1(array_in, len, RRBaseArray.getCPtr(rrarray), rrarray);
  }

  public static void doublesToComplexRRBaseArray(double[] array_in, int len, RRBaseArray rrarray) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_doublesToComplexRRBaseArray__SWIG_1(array_in, len, RRBaseArray.getCPtr(rrarray), rrarray);
  }

  public static void floatsToComplexRRBaseArray(float[] array_in, int len, RRBaseArray rrarray) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_floatsToComplexRRBaseArray__SWIG_1(array_in, len, RRBaseArray.getCPtr(rrarray), rrarray);
  }

  public static void bytesToBoolRRBaseArray(byte[] array_in, int len, RRBaseArray rrarray) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_bytesToBoolRRBaseArray__SWIG_2(array_in, len, RRBaseArray.getCPtr(rrarray), rrarray);
  }

  public static void bytesToBoolRRBaseArray(short[] array_in, int len, RRBaseArray rrarray) {
    RobotRaconteurJavaJNI.MessageElementDataUtil_bytesToBoolRRBaseArray__SWIG_3(array_in, len, RRBaseArray.getCPtr(rrarray), rrarray);
  }

  public MessageElementDataUtil() {
    this(RobotRaconteurJavaJNI.new_MessageElementDataUtil(), true);
  }

}
