1.5.0
CCC
 
AStringable.cpp File Reference
#include "Basic/AStringable.hpp"
#include "Basic/VectorNumT.hpp"
#include "Basic/String.hpp"
#include "Basic/Utilities.hpp"
#include "Basic/OptCst.hpp"
#include <iostream>
#include <sstream>
#include <typeinfo>
#include <iomanip>
#include <stdio.h>
#include <stdarg.h>
#include <math.h>
#include <string.h>

Macros

#define CASE_DOUBLE   0
 
#define CASE_REAL   1
 
#define CASE_INT   2
 
#define CASE_COL   3
 
#define CASE_ROW   4
 
#define TRI(i)   (((i) * ((i) + 1)) / 2)
 
#define TL1(i, j)   (tl[(j)*neq+(i)-TRI(j)]) /* only for i >= j */
 
#define TL2(i, j)   (tl[TRI(i)+(j)]) /* only for i >= j */
 

Functions

static int _getColumnRank ()
 
static int _getColumnName ()
 
static int _getColumnSize ()
 
static int _getDecimalNumber ()
 
static double _getThresh ()
 
static int _getMaxNCols ()
 
static int _getMaxNRows ()
 
static int _getNBatch ()
 
static void _buildFormat (int mode)
 
std::stringstream _formatColumn (const EJustify &justify, int localSize=0)
 
String _tabPrintString (const String &string, const EJustify &justify, int localSize=0)
 
String _tabPrintDouble (double value, const EJustify &justify, int localSize=0)
 
String _tabPrintInt (int value, const EJustify &justify, int localSize=0)
 
String _tabPrintRowColumn (int icase, int value, int flagAdd)
 
String _printColumnHeader (const VectorString &colnames, int colfrom, int colto, int colSize=_getColumnSize())
 
String _printRowHeader (const VectorString &rownames, int iy, int rowSize=_getColumnSize())
 
String _printTrailer (int ncols, int nrows, int ncols_util, int nrows_util)
 
void message (const char *format,...)
 
void messageNoDiff (const char *format,...)
 
void messageFlush (const String &string)
 
void messerrFlush (const String &string)
 
void messerr (const char *format,...)
 
void mesArg (const char *title, int current, int nmax)
 
bool checkArg (const char *title, int current, int nmax)
 
void mestitle (int level, const char *format,...)
 
void mes_process (const char *string, int ntot, int iech)
 
String toTitle (int level, const char *format,...)
 
void messageAbort (const char *format,...)
 
String toMatrix (const String &title, const AMatrix &mat, bool flagOverride, bool flagSkipZero)
 
String toMatrix (const String &title, const VectorString &colnames, const VectorString &rownames, bool bycol, int nrows, int ncols, const VectorDouble &tab, bool flagOverride, bool flagSkipZero)
 
String toMatrix (const String &title, const VectorString &colnames, const VectorString &rownames, bool bycol, int nrows, int ncols, const VectorInt &tab, bool flagOverride, bool flagSkipZero)
 
String toVector (const String &title, const VectorDouble &tab, bool flagOverride)
 
String toVector (const String &title, constvect tab, bool flagOverride)
 
String toVector (const String &title, const VectorVectorDouble &tab, bool flagOverride)
 
String toVector (const String &title, const VectorString &tab, bool flagOverride)
 
String toVector (const String &title, const VectorInt &tab, bool flagOverride)
 
String toStr (const String &string, const EJustify &justify, int localSize)
 
String toDouble (double value, const EJustify &justify)
 
VectorString toVectorDouble (const VectorDouble &values, const EJustify &justify)
 
String toInt (int value, const EJustify &justify)
 
String toInterval (double zmin, double zmax)
 
void tab_prints (const char *title, const char *string, int ncol, const EJustify &justify)
 
void tab_printg (const char *title, double value, int ncol, const EJustify &justify)
 
void tab_printd (const char *title, double value, int ncol, const EJustify &justify)
 
void tab_printi (const char *title, int value, int ncol, const EJustify &justify)
 
void tab_print_rc (const char *title, int mode, int value, int ncol, const EJustify &justify)
 
void tab_print_rowname (const char *string, int taille)
 
void print_matrix (const char *title, int flag_limit, int bycol, int nx, int ny, const double *sel, const double *tab)
 
void print_matrix (const char *title, int flag_limit, const AMatrix &mat)
 
void print_trimat (const char *title, int mode, int neq, const double *tl)
 
void print_imatrix (const char *title, int flag_limit, int bycol, int nx, int ny, const double *sel, const int *tab)
 
void print_vector (const char *title, int flag_limit, int ntab, const double *tab)
 
