MnaIO
Namespace: MNALIB · Library: MNA Library
#include <mna/mna_io.h>
class MNALIB::MnaIO
Read/write MNA project files (.mna = JSON, .mnx = CBOR with "MNX1" magic header).
src/examples/ex_mna/main.cpp
MnaProject project;
project.name = "ex_mna";
project.subjects.append(subject);
project.pipeline = graph.nodes();
const QString jsonPath = dir.filePath("pipeline.mna"); // UTF-8 JSON
const QString cborPath = dir.filePath("pipeline.mnx"); // CBOR with an "MNX1" magic
const bool saved = MnaIO::write(project, jsonPath) && MnaIO::write(project, cborPath);
const MnaProject fromJson = MnaIO::read(jsonPath);
const MnaProject fromCbor = MnaIO::read(cborPath);
Static Methods
read(path)
Read an MNA project from file.
Dispatches by extension.
Parameters:
- path : const QString & Path to the .mna or .mnx file.
Returns:
- MnaProject — The deserialized
MnaProject.
write(project, path)
Write an MNA project to file.
Dispatches by extension.
Parameters:
-
project : const MnaProject & The project to write.
-
path : const QString & Path to the .mna or .mnx file.
Returns:
- bool — True if successful.
Example
- Full source:
src/examples/ex_mna/main.cpp - Build target:
ex_mna(runs under CTest)
Used in examples
ex_mna
MNA library: register operations, build and run a graph, bind parameters and save a project.
src/examples/ex_mna/main.cpp, line 216
project.pipeline = graph.nodes();
const QString jsonPath = dir.filePath("pipeline.mna"); // UTF-8 JSON
const QString cborPath = dir.filePath("pipeline.mnx"); // CBOR with an "MNX1" magic
const bool saved = MnaIO::write(project, jsonPath) && MnaIO::write(project, cborPath);
const MnaProject fromJson = MnaIO::read(jsonPath);
const MnaProject fromCbor = MnaIO::read(cborPath);
ok &= expect(saved && fromJson.name == "ex_mna" && fromCbor.subjects.size() == 1 && fromCbor.subjects[0].sessions[0].recordings[0].files[0].path == raw.path && fromJson.pipeline[2].verification.postResults.first().message == verdict.message && report.language == "python" && fromJson.pipeline.size() == 3 && fromCbor.pipeline.size() == 3 && fromCbor.pipeline[1].inputs[0].sourceNodeId == "source" && fromJson.pipeline[1].attributes.value("gain").toDouble() == 2.0,
"MnaIO round-trips the 3-node pipeline through .mna and .mnx");
Authors of this file
- Christoph Dinh <christoph.dinh@mne-cpp.org>