27 #ifndef INTERNAL_CLASSES_IOMANIP_H_
28 #define INTERNAL_CLASSES_IOMANIP_H_
46 std::ostringstream ostr;
49 std::vector<std::string> vstr;
52 for (
idx i = 0; i < static_cast<idx>(_A.rows()); ++i)
55 j < static_cast<idx>(_A.cols()); ++j)
59 ostr.str(std::string {});
62 double re =
static_cast<cplx>(_A(i, j)).real();
63 double im =
static_cast<cplx>(_A(i, j)).imag();
65 if (std::abs(re) < _chop && std::abs(im) < _chop)
70 vstr.push_back(ostr.str());
72 else if (std::abs(re) < _chop)
75 vstr.push_back(ostr.str() +
"i");
77 else if (std::abs(im) < _chop)
80 vstr.push_back(ostr.str() +
" ");
87 strA += (im > 0 ?
" + " :
" - ");
89 ostr.str(std::string());
99 std::vector<idx> maxlengthcols(_A.cols(), 0);
101 for (
idx i = 0; i < static_cast<idx>(_A.rows());
104 j < static_cast<idx>(_A.cols()); ++j)
105 if (vstr[i * _A.cols() + j].size() > maxlengthcols[j])
106 maxlengthcols[j] = vstr[i * _A.cols() + j].size();
109 for (
idx i = 0; i < static_cast<idx>(_A.rows()); ++i)
111 _os << std::setw(static_cast<int>(maxlengthcols[0])) << std::right
112 << vstr[i * _A.cols()];
115 j < static_cast<idx>(_A.cols()); ++j)
116 _os << std::setw(static_cast<int>(maxlengthcols[j] + 2))
117 << std::right << vstr[i * _A.cols() + j];
119 if (i < static_cast<idx>(_A.rows()) - 1)
131 template<
typename InputIterator>
138 const std::string& separator,
139 const std::string& start =
"[",
140 const std::string& end =
"]") :
143 _separator{separator},
157 std::ostream&
display(std::ostream& os)
const override
162 for (
auto it = _first; it !=
_last; ++it)
175 template<
typename Po
interType>
178 const PointerType*
_p;
183 const std::string& separator,
184 const std::string& start =
"[",
185 const std::string& end =
"]") :
188 _separator{separator},
200 std::ostream&
display(std::ostream& os)
const override
204 for (
idx i = 0; i < _n - 1; ++i)
205 os << _p[i] << _separator;
221 template<
typename Derived>
224 _A{A.template cast<cplx>()},
231 _A{cmat::Zero(1, 1)}, _chop{
chop}
238 std::ostream&
display(std::ostream& os)
const override
constexpr double chop
Used in qpp::disp() for setting to zero numbers that have their absolute value smaller than qpp::chop...
Definition: constants.h:65
std::string _start
Definition: iomanip.h:180
IOManipEigen(const Eigen::MatrixBase< Derived > &A, double chop=qpp::chop)
Definition: iomanip.h:222
std::string _separator
Definition: iomanip.h:135
double _chop
Definition: iomanip.h:218
std::string _separator
Definition: iomanip.h:180
cmat _A
Definition: iomanip.h:217
std::ostream & display(std::ostream &os) const override
Must be overridden by all derived classes.
Definition: iomanip.h:157
Definition: iomanip.h:132
IOManipPointer & operator=(const IOManipPointer &)=default
Quantum++ main namespace.
Definition: codes.h:30
std::string _start
Definition: iomanip.h:135
std::string _end
Definition: iomanip.h:135
IOManipRange & operator=(const IOManipRange &)=default
std::ostream & display(std::ostream &os) const override
Must be overridden by all derived classes.
Definition: iomanip.h:200
std::string _end
Definition: iomanip.h:180
InputIterator _last
Definition: iomanip.h:134
IOManipPointer(const PointerType *p, idx n, const std::string &separator, const std::string &start="[", const std::string &end="]")
Definition: iomanip.h:182
Abstract class (interface) that mandates the definition of virtual std::ostream& display(std::ostream...
Definition: idisplay.h:43
Definition: iomanip.h:215
std::complex< double > cplx
Complex number in double precision.
Definition: types.h:51
IOManipRange(InputIterator first, InputIterator last, const std::string &separator, const std::string &start="[", const std::string &end="]")
Definition: iomanip.h:137
IOManipEigen(const cplx z, double chop=qpp::chop)
Definition: iomanip.h:230
Definition: iomanip.h:176
std::ostream & display(std::ostream &os) const override
Must be overridden by all derived classes.
Definition: iomanip.h:238
const PointerType * _p
Definition: iomanip.h:178
Eigen::MatrixXcd cmat
Complex (double precision) dynamic Eigen matrix.
Definition: types.h:66
std::ostream & _display_impl(const T &_A, std::ostream &_os, double _chop=qpp::chop) const
Definition: iomanip.h:42
std::size_t idx
Non-negative integer index.
Definition: types.h:36
InputIterator _first
Definition: iomanip.h:134
idx _n
Definition: iomanip.h:179