CortidQCT  1.2.2.52
MatrixIO.h
Go to the documentation of this file.
1 
13 #pragma once
14 
15 #include <Eigen/Core>
16 
17 #include <iostream>
18 
19 namespace CortidQCT {
20 
24 template <class MatrixType> struct MartrixIOWrapper {
25 
26  inline MartrixIOWrapper(Eigen::MatrixBase<MatrixType> &matrix)
27  : matrix_(matrix.derived()) {}
28 
30  friend inline std::ostream &operator<<(std::ostream &os,
31  MartrixIOWrapper const &wrapper) {
32  return os << wrapper.matrix_;
33  }
34 
36  friend inline std::istream &operator>>(std::istream &is,
37  MartrixIOWrapper &&wrapper) {
38 
39  for (auto i = 0; i < wrapper.matrix_.rows(); ++i)
40  for (auto j = 0; j < wrapper.matrix_.cols(); ++j)
41  is >> wrapper.matrix_(i, j);
42 
43  return is;
44  }
45 
46 private:
47  MatrixType &matrix_;
48 };
49 
56 template <class MatrixType>
57 inline MartrixIOWrapper<MatrixType> io(Eigen::MatrixBase<MatrixType> &matrix) {
58  return MartrixIOWrapper<MatrixType>(matrix);
59 }
60 
67 template <class MatrixType>
69 io(Eigen::MatrixBase<MatrixType> const &matrix) {
71 }
72 
73 } // namespace CortidQCT
Name namespace for CortidQCT library.
Definition: CortidQCT.h:23
MartrixIOWrapper< MatrixType > io(Eigen::MatrixBase< MatrixType > &matrix)
Definition: MatrixIO.h:57
friend std::ostream & operator<<(std::ostream &os, MartrixIOWrapper const &wrapper)
operator<< overload for io wrapped matrices
Definition: MatrixIO.h:30
friend std::istream & operator>>(std::istream &is, MartrixIOWrapper &&wrapper)
operator>> overload for io wrapped matrices
Definition: MatrixIO.h:36
Wrapper for Eigen matrices to support IO.
Definition: MatrixIO.h:24