The oops/r3root.h base class defines three methods which can be used for saving and loading objects.
To save an object to a file:
#include <oops/r3file.h>
R3OBJ *file;
file = R3New(R3CLID_FILE,
R3T(R3FIA_FileName, "myfile"),
R3T(R3FIA_Mode, "w+"),
R3TAG_END);
ok = R3ObjectSave(obj,
R3T(R3RA_FileObject, file),
R3TAG_END);
Note that R3ObjectSave() is a shield function that sends R3RM_WRITE method to the object.
To load an object:
R3INT error = 0;
file = R3New(R3CLID_FILE,
R3T(R3FIA_FileName, "myfile"),
R3T(R3FIA_Mode, "r"),
R3TAG_END);
obj = R3ObjectLoad(NULL,
R3T(R3RA_FileObject, file),
R3T(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.