/* SCCS - @(#)NslBoolean2.java 1.5 - 09/20/99 - 19:19:38 */ // Copyright: Copyright (c) 1997 University of Southern California Brain Project. // Copyright: This software may be freely copied provided the toplevel // Copyright: COPYRIGHT file is included with each such copy. // Copyright: Email nsl@java.usc.edu. //////////////////////////////////////////////////////////////////////////////// // NslBoolean2.java /** * NslBoolean2 - boolean vector */ package nslj.src.lang; public class NslBoolean2 extends NslBoolean { public boolean[][] _data; /** * Constructor with default value null */ public NslBoolean2() { super(); _data = null; } /** * Constructor, initialize the value to value * @param value - the init value */ public NslBoolean2(boolean[][] value) { super(); _data = new boolean[value.length][value[0].length]; set(value); } /** * Constructor, initialize the value to the same as another NslNumeric0 * @param n - a scalar number */ public NslBoolean2(NslNumeric2 n) { super(); _data = new boolean[n.getSize1()][n.getSize2()]; set(n.getint2()); } /** * Constructor, initialize the value to the same as another NslNumeric0 * @param n - a scalar number */ public NslBoolean2(NslBoolean2 n) { super(); _data = new boolean[n.getSize1()][n.getSize2()]; set(n.getboolean2()); } /** * Constructor, initialize the number to be size size 1-D array * @param size - size of the new array */ public NslBoolean2(int size1, int size2) { super(); _data = new boolean[size1][size2]; } /** * This constructs a number with specified name * @param name - name of the variable */ public NslBoolean2(String name) { super(name); _data = null; } /** * This constructs a number with specified name * @param name - name of the variable * @param size - size of the array */ public NslBoolean2(String name, int size1, int size2) { super(name); _data = new boolean[size1][size2]; } public NslBoolean2(String name, NslHierarchy curParent) { super(name,curParent,curParent.nslGetAccess()); _data = null; } public NslBoolean2(String name, NslHierarchy curParent, int size1, int size2) { super(name,curParent,curParent.nslGetAccess()); _data = new boolean[size1][size2]; } /** * This constructs a number with specified name * @param name - name of the variable * @param value - initialized values */ public NslBoolean2(String name, NslNumeric2 value) { super(name); _data = new boolean[value.getSize1()][value.getSize2()]; set(value.getint2()); } /** * This constructs a number with specified name * @param name - name of the variable * @param value - initialized values */ public NslBoolean2(String name, NslBoolean2 value) { super(name); _data = new boolean[value.getSize1()][value.getSize2()]; set(value.getboolean2()); } public NslBoolean2(String name, NslHierarchy curParent, NslNumeric2 value) { super(name,curParent,curParent.nslGetAccess()); _data = new boolean[value.getSize1()][value.getSize2()]; set(value.getint2()); } public NslBoolean2(String name, NslHierarchy curParent, NslBoolean2 value) { super(name,curParent,curParent.nslGetAccess()); _data = new boolean[value.getSize1()][value.getSize2()]; set(value.getboolean2()); } public NslBoolean2(String name, NslHierarchy curParent, boolean[][] value) { super(name,curParent,curParent.nslGetAccess()); _data = new boolean[value.length][value[0].length]; set(value); } /** * allocate memory dynamically */ public void nslMemAlloc(int size1, int size2) { _data = new boolean[size1][size2]; } //---various --------- /* * Duplicating data between buffers in double buffering port model. * Since we cannot ensure the copy is the original copy created * in instantiation, this code is to make a security check and * to make sure the program runs correctly in the latter step. */ public void duplicateData(NslData n) { try { /* Here we assume that the passed parameter is originally a NslBoolean0 class. Otherwise, it will force a ClassCastException and notify the NslSystem. */ set(((NslBoolean2)n).getboolean2()); } catch (ClassCastException e) { System.out.println("Class exception is caught in data duplication"); System.out.println("between two copies of buffer."); System.out.println("Please check NslPort arrangement"); throw e; } } /** * Clone this number * @return - a copy of this number */ public NslData duplicateThis() { if (isDataSet()) return (NslData)(new NslBoolean2(getboolean2())); else return (NslData) (new NslBoolean2()); } /** * Set the reference to the wrapped data of n * It is used in double buffered ports, to make the the ports * reference different number object at different time. * @param n - number concerned */ public void setReference(NslData n) { try { _data = ((NslBoolean2) n).getboolean2(); } catch (ClassCastException e) { System.out.println("Class exception is caught in reference setting"); System.out.println("between two copies of buffer."); System.out.println("Please check NslPort arrangement"); throw e; } } /** * Check if the internal number data is null * @return - true if it is defined, false if the reference is null */ public boolean isDataSet() { return (_data != null); } /** * Reset the reference pointer to null */ public void resetData() { _data = null; } public String toString() { StringBuffer strbuf = new StringBuffer(); int i, j; int size1 = _data.length; int size2 = _data[0].length; for (i=0; iposth element of this one-dimensional array * @return - value in java numerical type double. */ public double getdouble(int pos1, int pos2){ return (double)(_data[pos1][pos2]?1.0:0.0); } /** * Get the posth element of this one-dimensional array * @return - value in java numerical type float. */ public float getfloat(int pos1, int pos2) { return (float)(_data[pos1][pos2]?1.0:0.0); } /** * Get the posth element of this one-dimensional array * @return - value in java numerical type int. */ public int getint(int pos1, int pos2){ return (int)(_data[pos1][pos2]?1:0); } /** * Get the posth element of this one-dimensional array * @return - value in java numerical type int. */ public boolean getboolean(int pos1, int pos2){ return _data[pos1][pos2]; } // Interface with NslNumeric type /** * Get the value of this number in double precision * floating point NslNumeric * @return NslNumeric - in double precision pointing point */ public NslDouble2 getNslDouble2() { return (new NslDouble2(getdouble2())); } /** * Get the value of this number in single precision * floating point NslNumeric * @return NslNumeric - in single precision pointing point */ public NslFloat2 getNslFloat2() { return (new NslFloat2(getfloat2())); } /** * Get the value of this number in integer * @return NslNumeric - in integer */ public NslInt2 getNslInteger2() { return (new NslInt2(getint2())); } /** * Get the value of this number in integer * @return NslNumeric - in integer */ public NslBoolean2 getNslBoolean2() { return this; } public boolean[][] getSector(int start1, int start2, int end1, int end2) { int i1, i2, j1, j2; int length1, length2; boolean[][] intdata; if (start1 < 0) start1 = 0; if (start2 < 0) start2 = 0; if (end1 > _data.length) end1 = _data.length; if (end2 > _data[0].length) end2 = _data[0].length; length1 = end1-start1+1; length2 = end2-start2+1; intdata = new boolean[length1][length2]; i1 = start1; i2 = start2; for (j1=0; j1value * @param value */ public void set(int[][] value) { int i,j; int size1 = _data.length; int size2 = _data[0].length; if (size1 != value.length || size2 !=value[0].length) { System.out.println("NslBoolean2: array size not equal"); return; } for (i=0; ivalue * @param value */ public void set(int pos, float[] value) { if (_data[0].length != value.length) { System.out.println("NslBoolean2: array size not match"); return; } for (int i=0; i<_data[0].length; i++) { _data[pos][i]=value[i]!=0.0; } return; } /** * Set the value of this number to value * @param value */ public void set(int pos, int[] value) { if (_data[0].length != value.length) { System.out.println("NslBoolean1: array size not match"); return; } for (int i=0; i<_data[0].length; i++) { _data[pos][i]=value[i]!=0; } return; } /** * Set the value of this number to value * @param value */ public void set(int pos, boolean[] value) { if (_data[0].length != value.length) { System.out.println("NslBoolean1: array size not match"); return; } for (int i=0; i<_data[0].length; i++) { _data[pos][i]=value[i]; } return; } /** * Set the posth element of this array to value * @param pos * @param value */ public void set(int pos1, int pos2, double value) { _data[pos1][pos2]=value!=0.0; return; } /** * Set the posth element of this array to value * @param pos * @param value */ public void set(int pos1, int pos2, float value) { _data[pos1][pos2]=value!=0.0; return; } /** * Set the posth element of this array to value * @param pos * @param value */ public void set(int pos1, int pos2, int value) { _data[pos1][pos2]=value!=0; return; } /** * Set the posth element of this array to value * @param pos * @param value */ public void set(int pos1, int pos2, boolean value) { _data[pos1][pos2]=value; return; } /** * Set all elements of this array to value * @param value */ public void set(double value) { for (int i=0; i<_data.length; i++) { for (int j=0; j<_data[0].length; j++) { _data[i][j]=value!=0.0; } } return; } /** * Set all elements of this array to value * @param value */ public void set(float value) { for (int i=0; i<_data.length; i++) { for (int j=0; j<_data[0].length; j++) { _data[i][j]=value!=0.0; } } return; } /** * Set all elements of this array to value * @param value */ public void set(int value) { for (int i=0; i<_data.length; i++) { for (int j=0; j<_data[0].length; j++) { _data[i][j]=value!=0; } } return; } /** * Set all elements of this array to value * @param value */ public void set(boolean value) { for (int i=0; i<_data.length; i++) { for (int j=0; j<_data[0].length; j++) { _data[i][j]=value; } } return; } /** * Set the value of this array to value * @param value */ public void set(NslNumeric2 n) { set(n.getint2()); } public void set(int pos, NslNumeric1 value) { set(pos, value.getint1()); return; } /** * Set all elements of this array to value * @param value */ public void set(NslNumeric0 value) { set(value.getint()); return; } public void set(int pos1, int pos2, NslNumeric0 value) { set(pos1,pos2,value.getint()); return; } /** * Set the value of this array to value * @param value */ public void set(NslBoolean2 n) { set(n.getboolean2()); } public void set(int pos, NslBoolean1 value) { set(pos, value.getboolean1()); return; } /** * Set all elements of this array to value * @param value */ public void set(NslBoolean0 value) { set(value.getboolean()); } public void set(int pos1, int pos2, NslBoolean0 value) { set(pos1,pos2,value.getboolean()); return; } public void setSector(boolean[][] d, int startpos1, int startpos2) { int endpos1 = d.length+startpos1; int endpos2 = d[0].length+startpos2; int i1, i2; int j1=0, j2=0; if (startpos1 > _data.length) return; if (startpos2 > _data[0].length) return; if (endpos1 > _data.length) endpos1 = _data.length; if (endpos2 > _data[0].length) endpos2 = _data[0].length; for (i1=startpos1, j1=0; i1size * @param size */ public void getNslSize(NslInt0 size1, NslInt0 size2) { size1.set((_data==null?0:_data.length)); size2.set((_data==null?0:_data[0].length)); } /** * get the size of this array and put it into size * @return size - always a vector of 4 elements */ public int[] getSizes(){ int[]size =new int[4]; size[0]=(_data==null?0:_data.length); size[1]=(_data==null?0:_data[0].length); size[2]=0; size[3]=0; return(size); } /** * get the size of this array at the rightmost dimension * @return always zero */ public int getSize1() { return (_data==null?0:_data.length); } /** * get the size of this array at the second to right dimension * @return always zero */ public int getSize2() { return (_data==null?0:_data[0].length); } /** * get the size of this array at the third to right dimension * @return always zero */ public int getSize3() { return 0; } /** * get the size of this array at the fourth to right dimension * @return always zero */ public int getSize4() { return 0; } } // NslBoolean2.java ////////////////////////////////////////////////////////////////////////////////