cheshirekow  v0.1.0
ostream.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of fiber.
5  *
6  * fiber is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * fiber is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with fiber. If not, see <http://www.gnu.org/licenses/>.
18  */
25 #ifndef FIBER_OSTREAM_H_
26 #define FIBER_OSTREAM_H_
27 
28 #include <iostream>
29 #include <cstdio>
30 #include <iomanip>
31 #include <sstream>
32 
33 
34 namespace fiber {
35 
36 template <typename Scalar, class Mat>
37 std::ostream& operator<<(std::ostream& out, _RValue<Scalar, Mat> const& M) {
38  std::stringstream strm;
39  int max_len = 0;
40  for (int i = 0; i < M.rows(); i++) {
41  for (int j = 0; j < M.cols(); j++) {
42  strm.str("");
43  strm << M(i, j);
44  if (max_len < strm.str().size()) max_len = strm.str().size();
45  }
46  }
47 
48  out << std::setiosflags(std::ios::left);
49  for (int i = 0; i < M.rows(); i++) {
50  for (int j = 0; j < M.cols(); j++) {
51  strm.str("");
52  strm << M(i, j);
53  out << std::setw(max_len) << strm.str() << " ";
54  }
55  if (i < M.rows() - 1) {
56  out << "\n";
57  }
58  }
59 
60  return out;
61 }
62 
63 } // namespace fiber
64 
65 
66 #endif // FIBER_OSTREAM_H_