mp.struct2object

mp.struct2object(s)

mp.struct2object() - Convert a struct back to the object from which it was created.

obj = mp.struct2object(s)
Input:

s (struct) – a struct of the form created by a to_struct() method, containing the data from the object plus a char array field naned class_ with the class name of the desired object, and an optional cell array field named constructor_args_ with arguments to pass to the constructor.

Output:

obj (classdef object) – an instance of the object identical to the one used to create the input struct

As of version 10.x, Octave is still not able to save and load classdef objects. To aid in creating workarounds, this function allows objects to implement the following pattern with appropriately coded to_struct() and from_struct() methods:

s = obj.to_struct();            % convert to normal struct
new_obj = mp.struct2object(s);  % convert back to classdef object
isequal(new_obj, obj)           % returns true

The to_struct() method of the object must create a struct containing all of the data in the object, plus a char array field naned class_ with the class name of the desired object, and an optional cell array field named constructor_args_ with arguments to pass to the object constructor.

The from_struct() method takes a freshly constructed object and the struct above and copies the data from the struct back to the object.

This function creates an instance of the specified class, by calling its constructor with any specified arguments, then calling its from_struct() method.