//AUTOMATICALLY GENERATED BY genfields.pl.
//DO NOT EDIT!!!!

package vrml.field;
import vrml.*;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.IOException;

public class ConstMFColor extends ConstMField {
    public ConstMFColor() {
    }

    public ConstMFColor(float[] colors) {
        this(colors.length, colors);
    }

    public ConstMFColor(int size, float[] colors) {
        for (int i = 0; i < size; i += 3)
            __vect.addElement(new ConstSFColor(colors[i], colors[i+1], colors[i+2]));
    }

    public ConstMFColor(float[][] colors) {
        for (int i = 0; i < colors.length; i++)
            __vect.addElement(new ConstSFColor(colors[i][0], colors[i][1], colors[i][2]));
    }

    public void getValue(float[] colors) {
        __updateRead();
        int size = __vect.size();
        for (int i = 0; i < size; i++) {
            ConstSFColor sfColor = (ConstSFColor) __vect.elementAt(i);
            colors[3*i+0] = sfColor.red;
            colors[3*i+1] = sfColor.green;
            colors[3*i+2] = sfColor.blue;
        }
    }

    public void getValue(float[][] colors) {
        __updateRead();
        int size = __vect.size();
        for (int i = 0; i < size; i++)
            ((ConstSFColor) __vect.elementAt(i)).getValue(colors[i]);
    }

    public void get1Value(int index, float[] colors) {
        __update1Read(index);
        ((ConstSFColor) __vect.elementAt(index)).getValue(colors);
    }

    public void get1Value(int index, SFColor sfColor) {
        __update1Read(index);
        sfColor.setValue((ConstSFColor) __vect.elementAt(index));
    }

    public String toString() {
        __updateRead();
        StringBuffer sb = new StringBuffer("[");
        int size = __vect.size();
        for (int i = 0; i < size; i++) {
            if (i > 0) sb.append(", ");
            sb.append(__vect.elementAt(i));
        }
        return sb.append("]").toString();
    }

    public void __fromPerl(BufferedReader in)  throws IOException {
        __vect.clear();
	String lenline = in.readLine();
	//System.out.println ("__fromPerl, read in length as " + lenline);
        //int len = Integer.parseInt(in.readLine());
	int len = Integer.parseInt(lenline);
        for (int i = 0; i < len; i++) {
            ConstSFColor sf = new ConstSFColor();
            sf.__fromPerl(in);
            __vect.addElement(sf);
        }
    }

    public void __toPerl(PrintWriter out)  throws IOException {
        StringBuffer sb = new StringBuffer("");
        int size = __vect.size();
	//out.print(size);
        for (int i = 0; i < size; i++) {
            ((ConstSFColor) __vect.elementAt(i)).__toPerl(out);
	    if (i != (size-1)) out.print (", ");
	}
	//out.println();
    }
    //public void setOffset(String offs) { this.offset = offs; } //JAS2
    //public String getOffset() { return this.offset; } //JAS2
}