Saving and Loading Objects

The root class defines three methods which can be used for saving and loading objects.

If you want to save an object to a file, create Realsoft3D file object and call the object to be saved with R3RM_WRITE method.

    #include <oops/r3file.h>

    R3OBJ *file;

    file = R3New(R3CLID_FILE,
                 R3FIA_FileName, "myfile",
                 R3FIA_Mode,     "w+",
                 R3TAG_END);

    ok = R3ObjectSave(obj, 
                      R3RA_FileObject, file,
                      R3TAG_END);

Again, the R3ObjectSave() is a shield function that sends R3RM_WRITE method to the object.

To load an object:

    R3INT error = 0;
    obj = R3ObjectLoad(NULL,
                       R3RA_FileObject, file,
                       R3RA_Error, &error,
                       R3TAG_END);

R3ObjectLoad() function first asks the root class to read root specific attributes, such as class identifier and version number, from the given file. When read, the root class creates the object of that class and sends the R3RM_READ method to the newly created object. The each derived class then reads the their options from the file.