Cheetah Software  1.0
Utilities_print.h File Reference
#include <stdarg.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include "cppTypes.h"
+ Include dependency graph for Utilities_print.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  PrintColor {
  PrintColor::Default, PrintColor::Red, PrintColor::Green, PrintColor::Yellow,
  PrintColor::Blue, PrintColor::Magenta, PrintColor::Cyan
}
 

Functions

template<typename T >
std::string pretty_string (T vv)
 
template<typename T >
void pretty_print (DMat< T > const &mm, std::ostream &os, std::string const &title, std::string const &prefix="", bool vecmode=false, bool nonl=false)
 
template<typename T >
void pretty_print (Quat< T > const &vv, std::ostream &os, std::string const &title, std::string const &prefix="", bool nonl=false)
 
template<typename T >
void pretty_print (DVec< T > const &vv, std::ostream &os, std::string const &title, std::string const &prefix="", bool nonl=false)
 
template<typename T >
void pretty_print (D3Mat< T > const &vv, std::ostream &os, std::string const &title, std::string const &prefix="", bool nonl=false)
 
template<typename T >
void pretty_print (Mat3< T > const &vv, std::ostream &os, std::string const &title, std::string const &prefix="", bool nonl=false)
 
template<typename T >
void pretty_print (Mat6< T > const &vv, std::ostream &os, std::string const &title, std::string const &prefix="", bool nonl=false)
 
template<typename T >
void pretty_print (SVec< T > const &vv, std::ostream &os, std::string const &title, std::string const &prefix="", bool nonl=false)
 
template<typename T >
void pretty_print (Vec3< T > const &vv, std::ostream &os, std::string const &title, std::string const &prefix="", bool nonl=false)
 
template<typename T >
void pretty_print (Vec2< T > const &vv, std::ostream &os, std::string const &title, std::string const &prefix="", bool nonl=false)
 
template<typename T >
void pretty_print (const std::vector< T > &_vec, const char *title)
 
template<typename T >
void pretty_print (const T *_vec, const char *title, size_t size)
 
void printf_color (PrintColor color, const char *fmt,...)
 
void fprintf_color (PrintColor color, FILE *stream, const char *fmt,...)
 

Enumeration Type Documentation

enum PrintColor
strong
Enumerator
Default 
Red 
Green 
Yellow 
Blue 
Magenta 
Cyan 

Definition at line 123 of file Utilities_print.h.

Function Documentation

void fprintf_color ( PrintColor  color,
FILE *  stream,
const char *  fmt,
  ... 
)

Definition at line 13 of file Utilities_print.cpp.

13  {
14  auto color_id = (uint32_t)color;
15  if (color_id) fprintf(stream, "\033[1;%dm", (uint32_t)color + 30);
16  va_list args;
17  va_start(args, fmt);
18  vfprintf(stream, fmt, args);
19  va_end(args);
20  fprintf(stream, "\033[0m");
21 }

+ Here is the caller graph for this function:

template<typename T >
void pretty_print ( DMat< T > const &  mm,
std::ostream &  os,
std::string const &  title,
std::string const &  prefix = "",
bool  vecmode = false,
bool  nonl = false 
)

Definition at line 24 of file Utilities_print.h.

References pretty_string().

26  {
27  char const *nlornot("\n");
28  if (nonl) {
29  nlornot = "";
30  }
31  if (!title.empty()) {
32  os << title << nlornot;
33  }
34  if ((mm.rows() <= 0) || (mm.cols() <= 0)) {
35  os << prefix << " (empty)" << nlornot;
36  } else {
37  if (vecmode) {
38  if (!prefix.empty()) os << prefix;
39  for (int ir(0); ir < mm.rows(); ++ir) {
40  os << pretty_string(mm.coeff(ir, 0));
41  }
42  os << nlornot;
43 
44  } else {
45  for (int ir(0); ir < mm.rows(); ++ir) {
46  if (!prefix.empty()) os << prefix;
47  for (int ic(0); ic < mm.cols(); ++ic) {
48  os << pretty_string(mm.coeff(ir, ic));
49  }
50  os << nlornot;
51  }
52  }
53  }
54 }
std::string pretty_string(T vv)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
void pretty_print ( Quat< T > const &  vv,
std::ostream &  os,
std::string const &  title,
std::string const &  prefix = "",
bool  nonl = false 
)

Definition at line 57 of file Utilities_print.h.

References pretty_print().

58  {
59  pretty_print((DMat<T> const &)vv, os, title, prefix, true, nonl);
60 }
typename Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > DMat
Definition: cppTypes.h:106
void pretty_print(DMat< T > const &mm, std::ostream &os, std::string const &title, std::string const &prefix="", bool vecmode=false, bool nonl=false)

+ Here is the call graph for this function:

template<typename T >
void pretty_print ( DVec< T > const &  vv,
std::ostream &  os,
std::string const &  title,
std::string const &  prefix = "",
bool  nonl = false 
)

Definition at line 63 of file Utilities_print.h.

References pretty_print().

64  {
65  pretty_print((DMat<T> const &)vv, os, title, prefix, true, nonl);
66 }
typename Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > DMat
Definition: cppTypes.h:106
void pretty_print(DMat< T > const &mm, std::ostream &os, std::string const &title, std::string const &prefix="", bool vecmode=false, bool nonl=false)