void print_vector (const char *title, int flag_limit, int ntab, const VectorDouble &tab)
 
void print_ivector (const char *title, int flag_limit, int ntab, const int *itab)
 
void print_ivector (const char *title, int flag_limit, int ntab, const VectorInt &itab)
 

Variables

static char FORMAT [100]
 
static char DECODE [100]
 
static char TABSTR [100]
 

Macro Definition Documentation

◆ CASE_COL

#define CASE_COL   3

◆ CASE_DOUBLE

#define CASE_DOUBLE   0

◆ CASE_INT

#define CASE_INT   2

◆ CASE_REAL

#define CASE_REAL   1

◆ CASE_ROW

#define CASE_ROW   4

◆ TL1

#define TL1 (   i,
 
)    (tl[(j)*neq+(i)-TRI(j)]) /* only for i >= j */

◆ TL2

#define TL2 (   i,
 
)    (tl[TRI(i)+(j)]) /* only for i >= j */

◆ TRI

#define TRI (   i)    (((i) * ((i) + 1)) / 2)

Function Documentation

◆ _buildFormat()

static void _buildFormat ( int  mode)
static

◆ _formatColumn()

std::stringstream _formatColumn ( const EJustify &  justify,
int  localSize = 0 
)

◆ _getColumnName()

static int _getColumnName ( )
static

◆ _getColumnRank()

static int _getColumnRank ( )
static

◆ _getColumnSize()

static int _getColumnSize ( )
static

◆ _getDecimalNumber()

static int _getDecimalNumber ( )
static

◆ _getMaxNCols()

static int _getMaxNCols ( )
static

◆ _getMaxNRows()

static int _getMaxNRows ( )
static

◆ _getNBatch()

static int _getNBatch ( )
static

◆ _getThresh()

static double _getThresh ( )
static

◆ _printColumnHeader()

String _printColumnHeader ( const VectorString colnames,
int  colfrom,
int  colto,
int  colSize = _getColumnSize() 
)

◆ _printRowHeader()

String _printRowHeader ( const VectorString rownames,
int  iy,
int  rowSize = _getColumnSize() 
)

◆ _printTrailer()

String _printTrailer ( int  ncols,
int  nrows,
int  ncols_util,
int  nrows_util 
)

◆ _tabPrintDouble()

String _tabPrintDouble ( double  value,
const EJustify &  justify,
int  localSize = 0 
)

◆ _tabPrintInt()

String _tabPrintInt ( int  value,
const EJustify &  justify,
int  localSize = 0 
)

◆ _tabPrintRowColumn()

String _tabPrintRowColumn ( int  icase,
int  value,
int  flagAdd 
)

◆ _tabPrintString()

String _tabPrintString ( const String string,
const EJustify &  justify,
int  localSize = 0 
)

◆ checkArg()

bool checkArg ( const char *  title,
int  current,
int  nmax 
)

◆ mes_process()

void mes_process ( const char *  string,
int  ntot,
int  iech 
)

Conditionally print the progress of a procedure

Parameters
stringString to be printed
ntotTotal number of samples
iechRank of the current sample
Remarks
The value 'nproc' designates the quantile such that,
when changed, the printout is provoked.

◆ mesArg()

void mesArg ( const char *  title,
int  current,
int  nmax 
)

Print a standard Error Message if an argument does not lie in Interval

Parameters
titleTitle to be printed
currentCurrent value of the argument
nmaxMaximum (inclusive) possible value

◆ message()

void message ( const char *  format,
  ... 
)

Print a formatted message

Parameters
formatOutput format
...Additional arguments

◆ messageAbort()

void messageAbort ( const char *  format,
  ... 
)

Function for aborting the API

Parameters
formatFatal error format
...Additional arguments

◆ messageFlush()

void messageFlush ( const String string)

When message has been collected as a String, this function produces it out without passing through useless internal buffering

Parameters
stringString to be printed out

◆ messageNoDiff()

void messageNoDiff ( const char *  format,
  ... 
)

Print a formatted message (with "#NO_DIFF#" prefix)

Parameters
formatOutput format
...Additional arguments

◆ messerr()

void messerr ( const char *  format,
  ... 
)

Print Error message

Parameters
formatOutput format
...Additional arguments

◆ messerrFlush()

void messerrFlush ( const String string)

When the error message has been collected as a String, this function produces it out without passing through useless internal buffering

Parameters
stringString to be produced
Remarks
This function is similar to messageFlush but dedicated to Errors

◆ mestitle()

void mestitle ( int  level,
const char *  format,
  ... 
)

Print a message and underlines it with various formats

