MatFile::StructNode

 

class MatFile::StructNode

 

StructNode is a builder for creating and writing a 1×1 MATLAB struct backed by storage owned by the node itself. It keeps all field data alive until the node is written to the associated MatFile, which ensures that the MatIO library receives valid pointers during serialization. It supports scalar fields, string fields, numeric and complex matrices, and nested child structs.

 

 

Public Member List


 

StructNode()

Default constructor.

 


 

StructNode(MatFile& mf, const char *name, const Vector<String>& fieldNames)

Constructor with file association and predefined fields.

 


 

StructNode(const StructNode&)

Copy operations are disabled to avoid accidental sharing of owned matvar_t*.

 


 

StructNode(StructNode&& other)

Move operations transfer ownership of the underlying matvar_t* and backing storage.

 


 

~StructNode()

Frees the internal matvar_t* unless it has been transferred to the file by Write.

 

 

Constructor Detail

 

void Create(const char *name, const Vector<String>& fieldNames)

Creates or recreates a struct with the specified name and fields.

 


 

void Write(const char *field, int v)

Adds an integer scalar field to the struct.

 


 

void Write(const char *field, double v)

Adds a double scalar field to the struct.

 


 

void Write(const char *field, const String& s)

Adds a character vector field, stored as UTF‑8 when available or uint8 otherwise.

 


 

void WriteColMajor(const char *field, size_t rows, size_t cols, const double *colMajor)

Adds a double matrix field (column-major input).

 


 

void WriteColMajor(const char *field, size_t rows, size_t cols, const int *colMajor)

Adds an integer matrix field (column-major input).

 


 

StructNode& AddChild(const char *fieldName, const Vector<String>& childFields)

Creates a child struct as a field of the current struct and returns a reference to the child for population.

 


 

void Write(matio_compression compression = MAT_COMPRESSION_NONE)

Finalizes the struct, writes it to the associated MatFile, and relinquishes ownership to MatIO.