blob: e763ed5ec1fe3c05bc057d18b910152ad23fe866 [file] [log] [blame]
Brian Silvermanfd5e2a32014-02-22 20:02:39 -08001#ifndef AOS_COMMON_LOGGING_MATRIX_LOGGING_H_
2#define AOS_COMMON_LOGGING_MATRIX_LOGGING_H_
3
4#include <string>
Brian Silvermancb5da1f2015-12-05 22:19:58 -05005#include <functional>
Brian Silvermanfd5e2a32014-02-22 20:02:39 -08006
7#include "Eigen/Dense"
8
Brian Silvermancb5da1f2015-12-05 22:19:58 -05009#include "aos/common/logging/interface.h"
Brian Silvermanfd5e2a32014-02-22 20:02:39 -080010#include "aos/common/die.h"
Brian Silvermancb5da1f2015-12-05 22:19:58 -050011#include "aos/common/queue_primitives.h"
Brian Silvermanfd5e2a32014-02-22 20:02:39 -080012
13namespace aos {
14namespace logging {
15
16// Logs the contents of a matrix and a constant string.
17// matrix must be an instance of an Eigen matrix (or something similar).
Brian Silvermancb5da1f2015-12-05 22:19:58 -050018#define LOG_MATRIX(level, message, matrix) \
19 do { \
20 static const ::std::string kAosLoggingMessage( \
21 LOG_SOURCENAME ": " STRINGIFY(__LINE__) ": " message); \
22 ::aos::logging::DoLogMatrixTemplated(level, kAosLoggingMessage, matrix); \
23 /* so that GCC knows that it won't return */ \
24 if (level == FATAL) { \
25 ::aos::Die("DoLogStruct(FATAL) fell through!!!!!\n"); \
26 } \
Brian Silvermanfd5e2a32014-02-22 20:02:39 -080027 } while (false)
28
29template <class T>
Brian Silvermancb5da1f2015-12-05 22:19:58 -050030void DoLogMatrixTemplated(log_level level, const ::std::string &message,
31 const T &matrix) {
32 static_assert(!T::IsRowMajor, "we only handle column-major storage");
33 internal::DoLogMatrix(level, message, TypeID<typename T::Scalar>::id,
34 matrix.rows(), matrix.cols(), matrix.data(), 1);
35}
Brian Silvermanfd5e2a32014-02-22 20:02:39 -080036
37} // namespace logging
38} // namespace aos
39
Brian Silvermanfd5e2a32014-02-22 20:02:39 -080040#endif // AOS_COMMON_LOGGING_MATRIX_LOGGING_H_