@@ -0,0 +1,2100 @@
+package de.jangobrick.scratchlib.objects;%0A%0Aimport java.io.IOException;%0A%0Aimport de.jangobrick.scratchlib.writer.ScratchOutputStream;%0A%0A%0A/**%0A * Main container for project data: both the project's information and its stage%0A * are wrapped in this structure.%0A * %0A * %3Cp%3E%0A * Object stores have one root object, followed by zero or more reference types%0A * required by that root object. In other words, they wrap exactly one main%0A * object, but in a way that flattens its structure.%0A * %0A * %3Cp%3E%0A * They start with the header: %22ObjS%22 + 0x01 + %22Stch%22 + 0x01. Next, there is a%0A * 32-bit integer describing the store's flattened size (number of elements).%0A * Finally, the main object and its referenced objects are written out.%0A */%0Apublic class ScratchObjectStore%0A%7B%0A    private ScratchObject object;%0A%0A    /**%0A     * @param object The object contained in this store.%0A     */%0A    public ScratchObjectStore(ScratchObject object)%0A    %7B%0A        this.object = object;%0A    %7D%0A%0A    /**%0A     * @return The object contained in this store.%0A     */%0A    public ScratchObject get()%0A    %7B%0A        return object;%0A    %7D%0A%0A    /**%0A     * Changes the object contained in this store.%0A     * %0A     * @param object The new object.%0A     */%0A    public void set(ScratchObject object)%0A    %7B%0A        this.object = object;%0A    %7D%0A%0A    /**%0A     * Writes this object store to the given %7B@link ScratchOutputStream%7D.%0A     * %0A     * @param out The stream to write to.%0A     * @throws IOException%0A     */%0A    public void writeTo(ScratchOutputStream out) throws IOException%0A    %7B%0A        // create reference table%0A        ScratchReferenceTable refTable = new ScratchReferenceTable();%0A        refTable.insert(object);%0A        object.createReferences(refTable);%0A%0A        // write header%0A        out.writeString(%22ObjS%22);%0A        out.write(0x01);%0A        out.writeString(%22Stch%22);%0A        out.write(0x01);%0A%0A        // write size%0A        out.write32bitUnsignedInt(refTable.size());%0A%0A        // write objects from reference table%0A        for (ScratchObject object : refTable) %7B%0A            object.writeTo(out, refTable);%0A        %7D%0A%0A        out.flush();%0A    %7D%0A%7D%0A

Add ScratchObjectStore