Parameters
levelLevel of the title
formatOutput format
...Additional arguments

◆ print_imatrix()

void print_imatrix ( const char *  title,
int  flag_limit,
int  bycol,
int  nx,
int  ny,
const double *  sel,
const int *  tab 
)

Tabulated printout of a matrix (integer version)

Parameters
[in]titleTitle (Optional)
[in]flag_limitoption for the limits
  • 1 if limits must be applied
  • 0 if the whole matrix is printed
[in]bycol1 if values in 'tab' are sorted by column, 0 otherwise
[in]nxnumber of columns in the matrix
[in]nynumber of rows in the matrix
[in]selarray of selection or NULL
[in]tabarray containing the matrix

◆ print_ivector() [1/2]

void print_ivector ( const char *  title,
int  flag_limit,
int  ntab,
const int *  itab 
)

Print a vector of integer values in a matrix form

Parameters
[in]titleTitle (Optional)
[in]flag_limit1 if NTCOL is used; 0 otherwise
[in]ntabNumber of elements in the array
[in]itabArray to be printed

◆ print_ivector() [2/2]

void print_ivector ( const char *  title,
int  flag_limit,
int  ntab,
const VectorInt itab 
)

◆ print_matrix() [1/2]

void print_matrix ( const char *  title,
int  flag_limit,
const AMatrix mat 
)

◆ print_matrix() [2/2]

void print_matrix ( const char *  title,
int  flag_limit,
int  bycol,
int  nx,
int  ny,
const double *  sel,
const double *  tab 
)

Tabulated printout of a matrix

Parameters
[in]titleTitle (Optional)
[in]flag_limitoption for the limits
  • 1 if limits must be applied
  • 0 if the whole matrix is printed
[in]bycol1 if values in 'tab' are sorted by column, 0 otherwise
[in]nxnumber of columns in the matrix
[in]nynumber of rows in the matrix
[in]selarray of selection or NULL
[in]tabarray containing the matrix
Remarks
The order of the dimension (nx,ny) is opposite
of the one used in R-packages where dim[1]=nrow and dim[2]=ncol

◆ print_trimat()

void print_trimat ( const char *  title,
int  mode,
int  neq,
const double *  tl 
)

Tabulated printout of a upper triangular matrix

Parameters
[in]titleTitle (Optional)
[in]mode1 if the matrix is stored linewise 2 if the matrix is stored columnwise
[in]neqsize of the matrix
[in]tlarray containing the upper triangular matrix
Remarks
The ordering (compatible with matrix_solve is mode==2)

◆ print_vector() [1/2]

void print_vector ( const char *  title,
int  flag_limit,
int  ntab,
const double *  tab 
)

Print a vector of real values in a matrix form

Parameters
[in]titleTitle (Optional)
[in]flag_limit1 if NTCOL is used; 0 otherwise
[in]ntabNumber of elements in the array
[in]tabArray to be printed

◆ print_vector() [2/2]

void print_vector ( const char *  title,
int  flag_limit,
int  ntab,
const VectorDouble tab 
)

◆ tab_print_rc()

void tab_print_rc ( const char *  title,
int  mode,
int  value,
int  ncol,
const EJustify &  justify 
)

Tabulated printout of a row or column value

Parameters
[in]titleoptional title (NULL if not defined)
[in]modeCASE_ROW or CASE_COL
[in]valueValue to be written
[in]ncolnumber of columns for the printout
[in]justifyjustification flag (EJustify::LEFT, EJustify::CENTER or EJustify::RIGHT)

◆ tab_print_rowname()

void tab_print_rowname ( const char *  string,
int  taille 
)

Tabulated printout of a string (character size provided)

Parameters
[in]stringString to be written
[in]tailleNumber of characters
Remarks
The string is printed (left-adjusted) on 'taille' characters

◆ tab_printd()

void tab_printd ( const char *  title,
double  value,
int  ncol,
const EJustify &  justify 
)

Tabulated printout of a double value

Parameters
[in]titleoptional title (NULL if not defined)
[in]valueValue to be written
[in]ncolnumber of columns for the printout
[in]justifyjustification flag (EJustify::LEFT, EJustify::CENTER or EJustify::RIGHT)

◆ tab_printg()

void tab_printg ( const char *  title,
double  value,
int  ncol,
const EJustify &  justify 
)

Tabulated printout of a real value

Parameters
[in]titleoptional title (NULL if not defined)
[in]valueValue to be written
[in]ncolnumber of columns for the printout
[in]justifyjustification flag (EJustify::LEFT, EJustify::CENTER or EJustify::RIGHT)

◆ tab_printi()

