//Amended by paul johnson June 26 to move class DataRecord outside of the
//InnerClassHDFDemo class. It crashed under JDK otherwise.

//Marcus Daniels June 26, 2001, swarm-support

//  First off, you can't put arrays in objects that are stored `shallow'.
//  The other thing is that any ivars you want picked up should be tagged public.

//  Here's an example.  The first time it is run it will write the HDF5 file,
//  and the second time it will print out what it finds.

import swarm.Globals;

class DataRecord {
        public int count;
        public int step;
        // remove "public" below if you want to serialize this `shallow'
        int valArray[];

        DataRecord (int count, int step) {
            valArray = new int[count];

            valArray[0] = 0;
            for (int i = 1; i < count; i++)
                valArray[i] = valArray[i - 1] + step;
            
            this.count = count;
            this.step = step;
        }
 	DataRecord (){
	}


   }


public class InnerClassHDFDemo {

    InnerClassHDFDemo () {
    }

    void test () {
        DataRecord dataRecord;

        dataRecord =
            (DataRecord) Globals.env.hdf5AppArchiver.getObject ("data");

        if (dataRecord == null)
            {
                dataRecord = new DataRecord (10, 2);
                // "Deep" or "Shallow"
                Globals.env.hdf5AppArchiver.putShallow$object ("data",
                                                               dataRecord);
            }
        else
            {

                System.out.println ("count: " + dataRecord.count);
                System.out.println ("step: " + dataRecord.step);

                // valArray will be null in case of shallow serialization
                if (dataRecord.valArray != null)
                    {
                        int lastIndex = dataRecord.count - 1;
                        int lastVal = dataRecord.valArray[lastIndex];
                        
                        System.out.println ("valArray[9]: " + lastVal);
                    }
            }
    }

    static void main (String args[]) {
        Globals.env.initSwarm ("InnerClassHDFDemo", "0.0",
                               "bug-swarm@swarm.org",
                               args);
        
        InnerClassHDFDemo demo = new InnerClassHDFDemo ();
        demo.test ();
    }
}

