TDMS
Time Domain Maxwell Solver
All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
input_matrices.h
Go to the documentation of this file.
1/**
2 * @file input_matrices.h
3 * @brief Class handling the input matrices that are read in from the input file
4 */
5#pragma once
6
7#include <string>
8
10#include "mat_io.h"
11#include "matrix_collection.h"
12
13/** @brief Allows us to handle the MATLAB arrays from the input file in a
14 * human-readable format */
16private:
17 // Pointers to arrays in C++ that will be populated by the MATLAB matrices
18 // (default to nullptrs)
19 const mxArray *matrix_pointers[NMATRICES];
20
21 /**
22 * @brief Assigns pointers to the matrices in an input file, based on those we
23 * are expecting to recieve.
24 *
25 * MatrixCollection is a list of names of matrices we expect to be in the
26 * MatFileMatrixCollection, based on whether we are reading from a gridfile,
27 * input_file without a gridfile, or an input file that came with a gridfile.
28 *
29 * @param expected The matrices we expect to be able to pull from actual
30 * @param actual The matrices saved in an input file, to be loaded
31 */
34
35 /**
36 * @brief Validates that the MATLAB arrays that we are pointing to are of the
37 * type that we expect.
38 */
40
41public:
42 /*! Name of the input file from which MATLAB objects were extracted. Akward
43 * middle-child between full removal of MATLAB and the slow removal of class
44 * dependencies */
45 std::string input_filename;
46
47 InputMatrices() = default;
48
49
50 /**
51 * @brief Fetches the index of matrix_name in the
52 * tdms_matrix_names::matrixnames array
53 *
54 * @param matrix_name The matrix name to locate
55 * @return int The corresponding index
56 */
57 int index_from_matrix_name(const std::string &matrix_name);
58
59 /**
60 * @brief Fetch a (pointer to a) MATLAB input matrix by index reference.
61 *
62 * Index-references can be computed through index_from_matrix_name. They are
63 * ordered in the same way as the names in tdms_matrix_names::matrixnames.
64 *
65 * @param index The index to fetch
66 * @return const mxArray* Pointer to the corresponding MATLAB array
67 */
68 const mxArray *operator[](int index) { return matrix_pointers[index]; }
69 /**
70 * @brief Fetch a (pointer to a) MATLAB input matrix by name.
71 *
72 * @param matrix_name Name of the matrix to fetch the pointer to
73 * @return const mxArray* Pointer to the corresponding MATLAB array
74 */
75 const mxArray *operator[](const std::string &matrix_name) {
76 return matrix_pointers[index_from_matrix_name(matrix_name)];
77 }
78
79 /**
80 * @brief Set the matrix pointer with the given index.
81 *
82 * Not recommended unless you're certain you are setting the correct array
83 * pointer! Use the overload which takes the array name as an input if you are
84 * uncertain you are setting the correct pointer.
85 *
86 * This function mainly sees use during destruction (and output writing) when
87 * we just want to iterate over all the matrices that we are dealing with.
88 *
89 * @param index The index in matrix_pointers to set
90 * @param new_ptr The address we want to assign
91 */
92 void set_matrix_pointer(int index, mxArray *new_ptr) {
93 matrix_pointers[index] = new_ptr;
94 }
95 /**
96 * @brief Set the pointer to the named matrix
97 *
98 * @param matrix_name The name of the matrix that we want to set the pointer
99 * to
100 * @param new_ptr The address we want to assign
101 */
102 void set_matrix_pointer(const std::string &matrix_name, mxArray *new_ptr) {
103 set_matrix_pointer(index_from_matrix_name(matrix_name), new_ptr);
104 }
105
106 /**
107 * @brief Open the input mat file, load the matrices, and setup pointers to
108 * the matrices
109 *
110 * @param mat_filename The MATLAB filename
111 */
112 void set_from_input_file(const char *mat_filename);
113 /**
114 * @brief Open the input mat file, load the matrices, and setup pointers to
115 * the matrices
116 *
117 * @param mat_filename The MATLAB filename
118 * @param gridfile The additional gridfile
119 */
120 void set_from_input_file(const char *mat_filename, const char *gridfile);
121};
Allows us to handle the MATLAB arrays from the input file in a human-readable format.
Definition input_matrices.h:15
void set_from_input_file(const char *mat_filename)
Open the input mat file, load the matrices, and setup pointers to the matrices.
Definition input_matrices.cpp:26
const mxArray * operator[](const std::string &matrix_name)
Fetch a (pointer to a) MATLAB input matrix by name.
Definition input_matrices.h:75
void validate_assigned_pointers()
Validates that the MATLAB arrays that we are pointing to are of the type that we expect.
Definition input_matrices.cpp:126
void set_matrix_pointer(const std::string &matrix_name, mxArray *new_ptr)
Set the pointer to the named matrix.
Definition input_matrices.h:102
int index_from_matrix_name(const std::string &matrix_name)
Fetches the index of matrix_name in the tdms_matrix_names::matrixnames array.
Definition input_matrices.cpp:15
const mxArray * operator[](int index)
Fetch a (pointer to a) MATLAB input matrix by index reference.
Definition input_matrices.h:68
void assign_matrix_pointers(MatrixCollection &expected, MatFileMatrixCollection &actual)
Assigns pointers to the matrices in an input file, based on those we are expecting to recieve.
Definition input_matrices.cpp:105
void set_matrix_pointer(int index, mxArray *new_ptr)
Set the matrix pointer with the given index.
Definition input_matrices.h:92
std::string input_filename
Definition input_matrices.h:45
Definition matrix_collection.h:48
Definition matrix_collection.h:15
Constant values associated with the format of the input and output files and matrices.
Includes MATLAB headers for I/O.
A collection of named MATLAB matrices.