void tab_printi ( const char *  title,
int  value,
int  ncol,
const EJustify &  justify 
)

Tabulated printout of an integer value

Parameters
[in]titleoptional title (NULL if not defined)
[in]valueValue to be written
[in]ncolnumber of columns for the printout
[in]justifyjustification flag (EJustify::LEFT, EJustify::CENTER or EJustify::RIGHT)

◆ tab_prints()

void tab_prints ( const char *  title,
const char *  string,
int  ncol,
const EJustify &  justify 
)

Tabulated printout of a string

Parameters
[in]titleoptional title (NULL if not defined)
[in]stringString to be written
[in]ncolnumber of columns for the printout
[in]justifyjustification flag (EJustify::LEFT, EJustify::CENTER or EJustify::RIGHT)

◆ toDouble()

String toDouble ( double  value,
const EJustify &  justify 
)

◆ toInt()

String toInt ( int  value,
const EJustify &  justify 
)

◆ toInterval()

String toInterval ( double  zmin,
double  zmax 
)

◆ toMatrix() [1/3]

String toMatrix ( const String title,
const AMatrix mat,
bool  flagOverride,
bool  flagSkipZero 
)

Print the contents of a VectorDouble in a Matrix Form

Parameters
titleTitle of the printout
matContents of a AMatrix
flagOverridetrue to override printout limitations
flagSkipZerowhen true, skip the zero values (represented by a '.' as for sparse matrix) always true for sparse matrix

◆ toMatrix() [2/3]

String toMatrix ( const String title,
const VectorString colnames,
const VectorString rownames,
bool  bycol,
int  nrows,
int  ncols,
const VectorDouble tab,
bool  flagOverride,
bool  flagSkipZero 
)

Print the contents of a VectorDouble in a Matrix Form

Parameters
titleTitle of the printout
colnamesNames of the columns (optional)
rownamesNames of the rows (optional)
bycoltrue if values as sorted by column; false otherwise
nrowsNumber of rows
ncolsNumber of columns
tabVectorDouble containing the values
flagOverridetrue to override printout limitations
flagSkipZerowhen true, skip the zero values (represented by a '.' as for sparse matrix)

◆ toMatrix() [3/3]

String toMatrix ( const String title,
const VectorString colnames,
const VectorString rownames,
bool  bycol,
int  nrows,
int  ncols,
const VectorInt tab,
bool  flagOverride,
bool  flagSkipZero 
)

Print the contents of a VectorDouble in a Matrix Form

Parameters
titleTitle of the printout
colnamesNames of the columns (optional)
rownamesNames of the rows (optional)
bycoltrue if values as sorted by column; false otherwise
nrowsNumber of rows
ncolsNumber of columns
tabVectorInt containing the values
flagOverridetrue to override printout limitations
flagSkipZerowhen true, skip the zero values (represented by a '.' as for sparse matrix)

◆ toStr()

String toStr ( const String string,
const EJustify &  justify,
int  localSize 
)

◆ toTitle()

String toTitle ( int  level,
const char *  format,
  ... 
)

Print a message and underlines it with various formats

Parameters
levelLevel of the title
formatOutput format
...Additional arguments

◆ toVector() [1/5]

String toVector ( const String title,
const VectorDouble tab,
bool  flagOverride 
)

Printout a vector in a formatted manner

Parameters
titleTitle of the printout (or empty string)
tabVector (real values) to be printed
flagOverridetrue to override printout limitations
Returns
The string (terminated with a newline)

◆ toVector() [2/5]

String toVector ( const String title,
const VectorInt tab,
bool  flagOverride 
)

Printout a vector in a formatted manner

Parameters
titleTitle of the printout (or empty string)
tabVector (integer values) to be printed
flagOverridetrue to override printout limitations
Returns
The string (terminated with a newline)

◆ toVector() [3/5]

String toVector ( const String title,
const VectorString tab,
bool  flagOverride 
)

◆ toVector() [4/5]

String toVector ( const String title,
const VectorVectorDouble tab,
bool  flagOverride 
)

Printout a list of vectors in a formatted manner

Parameters
titleTitle of the printout (or empty string)
tabVector of vectors (real values) to be printed
flagOverridetrue to override printout limitations
Returns
The string (terminated with a newline)

◆ toVector() [5/5]

String toVector ( const String title,
constvect  tab,
bool  flagOverride 
)

◆ toVectorDouble()

VectorString toVectorDouble ( const VectorDouble values,
const EJustify &  justify 
)

Variable Documentation

◆ DECODE

char DECODE[100]
static

◆ FORMAT

char FORMAT[100]
static

◆ TABSTR

char TABSTR[100]
static