+ Here is the call graph for this function:

template<typename T >
void pretty_print ( D3Mat< T > const &  vv,
std::ostream &  os,
std::string const &  title,
std::string const &  prefix = "",
bool  nonl = false 
)

Definition at line 69 of file Utilities_print.h.

References pretty_print().

71  {
72  pretty_print((DMat<T> const &)vv, os, title, prefix, false, nonl);
73 }
typename Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > DMat
Definition: cppTypes.h:106
void pretty_print(DMat< T > const &mm, std::ostream &os, std::string const &title, std::string const &prefix="", bool vecmode=false, bool nonl=false)

+ Here is the call graph for this function:

template<typename T >
void pretty_print ( Mat3< T > const &  vv,
std::ostream &  os,
std::string const &  title,
std::string const &  prefix = "",
bool  nonl = false 
)

Definition at line 76 of file Utilities_print.h.

References pretty_print().

77  {
78  pretty_print((DMat<T> const &)vv, os, title, prefix, false, nonl);
79 }
typename Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > DMat
Definition: cppTypes.h:106
void pretty_print(DMat< T > const &mm, std::ostream &os, std::string const &title, std::string const &prefix="", bool vecmode=false, bool nonl=false)

+ Here is the call graph for this function:

template<typename T >
void pretty_print ( Mat6< T > const &  vv,
std::ostream &  os,
std::string const &  title,
std::string const &  prefix = "",
bool  nonl = false 
)

Definition at line 82 of file Utilities_print.h.

References pretty_print().

83  {
84  pretty_print((DMat<T> const &)vv, os, title, prefix, false, nonl);
85 }
typename Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > DMat
Definition: cppTypes.h:106
void pretty_print(DMat< T > const &mm, std::ostream &os, std::string const &title, std::string const &prefix="", bool vecmode=false, bool nonl=false)

+ Here is the call graph for this function:

template<typename T >
void pretty_print ( SVec< T > const &  vv,
std::ostream &  os,
std::string const &  title,
std::string const &  prefix = "",
bool  nonl = false 
)

Definition at line 88 of file Utilities_print.h.

References pretty_print().

89  {
90  pretty_print((DMat<T> const &)vv, os, title, prefix, true, nonl);
91 }
typename Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > DMat
Definition: cppTypes.h:106
void pretty_print(DMat< T > const &mm, std::ostream &os, std::string const &title, std::string const &prefix="", bool vecmode=false, bool nonl=false)

+ Here is the call graph for this function:

template<typename T >
void pretty_print ( Vec3< T > const &  vv,
std::ostream &  os,
std::string const &  title,
std::string const &  prefix = "",
bool  nonl = false 
)

Definition at line 94 of file Utilities_print.h.

References pretty_print().

95  {
96  pretty_print((DMat<T> const &)vv, os, title, prefix, true, nonl);
97 }
typename Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > DMat
Definition: cppTypes.h:106
void pretty_print(DMat< T > const &mm, std::ostream &os, std::string const &title, std::string const &prefix="", bool vecmode=false, bool nonl=false)

+ Here is the call graph for this function:

template<typename T >
void pretty_print ( Vec2< T > const &  vv,
std::ostream &  os,
std::string const &  title,
std::string const &  prefix = "",
bool  nonl = false 
)

Definition at line 100 of file Utilities_print.h.

References pretty_print().

101  {
102  pretty_print((DMat<T> const &)vv, os, title, prefix, true, nonl);
103 }
typename Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > DMat
Definition: cppTypes.h:106
void pretty_print(DMat< T > const &mm, std::ostream &os, std::string const &title, std::string const &prefix="", bool vecmode=false, bool nonl=false)

+ Here is the call graph for this function:

template<typename T >
void pretty_print ( const std::vector< T > &  _vec,
const char *  title 
)

Definition at line 106 of file Utilities_print.h.

106  {
107  printf("%s: ", title);
108  for (size_t i(0); i < _vec.size(); ++i) {
109  printf("% 6.4f, \t", _vec[i]);
110  }
111  printf("\n");
112 }
template<typename T >
void pretty_print ( const T *  _vec,
const char *  title,
size_t  size 
)

Definition at line 115 of file Utilities_print.h.

115  {
116  printf("%s: ", title);
117  for (size_t i(0); i < size; ++i) {
118  printf("% 6.4f, \t", _vec[i]);
119  }
120  printf("\n");
121 }
template<typename T >
std::string pretty_string ( vv)

Definition at line 14 of file Utilities_print.h.

14  {
15  static int const buflen(32);
16  static char buf[buflen];
17  memset(buf, 0, sizeof(buf));
18  snprintf(buf, buflen - 1, "% 6.6f ", vv);
19  std::string str(buf);
20  return str;
21 }

+ Here is the caller graph for this function:

void printf_color ( PrintColor  color,
const char *  fmt,
  ... 
)

Definition at line 3 of file Utilities_print.cpp.

3  {
4  auto color_id = (uint32_t)color;
5  if (color_id) printf("\033[1;%dm", (uint32_t)color + 30);
6  va_list args;
7  va_start(args, fmt);
8  vprintf(fmt, args);
9  va_end(args);
10  printf("\033[0m");
11 }

+ Here is the caller graph for this function: