25 Logger(std::ostream & os, std::string name, std::uint32_t flags = 0) : flags_(flags), iter_(-1), name_(name), os_(&os)
33 Logger & setFlag(std::uint32_t flag,
bool add =
true);
36 Logger & setOutputStream(std::ostream & os);
39 template<
typename... Args>
40 void comment(std::uint32_t flag, Args &&... args)
const;
42 void startIter(
int i);
48 template<
typename... Args>
49 void log(std::uint32_t flag, Args &&... args)
const;
54 Logger subLog(
const std::string & name)
const;
68 std::ostream & logIter()
const;
70 template<
bool b,
typename T,
typename... Args>
71 void log_(
const std::string & valName,
const T & val, Args &&... args)
const;
73 template<
bool b,
typename T>
74 void log_(
const T &)
const;
81 template<
bool b,
typename Derived>
82 void logVal_(
const std::string & valName,
const Eigen::EigenBase<Derived> & M)
const;
84 template<
bool b,
typename T>
85 void logVal_(
const std::string & valName,
const std::vector<T> & v)
const;
89 typename std::enable_if<(!internal::derives_from<Other, Eigen::EigenBase>()),
int>::type = 0>
90 void logVal_(
const std::string & valName,
const Other & val)
const;
99 inline std::ostream & Logger::logIter<true>()
const
101 *os_ << name_ <<
"(" << iter_ + 1 <<
")";
106 inline std::ostream & Logger::logIter<false>()
const
108 *os_ << name_ <<
"Data";
112 template<
typename... Args>
115 if(flag & flags_) ((*os_ <<
"% ") << ... << args) <<
"\n";
118 template<
typename... Args>
119 inline void Logger::log(std::uint32_t flag, Args &&... args)
const
124 log_<false>(std::forward<Args>(args)...);
126 log_<true>(std::forward<Args>(args)...);
130 template<
bool b,
typename T,
typename... Args>
131 inline void Logger::log_(
const std::string & valName,
const T & val, Args &&... args)
const
133 logVal_<b>(valName, val);
134 log_<b>(std::forward<Args>(args)...);
137 template<
bool,
typename T>
138 inline void Logger::log_(
const T &)
const
143 template<
bool b,
typename Derived>
144 inline void Logger::logVal_(
const std::string & valName,
const Eigen::EigenBase<Derived> & M)
const
146 logIter<b>() <<
"." << valName <<
" = " << (toMatlab)M.const_derived() <<
";\n";
149 template<
bool b,
typename T>
150 inline void Logger::logVal_(
const std::string & valName,
const std::vector<T> & v)
const
152 if(v.empty())
return;
153 auto & line = logIter<b>() <<
"." << valName <<
" = [";
154 for(
size_t i = 0; i < v.size() - 1; ++i)
156 line << internal::cast_as_underlying_if_enum<T>{}(v[i]) <<
", ";
158 line << internal::cast_as_underlying_if_enum<T>{}(v.back()) <<
"];\n";
161 template<bool b, typename Other, typename std::enable_if<(!internal::derives_from<Other, Eigen::EigenBase>()),
int>::type>
162 inline void Logger::logVal_(
const std::string & valName,
const Other & val)
const
164 logIter<b>() <<
"." << valName <<
" = " << val <<
";\n";