Eigen::IOFormat Class Reference

Stores a set of parameters controlling the way matrices are printed. More...

Public Member Functions

 IOFormat (int _precision=StreamPrecision, int _flags=0, const std::string &_coeffSeparator=" ", const std::string &_rowSeparator="\n", const std::string &_rowPrefix="", const std::string &_rowSuffix="", const std::string &_matPrefix="", const std::string &_matSuffix="", const char _fill=' ')
 

Public Attributes

std::string coeffSeparator
 
char fill
 
int flags
 
std::string matPrefix
 
std::string matSuffix
 
int precision
 
std::string rowPrefix
 
std::string rowSeparator
 
std::string rowSpacer
 
std::string rowSuffix
 

Detailed Description

Stores a set of parameters controlling the way matrices are printed.

List of available parameters:

  • precision number of digits for floating point values, or one of the special constants StreamPrecision and FullPrecision. The default is the special value StreamPrecision which means to use the stream's own precision setting, as set for instance using cout.precision(3). The other special value FullPrecision means that the number of digits will be computed to match the full precision of each floating-point type.
  • flags an OR-ed combination of flags, the default value is 0, the only currently available flag is DontAlignCols which allows to disable the alignment of columns, resulting in faster code.
  • coeffSeparator string printed between two coefficients of the same row
  • rowSeparator string printed between two rows
  • rowPrefix string printed at the beginning of each row
  • rowSuffix string printed at the end of each row
  • matPrefix string printed at the beginning of the matrix
  • matSuffix string printed at the end of the matrix
  • fill character printed to fill the empty space in aligned columns

Example:

std::string sep = "\n----------------------------------------\n";
m1 << 1.111111, 2, 3.33333, 4, 5, 6, 7, 8.888888, 9;
IOFormat CommaInitFmt(StreamPrecision, DontAlignCols, ", ", ", ", "", "", " << ", ";");
IOFormat CleanFmt(4, 0, ", ", "\n", "[", "]");
IOFormat OctaveFmt(StreamPrecision, 0, ", ", ";\n", "", "", "[", "]");
IOFormat HeavyFmt(FullPrecision, 0, ", ", ";\n", "[", "]", "[", "]");
std::cout << m1 << sep;
std::cout << m1.format(CommaInitFmt) << sep;
std::cout << m1.format(CleanFmt) << sep;
std::cout << m1.format(OctaveFmt) << sep;
std::cout << m1.format(HeavyFmt) << sep;
Matrix3d m1
Definition: IOFormat.cpp:2
std::string sep
Definition: IOFormat.cpp:1
Matrix< double, 3, 3 > Matrix3d
3×3 matrix of type double.
Definition: Matrix.h:502
@ StreamPrecision
Definition: IO.h:19
@ FullPrecision
Definition: IO.h:20
@ DontAlignCols
Definition: IO.h:18
IOFormat(int _precision=StreamPrecision, int _flags=0, const std::string &_coeffSeparator=" ", const std::string &_rowSeparator="\n", const std::string &_rowPrefix="", const std::string &_rowSuffix="", const std::string &_matPrefix="", const std::string &_matSuffix="", const char _fill=' ')
Definition: IO.h:56

Output:

1.11    2 3.33
   4    5    6
   7 8.89    9
----------------------------------------
 << 1.11, 2, 3.33, 4, 5, 6, 7, 8.89, 9;
----------------------------------------
[1.111,     2, 3.333]
[    4,     5,     6]
[    7, 8.889,     9]
----------------------------------------
[1.11,    2, 3.33;
    4,    5,    6;
    7, 8.89,    9]
----------------------------------------
[[1.111111,        2,  3.33333];
 [       4,        5,        6];
 [       7, 8.888888,        9]]
----------------------------------------
See also
DenseBase::format(), class WithFormat

Definition at line 53 of file IO.h.

Constructor & Destructor Documentation

◆ IOFormat()

Eigen::IOFormat::IOFormat ( int  _precision = StreamPrecision,
int  _flags = 0,
const std::string &  _coeffSeparator = " ",
const std::string &  _rowSeparator = "\n",
const std::string &  _rowPrefix = "",
const std::string &  _rowSuffix = "",
const std::string &  _matPrefix = "",
const std::string &  _matSuffix = "",
const char  _fill = ' ' 
)
inline

Default constructor, see class IOFormat for the meaning of the parameters

Definition at line 56 of file IO.h.

60  : matPrefix(_matPrefix), matSuffix(_matSuffix), rowPrefix(_rowPrefix), rowSuffix(_rowSuffix), rowSeparator(_rowSeparator),
61  rowSpacer(""), coeffSeparator(_coeffSeparator), fill(_fill), precision(_precision), flags(_flags)
62  {
63  // TODO check if rowPrefix, rowSuffix or rowSeparator contains a newline
64  // don't add rowSpacer if columns are not to be aligned
65  if((flags & DontAlignCols))
66  return;
67  int i = int(matSuffix.length())-1;
68  while (i>=0 && matSuffix[i]!='\n')
69  {
70  rowSpacer += ' ';
71  i--;
72  }
73  }
std::string rowPrefix
Definition: IO.h:75
std::string rowSuffix
Definition: IO.h:75
std::string coeffSeparator
Definition: IO.h:76
char fill
Definition: IO.h:77
std::string rowSpacer
Definition: IO.h:75
std::string matPrefix
Definition: IO.h:74
std::string rowSeparator
Definition: IO.h:75
std::string matSuffix
Definition: IO.h:74
int precision
Definition: IO.h:78
int flags
Definition: IO.h:79

Member Data Documentation

◆ coeffSeparator

std::string Eigen::IOFormat::coeffSeparator

Definition at line 76 of file IO.h.

◆ fill

char Eigen::IOFormat::fill

Definition at line 77 of file IO.h.

◆ flags

int Eigen::IOFormat::flags

Definition at line 79 of file IO.h.

◆ matPrefix

std::string Eigen::IOFormat::matPrefix

Definition at line 74 of file IO.h.

◆ matSuffix

std::string Eigen::IOFormat::matSuffix

Definition at line 74 of file IO.h.

◆ precision

int Eigen::IOFormat::precision

Definition at line 78 of file IO.h.

◆ rowPrefix

std::string Eigen::IOFormat::rowPrefix

Definition at line 75 of file IO.h.

◆ rowSeparator

std::string Eigen::IOFormat::rowSeparator

Definition at line 75 of file IO.h.

◆ rowSpacer

std::string Eigen::IOFormat::rowSpacer

Definition at line 75 of file IO.h.

◆ rowSuffix

std::string Eigen::IOFormat::rowSuffix

Definition at line 75 of file IO.h.


The documentation for this class was generated from the following file: